Introduce a new class `SpdxLicenseExpressionCreator`, responsible for converting license texts extracted from packages, into an SPDX-compliant license expressions. If the `license_expression` Python package is available on the system, it is used to determine the license text extracted from a package is a valid SPDX license expression. If it is, it's returned as is back to the caller. If it is not, or of the package is not available on the system, the license text is wrapped in a `ExtractedLicensingInfo` instance. The `SpdxLicenseExpressionCreator` object keeps track of all generated `ExtractedLicensingInfo` instances and de-duplicates them based on the license text. This means that if two packages use the same SPDX-non-compliant license text, they will be wrapped by an `ExtractedLicensingInfo` instance with the same `LicenseRef-` ID. The reason for fallback when `license_expression` package is not available is that it is not available on RHEL and CentOS Stream. This implementation allows us to ship the functionality in RHEL and optionally enabling it by installing `license_expression` from a 3rd party repository. In any case, the generated SBOM document will always contain valid SPDX license expressions. Extend unit tests to cover the newly added functionality. Signed-off-by: Tomáš Hozza <thozza@redhat.com> FIXUP: sbom/spdx: use compliant license expressions Signed-off-by: Tomáš Hozza <thozza@redhat.com>
122 lines
2.7 KiB
INI
122 lines
2.7 KiB
INI
[tox]
|
|
env_list =
|
|
py{36,37,38,39,310,311,312,313}
|
|
lint
|
|
type
|
|
|
|
labels =
|
|
test = py{36,37,38,39,310,311,312,313}
|
|
lint = ruff, autopep8, pylint
|
|
type = mypy,mypy-strict
|
|
|
|
[testenv]
|
|
description = "run osbuild unit tests"
|
|
deps =
|
|
pytest
|
|
pytest-xdist
|
|
jsonschema
|
|
mako
|
|
iniparse
|
|
pyyaml
|
|
toml
|
|
license_expression
|
|
pykickstart
|
|
# required by pykickstart but not pulled in automatically :/
|
|
requests
|
|
|
|
setenv =
|
|
LINTABLES = osbuild/ assemblers/* devices/*.* devices/test/*.py inputs/*.* mounts/*.* mounts/test/*.py runners/* sources/*.* stages/*.* inputs/test/*.py stages/test/*.py sources/test/*.py test/ tools/
|
|
LINTABLES_EXCLUDES = "*.json,*.sh"
|
|
LINTABLES_EXCLUDES_RE = ".*\.json$,.*\.sh"
|
|
TYPEABLES = osbuild
|
|
TYPEABLES_STRICT = ./osbuild/main_cli.py ./osbuild/util/parsing.py ./osbuild/testutil/atomic.py
|
|
|
|
passenv =
|
|
TEST_CATEGORY
|
|
|
|
commands =
|
|
python -m pytest -v --pyargs --rootdir=. {posargs}
|
|
|
|
allowlist_externals =
|
|
bash
|
|
|
|
[testenv:ruff]
|
|
deps =
|
|
ruff==0.3.0
|
|
|
|
commands =
|
|
bash -c 'python -m ruff check {env:LINTABLES}'
|
|
|
|
[testenv:autopep8]
|
|
deps =
|
|
autopep8==2.3.1
|
|
pycodestyle==2.12.1
|
|
|
|
commands =
|
|
bash -c 'python -m autopep8 --diff --max-line-length 120 -a -a -a -j0 -r --exclude {env:LINTABLES_EXCLUDES} --exit-code {env:LINTABLES}'
|
|
|
|
[testenv:pylint]
|
|
deps =
|
|
pylint==3.3.1
|
|
# Use astroid of at least v3.3.5 to fix the following error with Python 3.13:
|
|
# test/run/test_stages.py:21:0: E0611: No name 'Mapping' in module 'collections.abc' (no-name-in-module)
|
|
# More details: https://github.com/pylint-dev/pylint/issues/10000
|
|
astroid>=3.3.5
|
|
|
|
commands =
|
|
bash -c 'python -m pylint --ignore-patterns {env:LINTABLES_EXCLUDES_RE} {env:LINTABLES}'
|
|
|
|
[testenv:mypy]
|
|
deps =
|
|
mypy==1.2.0
|
|
|
|
commands =
|
|
bash -c 'python -m mypy {env:TYPEABLES}'
|
|
|
|
[testenv:mypy-strict]
|
|
deps =
|
|
mypy==1.2.0
|
|
|
|
commands =
|
|
bash -c 'python -m mypy --follow-imports=skip --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs {env:TYPEABLES_STRICT}'
|
|
|
|
[testenv:tomllib]
|
|
description = "test osbuild.util.toml with tomllib"
|
|
deps =
|
|
pytest
|
|
mako
|
|
tomli-w
|
|
|
|
commands =
|
|
python -m pytest -s -vvv -k test_util_toml
|
|
|
|
[testenv:tomli]
|
|
description = "test osbuild.util.toml with tomli"
|
|
deps =
|
|
pytest
|
|
tomli
|
|
tomli-w
|
|
mako
|
|
|
|
commands =
|
|
python -m pytest -s -vvv -k test_util_toml
|
|
|
|
[testenv:toml]
|
|
description = "test osbuild.util.toml with toml"
|
|
deps =
|
|
pytest
|
|
toml
|
|
mako
|
|
|
|
commands =
|
|
python -m pytest -s -vvv -k test_util_toml
|
|
|
|
[testenv:pytoml]
|
|
description = "test osbuild.util.toml with pytoml"
|
|
deps =
|
|
pytest
|
|
pytoml
|
|
mako
|
|
|
|
commands =
|
|
python -m pytest -s -vvv -k test_util_toml
|