Skip to content

Commit 66d199c

Browse files
committed
feat: prepare "contrib" area
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 28b94a7 commit 66d199c

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

cyclonedx/model/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
from typing import Any, Optional, Union
3232
from urllib.parse import quote as url_quote
3333
from uuid import UUID
34-
from warnings import warn
34+
from warnings import warn, deprecated
3535
from xml.etree.ElementTree import Element as XmlElement # nosec B405
3636

3737
import py_serializable as serializable
3838
from sortedcontainers import SortedSet
3939

40-
from contrib.hash.factories import HashTypeFactory
4140
from .._internal.compare import ComparableTuple as _ComparableTuple
4241
from ..exception.model import InvalidLocaleTypeException, InvalidUriException
4342
from ..exception.serialization import CycloneDxDeserializationException, SerializationOfUnexpectedValueException
@@ -377,6 +376,7 @@ class HashType:
377376
"""
378377

379378
@staticmethod
379+
@deprecated('Deprecated - use cyclonedx.contrib.hash.factories.HashTypeFactory.from_hashlib_alg instead')
380380
def from_hashlib_alg(hashlib_alg: str, content: str) -> 'HashType':
381381
"""Deprecated — Alias of :func:`cyclonedx.contrib.hash.factories.HashTypeFactory.from_hashlib_alge`.
382382
@@ -385,9 +385,12 @@ def from_hashlib_alg(hashlib_alg: str, content: str) -> 'HashType':
385385
.. deprecated:: next
386386
Use ``cyclonedx.contrib.hash.factories.HashTypeFactory.from_hashlib_alg()`` instead.
387387
"""
388+
from ..contrib.hash.factories import HashTypeFactory
389+
388390
return HashTypeFactory().from_hashlib_alg(hashlib_alg, content)
389391

390392
@staticmethod
393+
@deprecated('Deprecated - use cyclonedx.contrib.hash.factories.HashTypeFactory.from_composite_str instead')
391394
def from_composite_str(composite_hash: str) -> 'HashType':
392395
"""Deprecated — Alias of :func:`cyclonedx.contrib.hash.factories.HashTypeFactory.from_composite_str`.
393396
@@ -397,6 +400,8 @@ def from_composite_str(composite_hash: str) -> 'HashType':
397400
.. deprecated:: next
398401
Use ``cyclonedx.contrib.hash.factories.HashTypeFactory.from_composite_str()`` instead.
399402
"""
403+
from ..contrib.hash.factories import HashTypeFactory
404+
400405
return HashTypeFactory().from_composite_str(composite_hash)
401406

402407
def __init__(

cyclonedx/model/component.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from sortedcontainers import SortedSet
2828
from typing_extensions import deprecated
2929

30-
from contrib.component.builders import ComponentBuilder
3130
from .._internal.bom_ref import bom_ref_from_str as _bom_ref_from_str
3231
from .._internal.compare import ComparablePackageURL as _ComparablePackageURL, ComparableTuple as _ComparableTuple
3332
from ..exception.model import InvalidOmniBorIdException, InvalidSwhidException
@@ -963,6 +962,8 @@ def for_file(absolute_file_path: str, path_for_bom: Optional[str]) -> 'Component
963962
.. deprecated:: next
964963
Use ``cyclonedx.contrib.component.builders.ComponentBuilder.make_for_file()`` instead.
965964
"""
965+
from ..contrib.component.builders import ComponentBuilder
966+
966967
component = ComponentBuilder().make_for_file(absolute_file_path, name=path_for_bom)
967968
sha1_hash = next(h.content for h in component.hashes if h.alg is HashAlgorithm.SHA_1)
968969
component.version=f'0.0.0-{sha1_hash[0:12]}'

tests/test_component.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# See https://github.com/package-url/packageurl-python/issues/65
2222
from packageurl import PackageURL
2323

24-
from cyclonedx._internal.hash import file_sha1sum as _file_sha1sum
24+
from cyclonedx.contrib.component.builders import ComponentBuilder
2525
from cyclonedx.model.component import Component
2626
from tests import OWN_DATA_DIRECTORY
2727
from tests._data.models import get_component_setuptools_simple
@@ -65,7 +65,7 @@ def test_purl_incorrect_name(self) -> None:
6565
def test_from_xml_file_with_path_for_bom(self) -> None:
6666
test_file = join(OWN_DATA_DIRECTORY, 'xml', '1.4', 'bom_setuptools.xml')
6767
c = Component.for_file(absolute_file_path=test_file, path_for_bom='fixtures/bom_setuptools.xml')
68-
sha1_hash: str = _file_sha1sum(filename=test_file)
68+
sha1_hash: str = ComponentBuilder._file_sha1sum(filename=test_file)
6969
expected_version = f'0.0.0-{sha1_hash[0:12]}'
7070
self.assertEqual(c.name, 'fixtures/bom_setuptools.xml')
7171
self.assertEqual(c.version, expected_version)

0 commit comments

Comments
 (0)