Skip to content

Commit b485259

Browse files
committed
fix(poetry): properly handle multi-constraint dependency declarations
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 669a114 commit b485259

26 files changed

+27
-1115
lines changed

cyclonedx_py/_internal/poetry.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,21 @@ def _make_bom(self, project: 'T_NameDict', locker: 'T_NameDict',
292292
use_extras_dep_names = frozenset(map(normalize_packagename,
293293
chain.from_iterable(po_cfg['extras'][e] for e in use_extras)))
294294
for group_name in use_groups:
295-
for dep_name, dep_spec in po_cfg['group'][group_name].get('dependencies', {}).items():
295+
for dep_name, dep_specs in po_cfg['group'][group_name].get('dependencies', {}).items():
296296
dep_name = normalize_packagename(dep_name)
297-
dep_spec = dep_spec if isinstance(dep_spec, dict) else {'version': dep_spec}
297+
if not isinstance(dep_specs, list):
298+
if isinstance(dep_specs, dict):
299+
dep_specs = [dep_specs]
300+
else:
301+
dep_specs = [{'version': dep_specs}]
298302
self._logger.debug('root-component depends on %s', dep_name)
299303
if dep_name == 'python':
300304
continue # skip python constraint
301305
lock_entries = lock_data.get(dep_name)
302306
if lock_entries is None:
303307
self._logger.warning('skip unlocked dependency: %s', dep_name)
304308
continue
305-
if dep_spec.get('optional') and dep_name not in use_extras_dep_names:
309+
if all(ds.get('optional') for ds in dep_specs) and dep_name not in use_extras_dep_names:
306310
self._logger.debug('skip optional unused dependency: %s', dep_name)
307311
continue
308312
for lock_entry in lock_entries:
@@ -311,7 +315,10 @@ def _make_bom(self, project: 'T_NameDict', locker: 'T_NameDict',
311315
value=group_name
312316
))
313317
root_d.dependencies.add(Dependency(lock_entry.component.bom_ref))
314-
self.__add_dep(bom, lock_entry, dep_spec.get('extras', ()), lock_data)
318+
self.__add_dep(
319+
bom, lock_entry,
320+
chain.from_iterable(ds.get('extras', ()) for ds in dep_specs),
321+
lock_data)
315322

316323
return bom
317324

tests/_data/infiles/poetry/with-optionals-no-extra/pyproject-proto.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ authors = ["Your Name <[email protected]>"]
99
python = "^3.8"
1010
cyclonedx-python-lib = {version = ">=8,<9", optional = true}
1111
py-serializable = [
12+
# see https://github.com/CycloneDX/cyclonedx-python/issues/840
1213
{version = "*", optional = true}
1314
]
1415

1516
[tool.poetry.extras]
16-
# no extras - see https://github.com/CycloneDX/cyclonedx-python/issues/840
17+
# no extras!
1718

1819

1920
[build-system]

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.0.xml.bin

Lines changed: 1 addition & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.1.xml.bin

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.2.json.bin

Lines changed: 0 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.2.xml.bin

Lines changed: 1 addition & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.3.json.bin

Lines changed: 0 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.3.xml.bin

Lines changed: 1 addition & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.4.json.bin

Lines changed: 0 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/poetry/plain_with-optionals-no-extra_lock10_1.4.xml.bin

Lines changed: 1 addition & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)