Skip to content

Commit efd45b1

Browse files
authored
docs: showcase usage with uv (#858)
--------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 07d9bcc commit efd45b1

20 files changed

+1370
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Supported data sources are:
2323
* Pip's `requirements.txt` format
2424
* `PDM` manifest and lockfile are not explicitly supported.
2525
However, PDM's Python virtual environments are fully supported. See the docs for an example.
26+
* `uv` manifest and lockfile are not explicitly supported.
27+
However, uv's Python virtual environments are fully supported. See the docs for an example.
2628
* `Conda` as a package manager is no longer supported since version 4.
2729
However, conda's Python environments are fully supported via the methods listed above. See the docs for an example.
2830

cyclonedx_py/_internal/environment.py

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def make_argument_parser(**kwargs: Any) -> 'ArgumentParser':
8181
• Build an SBOM from PDM environment:
8282
> pdm.exe info --python
8383
> %(prog)s "%%path-to-pdm-python%%"
84+
• Build an SBOM from uv environment:
85+
> uv.exe python find
86+
> %(prog)s "%%path-to-uv-python%%"
8487
""")
8588
else: # if os_name == 'posix':
8689
p.epilog = dedent("""\
@@ -102,6 +105,8 @@ def make_argument_parser(**kwargs: Any) -> 'ArgumentParser':
102105
$ %(prog)s "$(poetry env info --executable)"
103106
• Build an SBOM from PDM environment:
104107
$ %(prog)s "$(pdm info --python)"
108+
• Build an SBOM from uv environment:
109+
$ %(prog)s "$(uv python find)"
105110
""")
106111
p.add_argument('--PEP-639',
107112
action='store_true',

docs/usage.rst

+28-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ Examples for macOS/Linux and alike
145145
146146
$ cyclonedx-py environment "$(pdm info --python)"
147147
148+
.. code-block:: shell-session
149+
:caption: Build an SBOM from uv environment
150+
151+
$ cyclonedx-py environment "$(uv python find)"
152+
148153
Examples for Windows
149154
^^^^^^^^^^^^^^^^^^^^
150155

@@ -183,7 +188,7 @@ Examples for Windows
183188
.. code-block:: doscon
184189
:caption: Build an SBOM from Poetry environment
185190
186-
> poetry.exe env info --executable
191+
> poetry.exe env info --executable
187192
> cyclonedx-py environment "%path-to-poetry-python%"
188193
189194
.. code-block:: doscon
@@ -192,6 +197,12 @@ Examples for Windows
192197
> pdm.exe info --python
193198
> cyclonedx-py environment "%path-to-pdm-python%"
194199
200+
.. code-block:: doscon
201+
:caption: Build an SBOM from uv environment
202+
203+
> uv.exe python find
204+
> cyclonedx-py environment "%path-to-uv-python%"
205+
195206
196207
For Pipenv
197208
----------
@@ -469,6 +480,22 @@ it is possible to use the functionality for Python (virtual) environments as des
469480

470481

471482

483+
For uv
484+
-------
485+
486+
Support for `uv`_ manifest and lockfile is not explicitly implemented, yet.
487+
488+
However, since uv utilizes Python virtual environments under the hood,
489+
it is possible to use the functionality for Python (virtual) environments as described above.
490+
491+
.. _uv: https://docs.astral.sh/uv/
492+
493+
494+
495+
*****
496+
497+
498+
472499
For Conda
473500
---------
474501

pyproject.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,18 @@ mypy = "1.14.1"
9595
bandit = "1.7.10"
9696
tomli = { version = "^2.0.1", python = "<3.11" }
9797
tox = "4.24.1"
98+
9899
# min version required to be able to install some dependencies
99100
# see https://github.com/MichaelKim0407/flake8-use-fstring/issues/33
100101
setuptools = ">= 47.0.0"
101-
# install` needed for setup/init of testbeds for `environment` purpose
102+
103+
# some package managers needed for setup/init of testbeds for `environment` purpose.
104+
# we do not relaly care for exact versions, as long as they have a stable CLI and craft usable virtual-environments
102105
pip = ">=23.0"
103106
pipenv = ">=2023.11.5"
104107
poetry = "^1.7"
105108
pdm = "^2.11"
109+
uv = "0.6.4" # keep pinned to exact version, until a v1.0.0 is released
106110

107111

108112

tests/_data/infiles/environment/via-uv/.gitignore

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This file is part of CycloneDX Python
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
"""
19+
initialize this testbed.
20+
"""
21+
22+
from os import environ
23+
from os.path import dirname, join
24+
from shutil import rmtree
25+
from subprocess import CompletedProcess, run # nosec:B404
26+
from sys import executable
27+
28+
__all__ = ['main']
29+
30+
this_dir = dirname(__file__)
31+
env_dir = join(this_dir, '.venv')
32+
33+
uv_env = environ.copy()
34+
uv_env['UV_NO_PROGRESS'] = '1'
35+
uv_env['UV_PROJECT_ENVIRONMENT'] = env_dir
36+
37+
38+
def uv_run(*args: str) -> CompletedProcess:
39+
# uv is not API, but a CLI -- call it like that!
40+
call = (
41+
executable, '-m', 'uv',
42+
*args
43+
)
44+
print('+ ', *call)
45+
res = run(call, cwd=this_dir, env=uv_env, shell=False) # nosec:B603
46+
if res.returncode != 0:
47+
raise RuntimeError('process failed')
48+
return res
49+
50+
51+
def main() -> None:
52+
# needed to reinit partially stripped evn
53+
rmtree(env_dir, ignore_errors=True)
54+
55+
# the actual setup
56+
uv_run('venv', env_dir)
57+
uv_run('sync', '--no-dev', '--locked', '--no-active')
58+
59+
60+
if __name__ == '__main__':
61+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[project]
2+
# https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#declaring-project-metadata
3+
name = "via-uv"
4+
version = "0.1.0"
5+
description = "environment via uv"
6+
license = { text = "Apache-2.0 OR MIT" }
7+
readme = "README.md"
8+
requires-python = ">=3.8"
9+
10+
# dynamic = [] # TODO
11+
12+
authors = ["Your Name <[email protected]>", "My Name"]
13+
maintainers = [
14+
"John Smith <[email protected]>",
15+
"Jane Smith <[email protected]>",
16+
]
17+
18+
keywords = ["packaging", "pipenv", "test"]
19+
classifiers = [
20+
"License :: OSI Approved :: Apache Software License",
21+
"License :: OSI Approved :: MIT License",
22+
"Classifier: Development Status :: 4 - Beta",
23+
"Intended Audience :: Developers"
24+
]
25+
26+
dependencies = [
27+
'toml'
28+
]
29+
optional-dependencies = { 'foo' = ['ddt'] }
30+
31+
# entry-point = {} # TODO
32+
33+
# gui-scripts = {} # TODO
34+
# scripts = {} # TODO
35+
36+
[project.urls]
37+
homepage = "https://oss.acme.org/my-project/"
38+
repository = "https://oss.acme.org/my-project.git"
39+
documentation = "https://oss.acme.org/my-project/docs/"
40+
"Bug Tracker" = "https://oss.acme.org/my-project/bugs/"
41+
"Funding" = "https://oss.acme.org/my-project/funding/"
42+
"Change log" = "https://oss.acme.org/my-project/changelog/"
43+
44+
45+
[tool.uv]
46+
# https://docs.astral.sh/uv/reference/settings/

tests/_data/infiles/environment/via-uv/uv.lock

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/environment/plain_via-uv_1.0.xml.bin

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/environment/plain_via-uv_1.1.xml.bin

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/environment/plain_via-uv_1.2.json.bin

+99
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)