Skip to content

feat(environment): add --isolated to ignore parent PYTHONPATH - #1106

Open
juliosuas wants to merge 1 commit into
CycloneDX:mainfrom
juliosuas:feat/1045-environment-isolated
Open

juliosuas wants to merge 1 commit into
CycloneDX:mainfrom
juliosuas:feat/1045-environment-isolated

Conversation

@juliosuas

Copy link
Copy Markdown

Description

Fixes #1045.

cyclonedx-py environment <python> discovers the target interpreter's sys.path via a subprocess. That subprocess previously honored parent PYTHON* variables (notably PYTHONPATH), so packages visible only to the caller could appear in the SBOM as if installed in the scanned environment.

Maintainers confirmed that inheriting the parent environment is intentional for some workflows and asked for an opt-in flag rather than changing the default.

This change adds --isolated, which probes the target interpreter with python -E (same insertion pattern as existing -S) so PYTHON* variables are ignored by the documented interpreter mechanism. Default behavior is unchanged. The flag only applies when a target <python> is given.

Regression covered by TestCliEnvironment.test_isolated_ignores_parent_pythonpath.

Resolves or fixes issue: #1045

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: [Cursor agent]
    • LLMs and versions: [Cursor agent (model not recorded); drafting only; every line human-reviewed]
    • Prompts: [Implement opt-in --isolated for environment path detection per issue #1045 and maintainer guidance (use python -E; keep default inheritance; add regression test and docs); human-reviewed before opening]

Affirmation

When analyzing a target interpreter, the path-detection subprocess
honored parent PYTHON* variables (notably PYTHONPATH), so packages
visible only to the caller could appear in the SBOM.

Add opt-in --isolated, which probes the target with python -E (same
pattern as existing -S). Default behavior is unchanged. Prefer -E over
-I so user-site packages remain discoverable. The flag only applies
when a target <python> is given.

Signed-off-by: Julio César Suástegui <juliosuas@users.noreply.github.com>
@juliosuas
juliosuas requested a review from a team as a code owner September 24, 2026 15:42
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity ✅ 0 (≤ 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.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 CycloneDX Python SBOM Tool | 🛠️ Build #34741628 | 📁 Comparing 79e2187 against latest (f6f4941)

  🔍 Preview build  

2 files changed
± changelog.html
± usage.html

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

environment subcommand: flag to NOT inherited PYTHONPATH

1 participant