From aa7b846c98f0adaa67c5be94ab92677e16830cbd Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Sat, 5 Apr 2025 13:18:19 +0200 Subject: [PATCH 1/5] deprecate CLI switch `--schema-version`; use new `--spec-version` instead Signed-off-by: Jan Kowalleck --- cyclonedx_py/_internal/cli.py | 39 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/cyclonedx_py/_internal/cli.py b/cyclonedx_py/_internal/cli.py index 15193ec3..c75887d1 100644 --- a/cyclonedx_py/_internal/cli.py +++ b/cyclonedx_py/_internal/cli.py @@ -17,7 +17,7 @@ import logging import sys -from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter +from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter, SUPPRESS as ARG_SUPPRESS from itertools import chain from typing import TYPE_CHECKING, Any, Dict, List, NoReturn, Optional, Sequence, TextIO, Type, Union @@ -82,12 +82,19 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar type=FileType('wt', encoding='utf8'), dest='outfile', default='-') - op.add_argument('--sv', '--schema-version', + op.add_argument('--schema-version', # DEPRECATED metavar='', - help='The CycloneDX schema version for your SBOM' + help='DEPRECATED alias for "--spec-version"', + dest='spec_version', + choices=SchemaVersion, + type=SchemaVersion.from_version, + default=SchemaVersion.V1_5.to_version()) + op.add_argument('--sv', '--spec-version', + metavar='', + help='The CycloneDX spec version for your SBOM' f' {{choices: {", ".join(sorted((v.to_version() for v in SchemaVersion), reverse=True))}}}' ' (default: %(default)s)', - dest='schema_version', + dest='spec_version', choices=SchemaVersion, type=SchemaVersion.from_version, default=SchemaVersion.V1_5.to_version()) @@ -150,7 +157,7 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar __OWN_ARGS = { # the arg keywords from __init__() - 'logger', 'short_purls', 'output_format', 'schema_version', 'output_reproducible', 'should_validate', + 'logger', 'short_purls', 'output_format', 'spec_version', 'output_reproducible', 'should_validate', # the arg keywords from __call__() 'outfile' } @@ -163,7 +170,7 @@ def __init__(self, *, logger: logging.Logger, short_purls: bool, output_format: OutputFormat, - schema_version: SchemaVersion, + spec_version: SchemaVersion, output_reproducible: bool, should_validate: bool, _bbc: Type['BomBuilder'], @@ -171,7 +178,7 @@ def __init__(self, *, self._logger = logger self._short_purls = short_purls self._output_format = output_format - self._schema_version = schema_version + self._spec_version = spec_version self._output_reproducible = output_reproducible self._should_validate = should_validate self._bbc = _bbc(**self._clean_kwargs(kwargs), @@ -206,23 +213,23 @@ def _validate(self, output: str) -> bool: self._logger.warning('Validation skipped.') return False - self._logger.info('Validating result to schema: %s/%s', - self._schema_version.to_version(), self._output_format.name) + self._logger.info('Validating result to spec: %s/%s', + self._spec_version.to_version(), self._output_format.name) validation_error = make_schemabased_validator( self._output_format, - self._schema_version + self._spec_version ).validate_str(output) if validation_error: self._logger.debug('Validation Errors: %r', validation_error.data) - self._logger.error('The result is invalid to schema ' - f'{self._schema_version.to_version()}/{self._output_format.name}') + self._logger.error('The result is invalid to spec ' + f'{self._spec_version.to_version()}/{self._output_format.name}') self._logger.warning('Please report the issue and provide all input data to: ' 'https://github.com/CycloneDX/cyclonedx-python/issues/new?' 'template=ValidationError-report.md&' 'labels=ValidationError&title=%5BValidationError%5D') - raise ValueError('result is schema-invalid') - self._logger.debug('result is schema-valid') + raise ValueError('result is spec-invalid') + self._logger.debug('result is spec-valid') return True def _write(self, output: str, outfile: TextIO) -> int: @@ -232,7 +239,7 @@ def _write(self, output: str, outfile: TextIO) -> int: return written def _make_output(self, bom: 'Bom') -> str: - self._logger.info('Serializing SBOM: %s/%s', self._schema_version.to_version(), self._output_format.name) + self._logger.info('Serializing SBOM: %s/%s', self._spec_version.to_version(), self._output_format.name) if self._output_reproducible: bom.metadata.properties.add(Property(name=PropertyName.Reproducible.value, @@ -244,7 +251,7 @@ def _make_output(self, bom: 'Bom') -> str: return make_outputter( bom, self._output_format, - self._schema_version + self._spec_version ).output_as_string(indent=2) def _make_bom(self, **kwargs: Any) -> 'Bom': From b9358e149c1bd1efe9cb96245adeb39f215cc265 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Sat, 5 Apr 2025 13:37:28 +0200 Subject: [PATCH 2/5] docs Signed-off-by: Jan Kowalleck --- cyclonedx_py/_internal/cli.py | 2 +- docs/usage.rst | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cyclonedx_py/_internal/cli.py b/cyclonedx_py/_internal/cli.py index c75887d1..5af2b517 100644 --- a/cyclonedx_py/_internal/cli.py +++ b/cyclonedx_py/_internal/cli.py @@ -84,7 +84,7 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar default='-') op.add_argument('--schema-version', # DEPRECATED metavar='', - help='DEPRECATED alias for "--spec-version"', + help='DEPRECATED alias for option "--spec-version".', dest='spec_version', choices=SchemaVersion, type=SchemaVersion.from_version, diff --git a/docs/usage.rst b/docs/usage.rst index cf0d0083..61e0f920 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -35,7 +35,7 @@ Example usage: save SBOM in CycloneDX 1.6 XML format, generated from current pyt .. code-block:: shell - cyclonedx-py environment --outfile my-sbom.xml --schema-version 1.6 --output-format XML + cyclonedx-py environment --outfile my-sbom.xml --spec-version 1.6 --output-format XML For Python (virtual) environment @@ -85,7 +85,9 @@ The full documentation can be issued by running with ``environment --help``: Output file path for your SBOM (set to "-" to output to STDOUT) (default: -) - --sv , --schema-version + --schema-version + DEPRECATED alias for "--spec-version" + --sv , --spec-version The CycloneDX schema version for your SBOM {choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0} (default: 1.5) @@ -256,7 +258,9 @@ The full documentation can be issued by running with ``pipenv --help``: Output file path for your SBOM (set to "-" to output to ) (default: -) - --sv , --schema-version + --schema-version + DEPRECATED alias for "--spec-version" + --sv , --spec-version The CycloneDX schema version for your SBOM {choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0} (default: 1.5) @@ -331,7 +335,9 @@ The full documentation can be issued by running with ``poetry --help``: Output file path for your SBOM (set to "-" to output to ) (default: -) - --sv , --schema-version + --schema-version + DEPRECATED alias for "--spec-version" + --sv , --spec-version The CycloneDX schema version for your SBOM {choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0} (default: 1.5) @@ -402,7 +408,9 @@ The full documentation can be issued by running with ``requirements --help``: Output file path for your SBOM (set to "-" to output to ) (default: -) - --sv , --schema-version + --schema-version + DEPRECATED alias for "--spec-version" + --sv , --spec-version The CycloneDX schema version for your SBOM {choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0} (default: 1.5) From a69c330b876984c3fe9e2dac08530d0752e735d2 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Sat, 5 Apr 2025 13:37:59 +0200 Subject: [PATCH 3/5] tidy Signed-off-by: Jan Kowalleck --- cyclonedx_py/_internal/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyclonedx_py/_internal/cli.py b/cyclonedx_py/_internal/cli.py index 5af2b517..61a19d29 100644 --- a/cyclonedx_py/_internal/cli.py +++ b/cyclonedx_py/_internal/cli.py @@ -17,7 +17,7 @@ import logging import sys -from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter, SUPPRESS as ARG_SUPPRESS +from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter from itertools import chain from typing import TYPE_CHECKING, Any, Dict, List, NoReturn, Optional, Sequence, TextIO, Type, Union From 9e772e9429d758c6776798a95870a6eddef9705f Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Sat, 5 Apr 2025 13:40:08 +0200 Subject: [PATCH 4/5] tests Signed-off-by: Jan Kowalleck --- tests/unit/test_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 3ad008ff..ef09801d 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -76,7 +76,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder: command = Command( logger=self.__make_fresh_logger(logs), short_purls=short_purls, - schema_version=SchemaVersion.V1_4, + spec_version=SchemaVersion.V1_4, output_format=OutputFormat.JSON, should_validate=True, output_reproducible=True, @@ -100,7 +100,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder: command = Command( logger=self.__make_fresh_logger(logs), short_purls=False, - schema_version=SchemaVersion.V1_4, + spec_version=SchemaVersion.V1_4, output_format=OutputFormat.JSON, output_reproducible=False, should_validate=True, @@ -123,7 +123,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder: command = Command( logger=self.__make_fresh_logger(logs, logging.WARNING), short_purls=False, - schema_version=SchemaVersion.V1_4, + spec_version=SchemaVersion.V1_4, output_format=OutputFormat.JSON, should_validate=False, output_reproducible=False, From 8d4cac89ff2755d1d3490dfff8061ee98434614e Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Sat, 5 Apr 2025 13:48:51 +0200 Subject: [PATCH 5/5] fix Signed-off-by: Jan Kowalleck --- cyclonedx_py/_internal/cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cyclonedx_py/_internal/cli.py b/cyclonedx_py/_internal/cli.py index 61a19d29..d9ad4c95 100644 --- a/cyclonedx_py/_internal/cli.py +++ b/cyclonedx_py/_internal/cli.py @@ -222,14 +222,14 @@ def _validate(self, output: str) -> bool: ).validate_str(output) if validation_error: self._logger.debug('Validation Errors: %r', validation_error.data) - self._logger.error('The result is invalid to spec ' + self._logger.error('The result is invalid to schema ' f'{self._spec_version.to_version()}/{self._output_format.name}') self._logger.warning('Please report the issue and provide all input data to: ' 'https://github.com/CycloneDX/cyclonedx-python/issues/new?' 'template=ValidationError-report.md&' 'labels=ValidationError&title=%5BValidationError%5D') - raise ValueError('result is spec-invalid') - self._logger.debug('result is spec-valid') + raise ValueError('result is schema-invalid') + self._logger.debug('result is schema-valid') return True def _write(self, output: str, outfile: TextIO) -> int: