Skip to content

--python parameter doesn't work when using tilde (~) expansion in file path #36

@HalaAli198

Description

@HalaAli198

Bug Description

The --python parameter doesn't work when using tilde (~) expansion in file paths.

Steps to Reproduce

sbom4python --use-pip --python ~/path/to/venv/bin/python3.9 --system --sbom cyclonedx --format json --output-file test.json

Expected Behavior

Should use the specified Python interpreter from the virtual environment and scan packages installed in that environment.

Actual Behavior

Ignores the --python parameter and uses system Python instead, scanning system-wide packages rather than the virtual environment packages.

Root Cause

In SBOMScanner.__init__(), line 67:
self.python_path =[+] pathlib.Path(python_path)[/+][-] pathlib.Path(python_path[/-] The pathlib.Pathconstructor doesn't expand ~, soself.python_path.exists()returns False inrun_pip_cmd(), causing the --python` parameter to be skipped.

Suggested Fix

pythonself.python_path = pathlib.Path(python_path).expanduser()

Workaround

Use absolute paths instead of tilde paths:
bashsbom4python --use-pip --python /home/user/path/to/venv/bin/python3.9 --system

Environment

sbom4python version: 0.12.4
OS: Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions