Skip to content

Commit

Permalink
style: model args one per line
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Jul 4, 2024
1 parent 49a93a0 commit 0b7850e
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 161 deletions.
73 changes: 57 additions & 16 deletions cyclonedx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class DataClassification:
https://cyclonedx.org/docs/1.4/xml/#type_dataClassificationType
"""

def __init__(self, *, flow: DataFlow, classification: str) -> None:
def __init__(
self, *,
flow: DataFlow,
classification: str
) -> None:
self.flow = flow
self.classification = classification

Expand Down Expand Up @@ -165,8 +169,12 @@ class AttachedText:

DEFAULT_CONTENT_TYPE = 'text/plain'

def __init__(self, *, content: str, content_type: str = DEFAULT_CONTENT_TYPE,
encoding: Optional[Encoding] = None) -> None:
def __init__(
self, *,
content: str,
content_type: str = DEFAULT_CONTENT_TYPE,
encoding: Optional[Encoding] = None
) -> None:
self.content_type = content_type
self.encoding = encoding
self.content = content
Expand Down Expand Up @@ -435,7 +443,11 @@ def from_composite_str(composite_hash: str) -> 'HashType':

raise UnknownHashTypeException(f'Unable to determine hash type from {composite_hash!r}')

def __init__(self, *, alg: HashAlgorithm, content: str) -> None:
def __init__(
self, *,
alg: HashAlgorithm,
content: str
) -> None:
self.alg = alg
self.content = content

Expand Down Expand Up @@ -735,8 +747,13 @@ class ExternalReference:
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.3/#type_externalReference
"""

def __init__(self, *, type: ExternalReferenceType, url: XsUri, comment: Optional[str] = None,
hashes: Optional[Iterable[HashType]] = None) -> None:
def __init__(
self, *,
type: ExternalReferenceType,
url: XsUri,
comment: Optional[str] = None,
hashes: Optional[Iterable[HashType]] = None
) -> None:
self.url = url
self.comment = comment
self.type = type
Expand Down Expand Up @@ -845,7 +862,11 @@ class Property:
Specifies an individual property with a name and value.
"""

def __init__(self, *, name: str, value: Optional[str] = None) -> None:
def __init__(
self, *,
name: str,
value: Optional[str] = None
) -> None:
self.name = name
self.value = value

Expand Down Expand Up @@ -914,8 +935,12 @@ class NoteText:

DEFAULT_CONTENT_TYPE: str = 'text/plain'

def __init__(self, *, content: str, content_type: Optional[str] = None,
encoding: Optional[Encoding] = None) -> None:
def __init__(
self, *,
content: str,
content_type: Optional[str] = None,
encoding: Optional[Encoding] = None
) -> None:
self.content = content
self.content_type = content_type or NoteText.DEFAULT_CONTENT_TYPE
self.encoding = encoding
Expand Down Expand Up @@ -1003,7 +1028,11 @@ class Note:

_LOCALE_TYPE_REGEX = re.compile(r'^[a-z]{2}(?:\-[A-Z]{2})?$')

def __init__(self, *, text: NoteText, locale: Optional[str] = None) -> None:
def __init__(
self, *,
text: NoteText,
locale: Optional[str] = None
) -> None:
self.text = text
self.locale = locale

Expand Down Expand Up @@ -1083,9 +1112,14 @@ class Tool:
See the CycloneDX Schema for toolType: https://cyclonedx.org/docs/1.3/#type_toolType
"""

def __init__(self, *, vendor: Optional[str] = None, name: Optional[str] = None, version: Optional[str] = None,
hashes: Optional[Iterable[HashType]] = None,
external_references: Optional[Iterable[ExternalReference]] = None) -> None:
def __init__(
self, *,
vendor: Optional[str] = None,
name: Optional[str] = None,
version: Optional[str] = None,
hashes: Optional[Iterable[HashType]] = None,
external_references: Optional[Iterable[ExternalReference]] = None
) -> None:
self.vendor = vendor
self.name = name
self.version = version
Expand Down Expand Up @@ -1203,8 +1237,12 @@ class IdentifiableAction:
See the CycloneDX specification: https://cyclonedx.org/docs/1.4/xml/#type_identifiableActionType
"""

def __init__(self, *, timestamp: Optional[datetime] = None, name: Optional[str] = None,
email: Optional[str] = None) -> None:
def __init__(
self, *,
timestamp: Optional[datetime] = None,
name: Optional[str] = None,
email: Optional[str] = None
) -> None:
if not timestamp and not name and not email:
raise NoPropertiesProvidedException(
'At least one of `timestamp`, `name` or `email` must be provided for an `IdentifiableAction`.'
Expand Down Expand Up @@ -1287,7 +1325,10 @@ class Copyright:
See the CycloneDX specification: https://cyclonedx.org/docs/1.4/xml/#type_copyrightsType
"""

def __init__(self, *, text: str) -> None:
def __init__(
self, *,
text: str
) -> None:
self.text = text

