Skip to content

feat(environment)!: add Python runtime component - #1146

Merged
jkowalleck merged 2 commits into
CycloneDX:mainfrom
juliosuas:feat/597-python-runtime-platform
Nov 19, 2026
Merged

jkowalleck merged 2 commits into
CycloneDX:mainfrom
juliosuas:feat/597-python-runtime-platform

Conversation

@juliosuas

@juliosuas juliosuas commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Implements the expected outcome from #597 (comment) for cyclonedx-py environment only:
with the new opt-in switch --add-python-runtime, the Python runtime of the analyzed environment is added as a component with type=platform and isExternal=true.

Example (cyclonedx-py environment --add-python-runtime --sv 1.7 --pyproject pyproject.toml .venv):

"components": [
  {
    "bom-ref": "python-runtime",
    "isExternal": true,
    "name": "python",
    "type": "platform",
    "version": "3.13.5"
  }
],
"dependencies": [
  { "ref": "python-runtime" },
  { "dependsOn": ["python-runtime"], "ref": "root-component" }
]
<component type="platform" bom-ref="python-runtime" isExternal="true">
  <name>python</name>
  <version>3.13.5</version>
</component>

Behavior:

  • Off by default. Without --add-python-runtime the output is unchanged for every spec version.
  • name is python, version is platform.python_version(): taken from the target <python> via __version4python (started with the same -S/-E flags as __path4python), otherwise from the current interpreter. The implementation (CPython, PyPy, etc.) is not recorded.
  • isExternal is only serialized for CycloneDX 1.7+. With --sv below 1.7 the component is still added, as a plain platform component (documented in help and docs).
  • If a root component is known (--pyproject), it depends on the runtime component. Without a root component, the runtime appears as a standalone node in the dependency graph.
  • Requires cyclonedx-python-lib>=11.12, <12 (first release with Component.is_external).
    Breaking change: the lower bound moves up from >=8, so environments pinned to cyclonedx-python-lib 8.x–11.11 need to upgrade.
  • poetry, requirements and pipenv are not covered.

Open for follow-up (not part of this PR):

  • Emitting the runtime component from poetry/requirements/pipenv.
  • A PURL/CPE or properties (OS, architecture) on the runtime component.

Tests:

  • Existing 1.7 snapshots unchanged versus main.
  • Integration tests: runtime component and root dependency with --add-python-runtime; version of the current interpreter; omitted by default.
  • Docs: docs/usage.rst, environment section and --help output.

Resolves or fixes issue: #597

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: Grok Bot (coding agent)
    • LLMs and versions: not exposed by the tool
    • Prompts: Implement the expected outcome from #597 (python runtime as type=platform, isExternal=true, CycloneDX 1.7) in "cyclonedx-py environment" only, following CONTRIBUTING.md; regenerate snapshots; add tests and docs. and Address the review feedback on this PR: raise the lib floor, put the runtime behind a CLI switch, simplify. I reviewed the changes and ran the test suite and linters locally.

Affirmation

…t for CycloneDX 1.7

When CycloneDX 1.7 or later is requested, `cyclonedx-py environment` adds
the Python runtime of the analyzed environment as a component with
`type=platform` and `isExternal=true`, named `python` and versioned like
`3.13.5`. The version is taken from the analyzed interpreter.
If a root component is known, it depends on the runtime component.
The implementation (CPython, PyPy, etc.) is intentionally not recorded.

Requires `cyclonedx-python-lib` with `Component.is_external` (>= 11.12);
with older versions of the lib, the runtime component is omitted.

Resolves CycloneDX#597

Signed-off-by: juliosuas <juliosuas@users.noreply.github.com>
@read-the-docs-community

read-the-docs-community Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 CycloneDX Python SBOM Tool | 🛠️ Build #35934530 | 📁 Comparing f6599a9 against latest (9d0acc7)

  🔍 Preview build  

1 file changed
± usage.html

@codacy-production

codacy-production Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 9 complexity · 0 duplication

Metric Results
Complexity ✅ 9 (≤ 20 complexity)
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jkowalleck jkowalleck linked an issue Nov 16, 2026 that may be closed by this pull request
Comment thread cyclonedx_py/_internal/environment.py Resolved
Comment thread cyclonedx_py/_internal/environment.py Resolved
Comment thread cyclonedx_py/_internal/environment.py Resolved
…ime`

Address review feedback:
- Raise the minimum `cyclonedx-python-lib` to `>=11.12`, the first release
  with `Component.is_external` (CycloneDX 1.7), and drop the feature detection.
- A new CLI switch `--add-python-runtime` decides whether the runtime component
  is added. Its version is taken via `__version4python(python)` for a target
  `<python>`, else `platform.python_version()` of the current interpreter.
  The spec-version gate and the extra `-S`/`-E` probing branch are gone, and
  `cli.py` is unchanged again.
- The switch is off by default, so existing 1.7 snapshots stay as on main.

Signed-off-by: Julio César Suástegui <5745504+juliosuas@users.noreply.github.com>
Comment thread pyproject.toml Resolved
@jkowalleck jkowalleck added enhancement New feature or request breaking change labels Nov 17, 2026
@jkowalleck
jkowalleck self-requested a review November 17, 2026 09:34
@jkowalleck

jkowalleck commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

the approach looks promising - feel free to transition from draft to open.

please adjust the PR description to the actual/final outcome.

@jkowalleck jkowalleck changed the title feat(environment): add Python runtime as external platform component for CycloneDX 1.7 feat(environment): add Python runtime component Nov 17, 2026
@juliosuas
juliosuas marked this pull request as ready for review November 17, 2026 21:27
@juliosuas
juliosuas requested a review from a team as a code owner November 17, 2026 21:27
@jkowalleck jkowalleck changed the title feat(environment): add Python runtime component feat(environment)!: add Python runtime component Nov 18, 2026
@jkowalleck

jkowalleck commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

This PR is ready to be merged.

For the changelog I propose the following text:

### Breaking Changes

- Raise the minimum `cyclonedx-python-lib` version from `8` to `11.12`.  
  Environments pinned below `11.12` must upgrade.

### Features

- **environment**: Add opt-in `--add-python-runtime` to include the analyzed Python runtime as a `platform` component.  
  The root component depends on it when present; `isExternal` is included for CycloneDX 1.7+.

@juliosuas what do you think?

@juliosuas

Copy link
Copy Markdown
Contributor Author

Thanks @jkowalleck, the changelog text looks good to me and matches the final behavior. Happy for this to be merged.

@jkowalleck
jkowalleck merged commit ee6dc7a into CycloneDX:main Nov 19, 2026
37 checks passed
@jkowalleck

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants