Skip to content

Commit

Permalink
streamline code style
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Oct 20, 2023
1 parent 68b05a3 commit adedd63
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 72 deletions.
2 changes: 1 addition & 1 deletion cyclonedx/exception/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class CycloneDxException(Exception): # noqa: N818
pass


class MissingOptionalDependencyException(CycloneDxException): # noqa: N818
class MissingOptionalDependencyException(CycloneDxException): # noqa: N818
"""Validation did not happen, due to missing dependencies."""
pass
26 changes: 13 additions & 13 deletions cyclonedx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def sha1sum(filename: str) -> str:
"""
h = sha1()
with open(filename, 'rb') as f:
for byte_block in iter(lambda: f.read(4096), b""):
for byte_block in iter(lambda: f.read(4096), b''):
h.update(byte_block)
return h.hexdigest()

Expand Down Expand Up @@ -102,10 +102,10 @@ class DataFlow(str, Enum):
.. note::
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/xml/#type_dataFlowType
"""
INBOUND = "inbound"
OUTBOUND = "outbound"
BI_DIRECTIONAL = "bi-directional"
UNKNOWN = "unknown"
INBOUND = 'inbound'
OUTBOUND = 'outbound'
BI_DIRECTIONAL = 'bi-directional'
UNKNOWN = 'unknown'


@serializable.serializable_class
Expand Down Expand Up @@ -542,7 +542,7 @@ def type(self, type: ExternalReferenceType) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'hash')
def hashes(self) -> "SortedSet[HashType]":
def hashes(self) -> 'SortedSet[HashType]':
"""
The hashes of the external reference (if applicable).
Expand Down Expand Up @@ -779,9 +779,9 @@ def locale(self, locale: Optional[str]) -> None:
if not re.search(Note._LOCALE_TYPE_REGEX, locale):
self._locale = None
raise InvalidLocaleTypeException(
f"Supplied locale '{locale}' is not a valid locale. "
f"Locale string should be formatted as the ISO-639 (or higher) language code and optional "
f"ISO-3166 (or higher) country code. according to ISO-639 format. Examples include: 'en', 'en-US'."
f'Supplied locale {locale!r} is not a valid locale.'
' Locale string should be formatted as the ISO-639 (or higher) language code and optional'
" ISO-3166 (or higher) country code. according to ISO-639 format. Examples include: 'en', 'en-US'."
)

def __eq__(self, other: object) -> bool:
Expand Down Expand Up @@ -922,7 +922,7 @@ def name(self, name: Optional[str]) -> None:
@serializable.json_name('url')
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'url')
@serializable.xml_sequence(2)
def urls(self) -> "SortedSet[XsUri]":
def urls(self) -> 'SortedSet[XsUri]':
"""
Get a list of URLs of the organization. Multiple URLs are allowed.
Expand All @@ -939,7 +939,7 @@ def urls(self, urls: Iterable[XsUri]) -> None:
@serializable.json_name('contact')
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'contact')
@serializable.xml_sequence(3)
def contacts(self) -> "SortedSet[OrganizationalContact]":
def contacts(self) -> 'SortedSet[OrganizationalContact]':
"""
Get a list of contact person at the organization. Multiple contacts are allowed.
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def version(self, version: Optional[str]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'hash')
@serializable.xml_sequence(4)
def hashes(self) -> "SortedSet[HashType]":
def hashes(self) -> 'SortedSet[HashType]':
"""
The hashes of the tool (if applicable).
Expand All @@ -1054,7 +1054,7 @@ def hashes(self, hashes: Iterable[HashType]) -> None:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'reference')
@serializable.xml_sequence(5)
def external_references(self) -> "SortedSet[ExternalReference]":
def external_references(self) -> 'SortedSet[ExternalReference]':
"""
External References provide a way to document systems, sites, and information that may be relevant but which
are not included with the BOM.
Expand Down
20 changes: 10 additions & 10 deletions cyclonedx/model/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def timestamp(self, timestamp: datetime) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'tool')
@serializable.xml_sequence(2)
def tools(self) -> "SortedSet[Tool]":
def tools(self) -> 'SortedSet[Tool]':
"""
Tools used to create this BOM.
Expand All @@ -110,7 +110,7 @@ def tools(self, tools: Iterable[Tool]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'author')
@serializable.xml_sequence(3)
def authors(self) -> "SortedSet[OrganizationalContact]":
def authors(self) -> 'SortedSet[OrganizationalContact]':
"""
The person(s) who created the BOM.
Expand Down Expand Up @@ -207,7 +207,7 @@ def licenses(self, licenses: Iterable[License]) -> None:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'property')
@serializable.xml_sequence(8)
def properties(self) -> "SortedSet[Property]":
def properties(self) -> 'SortedSet[Property]':
"""
Provides the ability to document properties in a key/value store. This provides flexibility to include data not
officially supported in the standard without having to use additional namespaces or create extensions.
Expand Down Expand Up @@ -335,7 +335,7 @@ def metadata(self, metadata: BomMetaData) -> None:
@serializable.include_none(SchemaVersion1Dot1)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'component')
@serializable.xml_sequence(2)
def components(self) -> "SortedSet[Component]":
def components(self) -> 'SortedSet[Component]':
"""
Get all the Components currently in this Bom.
Expand All @@ -348,7 +348,7 @@ def components(self) -> "SortedSet[Component]":
def components(self, components: Iterable[Component]) -> None:
self._components = SortedSet(components)

def get_component_by_purl(self, purl: Optional["PackageURL"]) -> Optional[Component]:
def get_component_by_purl(self, purl: Optional['PackageURL']) -> Optional[Component]:
"""
Get a Component already in the Bom by its PURL
Expand Down Expand Up @@ -394,7 +394,7 @@ def has_component(self, component: Component) -> bool:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'service')
@serializable.xml_sequence(3)
def services(self) -> "SortedSet[Service]":
def services(self) -> 'SortedSet[Service]':
"""
Get all the Services currently in this Bom.
Expand All @@ -414,7 +414,7 @@ def services(self, services: Iterable[Service]) -> None:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'reference')
@serializable.xml_sequence(4)
def external_references(self) -> "SortedSet[ExternalReference]":
def external_references(self) -> 'SortedSet[ExternalReference]':
"""
Provides the ability to document external references related to the BOM or to the project the BOM describes.
Expand All @@ -438,7 +438,7 @@ def _get_all_components(self) -> Set[Component]:

return components

def get_vulnerabilities_for_bom_ref(self, bom_ref: BomRef) -> "SortedSet[Vulnerability]":
def get_vulnerabilities_for_bom_ref(self, bom_ref: BomRef) -> 'SortedSet[Vulnerability]':
"""
Get all known Vulnerabilities that affect the supplied bom_ref.
Expand Down Expand Up @@ -469,7 +469,7 @@ def has_vulnerabilities(self) -> bool:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'vulnerability')
@serializable.xml_sequence(8)
def vulnerabilities(self) -> "SortedSet[Vulnerability]":
def vulnerabilities(self) -> 'SortedSet[Vulnerability]':
"""
Get all the Vulnerabilities in this BOM.
Expand Down Expand Up @@ -497,7 +497,7 @@ def version(self, version: int) -> None:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'dependency')
@serializable.xml_sequence(5)
def dependencies(self) -> "SortedSet[Dependency]":
def dependencies(self) -> 'SortedSet[Dependency]':
return self._dependencies

@dependencies.setter
Expand Down
27 changes: 14 additions & 13 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def licenses(self, licenses: Iterable[License]) -> None:

@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'text')
def copyright(self) -> "SortedSet[Copyright]":
def copyright(self) -> 'SortedSet[Copyright]':
"""
Optional list of copyright statements.
Expand Down Expand Up @@ -388,7 +388,7 @@ def diff(self, diff: Optional[Diff]) -> None:

@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'issue')
def resolves(self) -> "SortedSet[IssueType]":
def resolves(self) -> 'SortedSet[IssueType]':
"""
Optional list of issues resolved by this patch.
Expand Down Expand Up @@ -510,7 +510,7 @@ def variants(self, variants: Iterable['Component']) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'commit')
@serializable.xml_sequence(4)
def commits(self) -> "SortedSet[Commit]":
def commits(self) -> 'SortedSet[Commit]':
"""
A list of zero or more commits which provide a trail describing how the component deviates from an ancestor,
descendant, or variant.
Expand All @@ -530,7 +530,7 @@ def commits(self, commits: Iterable[Commit]) -> None:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'patch')
@serializable.xml_sequence(5)
def patches(self) -> "SortedSet[Patch]":
def patches(self) -> 'SortedSet[Patch]':
"""
A list of zero or more patches describing how the component deviates from an ancestor, descendant, or variant.
Patches may be complimentary to commits or may be used in place of commits.
Expand Down Expand Up @@ -802,7 +802,8 @@ def __init__(self, *, name: str, type: ComponentType = ComponentType.LIBRARY,

if license_str:
warnings.warn(
'`license_str` is deprecated and has been replaced with `licenses` to align with the CycloneDX standard',
'`license_str` is deprecated and has been'
' replaced with `licenses` to align with the CycloneDX standard',
category=DeprecationWarning, stacklevel=1
)
if not licenses:
Expand Down Expand Up @@ -953,10 +954,10 @@ def name(self, name: str) -> None:
self._name = name

@property
@serializable.include_none(SchemaVersion1Dot0, "")
@serializable.include_none(SchemaVersion1Dot1, "")
@serializable.include_none(SchemaVersion1Dot2, "")
@serializable.include_none(SchemaVersion1Dot3, "")
@serializable.include_none(SchemaVersion1Dot0, '')
@serializable.include_none(SchemaVersion1Dot1, '')
@serializable.include_none(SchemaVersion1Dot2, '')
@serializable.include_none(SchemaVersion1Dot3, '')
@serializable.xml_sequence(6)
def version(self) -> Optional[str]:
"""
Expand Down Expand Up @@ -1009,7 +1010,7 @@ def scope(self, scope: Optional[ComponentScope]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'hash')
@serializable.xml_sequence(9)
def hashes(self) -> "SortedSet[HashType]":
def hashes(self) -> 'SortedSet[HashType]':
"""
Optional list of hashes that help specify the integrity of this Component.
Expand Down Expand Up @@ -1148,7 +1149,7 @@ def pedigree(self, pedigree: Optional[Pedigree]) -> None:
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'reference')
@serializable.xml_sequence(17)
def external_references(self) -> "SortedSet[ExternalReference]":
def external_references(self) -> 'SortedSet[ExternalReference]':
"""
Provides the ability to document external references related to the component or to the project the component
describes.
Expand All @@ -1167,7 +1168,7 @@ def external_references(self, external_references: Iterable[ExternalReference])
@serializable.view(SchemaVersion1Dot4)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'property')
@serializable.xml_sequence(18)
def properties(self) -> "SortedSet[Property]":
def properties(self) -> 'SortedSet[Property]':
"""
Provides the ability to document properties in a key/value store. This provides flexibility to include data not
officially supported in the standard without having to use additional namespaces or create extensions.
Expand Down Expand Up @@ -1232,7 +1233,7 @@ def release_notes(self) -> Optional[ReleaseNotes]:
def release_notes(self, release_notes: Optional[ReleaseNotes]) -> None:
self._release_notes = release_notes