@property
Expand Down
42 changes: 25 additions & 17 deletions cyclonedx/model/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ class BomMetaData:
See the CycloneDX Schema for Bom metadata: https://cyclonedx.org/docs/1.5/#type_metadata
"""

def __init__(self, *, tools: Optional[Iterable[Tool]] = None,
authors: Optional[Iterable[OrganizationalContact]] = None, component: Optional[Component] = None,
supplier: Optional[OrganizationalEntity] = None,
licenses: Optional[Iterable[License]] = None,
properties: Optional[Iterable[Property]] = None,
timestamp: Optional[datetime] = None,
manufacturer: Optional[OrganizationalEntity] = None,
# Deprecated as of v1.6
manufacture: Optional[OrganizationalEntity] = None) -> None:
def __init__(
self, *,
tools: Optional[Iterable[Tool]] = None,
authors: Optional[Iterable[OrganizationalContact]] = None,
component: Optional[Component] = None,
supplier: Optional[OrganizationalEntity] = None,
licenses: Optional[Iterable[License]] = None,
properties: Optional[Iterable[Property]] = None,
timestamp: Optional[datetime] = None,
manufacturer: Optional[OrganizationalEntity] = None,
# Deprecated as of v1.6
manufacture: Optional[OrganizationalEntity] = None
) -> None:
self.timestamp = timestamp or _get_now_utc()
self.tools = tools or [] # type:ignore[assignment]
self.authors = authors or [] # type:ignore[assignment]
Expand Down Expand Up @@ -304,14 +308,18 @@ class Bom:
`cyclonedx.output.BaseOutput` to produce a CycloneDX document according to a specific schema version and format.
"""

def __init__(self, *, components: Optional[Iterable[Component]] = None,
services: Optional[Iterable[Service]] = None,
external_references: Optional[Iterable[ExternalReference]] = None,
serial_number: Optional[UUID] = None, version: int = 1,
metadata: Optional[BomMetaData] = None,
dependencies: Optional[Iterable[Dependency]] = None,
vulnerabilities: Optional[Iterable[Vulnerability]] = None,
properties: Optional[Iterable[Property]] = None) -> None:
def __init__(
self, *,
components: Optional[Iterable[Component]] = None,
services: Optional[Iterable[Service]] = None,
external_references: Optional[Iterable[ExternalReference]] = None,
serial_number: Optional[UUID] = None,
version: int = 1,
metadata: Optional[BomMetaData] = None,
dependencies: Optional[Iterable[Dependency]] = None,
vulnerabilities: Optional[Iterable[Vulnerability]] = None,
properties: Optional[Iterable[Property]] = None
) -> None:
"""
Create a new Bom that you can manually/programmatically add data to later.
Expand Down
111 changes: 77 additions & 34 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ class Commit:
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_commitType
"""

def __init__(self, *, uid: Optional[str] = None, url: Optional[XsUri] = None,
author: Optional[IdentifiableAction] = None, committer: Optional[IdentifiableAction] = None,
message: Optional[str] = None) -> None:
def __init__(
self, *,
uid: Optional[str] = None,
url: Optional[XsUri] = None,
author: Optional[IdentifiableAction] = None,
committer: Optional[IdentifiableAction] = None,
message: Optional[str] = None
) -> None:
if not uid and not url and not author and not committer and not message:
raise NoPropertiesProvidedException(
'At least one of `uid`, `url`, `author`, `committer` or `message` must be provided for a `Commit`.'
Expand Down Expand Up @@ -195,8 +200,11 @@ class ComponentEvidence:
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_componentEvidenceType
"""

def __init__(self, *, licenses: Optional[Iterable[License]] = None,
copyright: Optional[Iterable[Copyright]] = None) -> None:
def __init__(
self, *,
licenses: Optional[Iterable[License]] = None,
copyright: Optional[Iterable[Copyright]] = None
) -> None:
if not licenses and not copyright:
raise NoPropertiesProvidedException(
'At least one of `licenses` or `copyright` must be supplied for a `ComponentEvidence`.'
Expand Down Expand Up @@ -426,7 +434,11 @@ class Diff:
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_diffType
"""

def __init__(self, *, text: Optional[AttachedText] = None, url: Optional[XsUri] = None) -> None:
def __init__(
self, *,
text: Optional[AttachedText] = None,
url: Optional[XsUri] = None
) -> None:
if not text and not url:
raise NoPropertiesProvidedException(
'At least one of `text` or `url` must be provided for a `Diff`.'
Expand Down Expand Up @@ -507,8 +519,12 @@ class Patch:
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_patchType
"""

def __init__(self, *, type: PatchClassification, diff: Optional[Diff] = None,
resolves: Optional[Iterable[IssueType]] = None) -> None:
def __init__(
self, *,
type: PatchClassification,
diff: Optional[Diff] = None,
resolves: Optional[Iterable[IssueType]] = None
) -> None:
self.type = type
self.diff = diff
self.resolves = resolves or [] # type:ignore[assignment]
Expand Down Expand Up @@ -596,10 +612,15 @@ class Pedigree:
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_pedigreeType
"""

def __init__(self, *, ancestors: Optional[Iterable['Component']] = None,
descendants: Optional[Iterable['Component']] = None, variants: Optional[Iterable['Component']] = None,
commits: Optional[Iterable[Commit]] = None, patches: Optional[Iterable[Patch]] = None,
notes: Optional[str] = None) -> None:
def __init__(
self, *,
ancestors: Optional[Iterable['Component']] = None,
descendants: Optional[Iterable['Component']] = None,
variants: Optional[Iterable['Component']] = None,
commits: Optional[Iterable[Commit]] = None,
patches: Optional[Iterable[Patch]] = None,
notes: Optional[str] = None
) -> None:
if not ancestors and not descendants and not variants and not commits and not patches and not notes:
raise NoPropertiesProvidedException(
'At least one of `ancestors`, `descendants`, `variants`, `commits`, `patches` or `notes` must be '
Expand Down Expand Up @@ -748,9 +769,16 @@ class Swid:
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_swidType
"""

def __init__(self, *, tag_id: str, name: str, version: Optional[str] = None,
tag_version: Optional[int] = None, patch: Optional[bool] = None,
text: Optional[AttachedText] = None, url: Optional[XsUri] = None) -> None:
def __init__(
self, *,
tag_id: str,
name: str,
version: Optional[str] = None,
tag_version: Optional[int] = None,
patch: Optional[bool] = None,
text: Optional[AttachedText] = None,
url: Optional[XsUri] = None
) -> None:
self.tag_id = tag_id
self.name = name
self.version = version
Expand Down Expand Up @@ -1031,25 +1059,40 @@ def for_file(absolute_file_path: str, path_for_bom: Optional[str]) -> 'Component
)
)

def __init__(self, *,
name: str, type: ComponentType = ComponentType.LIBRARY,
mime_type: Optional[str] = None, bom_ref: Optional[Union[str, BomRef]] = None,
supplier: Optional[OrganizationalEntity] = None,
publisher: Optional[str] = None, group: Optional[str] = None, version: Optional[str] = None,
description: Optional[str] = None, scope: Optional[ComponentScope] = None,
hashes: Optional[Iterable[HashType]] = None, licenses: Optional[Iterable[License]] = None,
copyright: Optional[str] = None, purl: Optional[PackageURL] = None,
external_references: Optional[Iterable[ExternalReference]] = None,
properties: Optional[Iterable[Property]] = None, release_notes: Optional[ReleaseNotes] = None,
cpe: Optional[str] = None, swid: Optional[Swid] = None, pedigree: Optional[Pedigree] = None,
components: Optional[Iterable['Component']] = None, evidence: Optional[ComponentEvidence] = None,
modified: bool = False, manufacturer: Optional[OrganizationalEntity] = None,
authors: Optional[Iterable[OrganizationalContact]] = None,
omnibor_ids: Optional[Iterable[OmniborId]] = None, swhids: Optional[Iterable[Swhid]] = None,
crypto_properties: Optional[CryptoProperties] = None, tags: Optional[Iterable[str]] = None,
# Deprecated in v1.6
author: Optional[str] = None,
) -> None:
def __init__(
self, *,
name: str,
type: ComponentType = ComponentType.LIBRARY,
mime_type: Optional[str] = None,
bom_ref: Optional[Union[str, BomRef]] = None,
supplier: Optional[OrganizationalEntity] = None,
publisher: Optional[str] = None,
group: Optional[str] = None,
version: Optional[str] = None,
description: Optional[str] = None,
scope: Optional[ComponentScope] = None,
hashes: Optional[Iterable[HashType]] = None,
licenses: Optional[Iterable[License]] = None,
copyright: Optional[str] = None,
purl: Optional[PackageURL] = None,
external_references: Optional[Iterable[ExternalReference]] = None,
properties: Optional[Iterable[Property]] = None,
release_notes: Optional[ReleaseNotes] = None,
cpe: Optional[str] = None,
swid: Optional[Swid] = None,
pedigree: Optional[Pedigree] = None,
components: Optional[Iterable['Component']] = None,
evidence: Optional[ComponentEvidence] = None,
modified: bool = False,
manufacturer: Optional[OrganizationalEntity] = None,
authors: Optional[Iterable[OrganizationalContact]] = None,
omnibor_ids: Optional[Iterable[OmniborId]] = None,
swhids: Optional[Iterable[Swhid]] = None,
crypto_properties: Optional[CryptoProperties] = None,
tags: Optional[Iterable[str]] = None,
# Deprecated in v1.6
author: Optional[str] = None,
) -> None:
self.type = type
self.mime_type = mime_type
if isinstance(bom_ref, BomRef):
Expand Down
Loading

0 comments on commit 0b7850e

Please sign in to comment.