Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions cyclonedx_py/_internal/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,60 +58,61 @@ class EnvironmentBB(BomBuilder):

@staticmethod
def make_argument_parser(**kwargs: Any) -> 'ArgumentParser':
p = ArgumentParser(description='Build an SBOM from Python (virtual) environment',
**kwargs)
p = ArgumentParser(
description='Build an SBOM from Python (virtual) environment',
**kwargs)
if os_name == 'nt':
p.epilog = dedent("""\
Example Usage:
• Build an SBOM from python environment:
> %(prog)s
> %(prog)s
• Build an SBOM from a Python (virtual) environment:
> %(prog)s "...\\some\\path\\bin\\python.exe"
> %(prog)s "...\\some\\path\\.venv"
> %(prog)s "$env:VIRTUAL_ENV"
> %(prog)s %%VIRTUAL_ENV%%
> %(prog)s "...\\some\\path\\bin\\python.exe"
> %(prog)s "...\\some\\path\\.venv"
> %(prog)s "$env:VIRTUAL_ENV"
> %(prog)s %%VIRTUAL_ENV%%
• Build an SBOM from specific Python environment:
> where.exe python3.9.exe
> %(prog)s "%%path-to-specific-python%%"
> where.exe python3.9.exe
> %(prog)s "%%path-to-specific-python%%"
• Build an SBOM from conda Python environment:
> conda.exe run where.exe python
> %(prog)s "%%path-to-conda-python%%"
> conda.exe run where.exe python
> %(prog)s "%%path-to-conda-python%%"
• Build an SBOM from Pipenv environment:
> pipenv.exe --py
> pipenv.exe --venv
> %(prog)s "%%path-to-pipenv-python%%"
> pipenv.exe --py
> pipenv.exe --venv
> %(prog)s "%%path-to-pipenv-python%%"
• Build an SBOM from Poetry environment:
> poetry.exe env info --executable
> %(prog)s "%%path-to-poetry-python%%"
> poetry.exe env info --executable
> %(prog)s "%%path-to-poetry-python%%"
• Build an SBOM from PDM environment:
> pdm.exe info --python
> %(prog)s "%%path-to-pdm-python%%"
> pdm.exe info --python
> %(prog)s "%%path-to-pdm-python%%"
• Build an SBOM from uv environment:
> uv.exe python find
> %(prog)s "%%path-to-uv-python%%"
> uv.exe python find
> %(prog)s "%%path-to-uv-python%%"
""")
else: # if os_name == 'posix':
p.epilog = dedent("""\
Example Usage:
• Build an SBOM from python environment:
$ %(prog)s
$ %(prog)s
• Build an SBOM from a Python (virtual) environment:
$ %(prog)s '.../some/path/bin/python'
$ %(prog)s '.../some/path/.venv'
$ %(prog)s "$VIRTUAL_ENV"
$ %(prog)s '.../some/path/bin/python'
$ %(prog)s '.../some/path/.venv'
$ %(prog)s "$VIRTUAL_ENV"
• Build an SBOM from specific Python environment:
$ %(prog)s "$(which python3.9)"
$ %(prog)s "$(which python3.9)"
• Build an SBOM from conda Python environment:
$ %(prog)s "$(conda run which python)"
$ %(prog)s "$(conda run which python)"
• Build an SBOM from Pipenv environment:
$ %(prog)s "$(pipenv --py)"
$ %(prog)s "$(pipenv --venv)"
$ %(prog)s "$(pipenv --py)"
$ %(prog)s "$(pipenv --venv)"
• Build an SBOM from Poetry environment:
$ %(prog)s "$(poetry env info --executable)"
$ %(prog)s "$(poetry env info --executable)"
• Build an SBOM from PDM environment:
$ %(prog)s "$(pdm info --python)"
$ %(prog)s "$(pdm info --python)"
• Build an SBOM from uv environment:
$ %(prog)s "$(uv python find)"
$ %(prog)s "$(uv python find)"
""")
p.add_argument('--PEP-639',
action='store_true',
Expand Down
11 changes: 6 additions & 5 deletions cyclonedx_py/_internal/pipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class PipenvBB(BomBuilder):

@staticmethod
def make_argument_parser(**kwargs: Any) -> 'ArgumentParser':
p = ArgumentParser(description=dedent("""\
Build an SBOM from Pipenv manifest.
p = ArgumentParser(
description=dedent("""\
Build an SBOM from Pipenv manifest.

The options and switches mimic the respective ones from Pipenv CLI.
"""),
**kwargs)
The options and switches mimic the respective ones from Pipenv CLI.
"""),
**kwargs)
# the options and switches SHALL mimic the ones from Pipenv
# see also: https://pipenv.pypa.io/en/latest/configuration.html
p.add_argument('--categories',
Expand Down
11 changes: 6 additions & 5 deletions cyclonedx_py/_internal/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ class PoetryBB(BomBuilder):

@staticmethod
def make_argument_parser(**kwargs: Any) -> 'ArgumentParser':
p = ArgumentParser(description=dedent("""\
Build an SBOM from Poetry project.
p = ArgumentParser(
description=dedent("""\
Build an SBOM from Poetry project.

The options and switches mimic the respective ones from Poetry CLI.
"""),
**kwargs)
The options and switches mimic the respective ones from Poetry CLI.
"""),
**kwargs)
# the options and switches SHALL mimic the ones from Poetry, which uses comma-separated lists and multi-use
p.add_argument('--without',
metavar='<groups>',
Expand Down
47 changes: 24 additions & 23 deletions cyclonedx_py/_internal/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,30 @@ class RequirementsBB(BomBuilder):

@staticmethod
def make_argument_parser(**kwargs: Any) -> 'ArgumentParser':
p = ArgumentParser(description=dedent("""\
Build an SBOM from Pip requirements.

The options and switches mimic the respective ones from Pip CLI.
"""),
epilog=dedent("""\
Example Usage:
• Build an SBOM from a requirements file:
$ %(prog)s requirements-prod.txt
• Merge multiple files and build an SBOM from it:
$ cat requirements/*.txt | %(prog)s -
• Build an inventory for all installed packages:
$ python -m pip freeze --all | %(prog)s -
• Build an inventory for all installed packages in a conda environment:
$ conda run python -m pip freeze --all | %(prog)s -
• Build an inventory for installed packages in a Python (virtual) environment:
$ .../.venv/bin/python -m pip freeze --all --local --require-virtualenv |\\
%(prog)s -
• Build an inventory from an unfrozen manifest:
$ python -m pip install -r dependencies.txt &&\\
python -m pip freeze | %(prog)s -
"""),
**kwargs)
p = ArgumentParser(
description=dedent("""\
Build an SBOM from Pip requirements.

The options and switches mimic the respective ones from Pip CLI.
"""),
epilog=dedent("""\
Example Usage:
• Build an SBOM from a requirements file:
$ %(prog)s requirements-prod.txt
• Merge multiple files and build an SBOM from it:
$ cat requirements/*.txt | %(prog)s -
• Build an inventory for all installed packages:
$ python -m pip freeze --all | %(prog)s -
• Build an inventory for all installed packages in a conda environment:
$ conda run python -m pip freeze --all | %(prog)s -
• Build an inventory for installed packages in a Python (virtual) environment:
$ .../.venv/bin/python -m pip freeze --all --local --require-virtualenv | \\
%(prog)s -
• Build an inventory from an unfrozen manifest:
$ python -m pip install -r dependencies.txt && \\
python -m pip freeze | %(prog)s -
"""),
**kwargs)
# the options and switches SHALL mimic the ones from Pip
p.add_argument('-i', '--index-url',
metavar='<url>',
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,13 @@ Example Usage
.. code-block:: shell-session
:caption: Build an inventory for installed packages in a Python (virtual) environment

$ .../.venv/bin/python -m pip freeze --all --local --require-virtualenv |\
$ .../.venv/bin/python -m pip freeze --all --local --require-virtualenv | \
cyclonedx-py requirements -

.. code-block:: shell-session
:caption: Build an inventory from an unfrozen manifest

$ python -m pip install -r dependencies.txt &&\
$ python -m pip install -r dependencies.txt && \
python -m pip freeze | cyclonedx-py requirements -


Expand Down