def get_all_nested_components(self, include_self: bool = False) -> Set["Component"]:
def get_all_nested_components(self, include_self: bool = False) -> Set['Component']:
components = set()
if include_self:
components.add(self)
Expand Down
10 changes: 5 additions & 5 deletions cyclonedx/model/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def serialize(cls, o: Any) -> List[str]:
raise ValueError(f'Attempt to serialize a non-Dependency: {o.__class__}')

@classmethod
def deserialize(cls, o: Any) -> Set["Dependency"]:
dependencies: Set["Dependency"] = set()
def deserialize(cls, o: Any) -> Set['Dependency']:
dependencies: Set['Dependency'] = set()
if isinstance(o, list):
for v in o:
dependencies.add(Dependency(ref=BomRef(value=v)))
Expand All @@ -54,7 +54,7 @@ class Dependency:
See https://cyclonedx.org/docs/1.4/xml/#type_dependencyType
"""

def __init__(self, ref: BomRef, dependencies: Optional[Iterable["Dependency"]] = None) -> None:
def __init__(self, ref: BomRef, dependencies: Optional[Iterable['Dependency']] = None) -> None:
self.ref = ref
self.dependencies = SortedSet(dependencies or [])

Expand All @@ -72,11 +72,11 @@ def ref(self, ref: BomRef) -> None:
@serializable.json_name('dependsOn')
@serializable.type_mapping(DependencyDependencies)
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'dependency')
def dependencies(self) -> "SortedSet[Dependency]":
def dependencies(self) -> 'SortedSet[Dependency]':
return self._dependencies

@dependencies.setter
def dependencies(self, dependencies: Iterable["Dependency"]) -> None:
def dependencies(self, dependencies: Iterable['Dependency']) -> None:
self._dependencies = SortedSet(dependencies)

def dependencies_as_bom_refs(self) -> Set[BomRef]:
Expand Down
2 changes: 1 addition & 1 deletion cyclonedx/model/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def source(self, source: Optional[IssueTypeSource]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'url')
@serializable.xml_sequence(5)
def references(self) -> "SortedSet[XsUri]":
def references(self) -> 'SortedSet[XsUri]':
"""
Any reference URLs related to this issue.
Expand Down
10 changes: 5 additions & 5 deletions cyclonedx/model/release_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def timestamp(self, timestamp: Optional[datetime]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'alias')
@serializable.xml_sequence(7)
def aliases(self) -> "SortedSet[str]":
def aliases(self) -> 'SortedSet[str]':
"""
One or more alternate names the release may be referred to. This may include unofficial terms used by
development and marketing teams (e.g. code names).
Expand All @@ -158,7 +158,7 @@ def aliases(self, aliases: Iterable[str]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'tag')
@serializable.xml_sequence(8)
def tags(self) -> "SortedSet[str]":
def tags(self) -> 'SortedSet[str]':
"""
One or more tags that may aid in search or retrieval of the release note.
Expand All @@ -174,7 +174,7 @@ def tags(self, tags: Iterable[str]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'issue')
@serializable.xml_sequence(9)
def resolves(self) -> "SortedSet[IssueType]":
def resolves(self) -> 'SortedSet[IssueType]':
"""
A collection of issues that have been resolved.
Expand All @@ -190,7 +190,7 @@ def resolves(self, resolves: Iterable[IssueType]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'note')
@serializable.xml_sequence(10)
def notes(self) -> "SortedSet[Note]":
def notes(self) -> 'SortedSet[Note]':
"""
Zero or more release notes containing the locale and content. Multiple note elements may be specified to support
release notes in a wide variety of languages.
Expand All @@ -207,7 +207,7 @@ def notes(self, notes: Iterable[Note]) -> None:
@property
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'property')
@serializable.xml_sequence(11)
def properties(self) -> "SortedSet[Property]":
def properties(self) -> 'SortedSet[Property]':
"""
Provides the ability to document properties in a name-value store. This provides flexibility to include data not
officially supported in the standard without having to use additional namespaces or create extensions. Unlike
Expand Down
Loading

0 comments on commit adedd63

Please sign in to comment.