nox-uv 0.3.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nox_uv/__init__.py CHANGED
@@ -16,15 +16,17 @@ def session(
16
16
  python: Python | None = None,
17
17
  reuse_venv: bool | None = None,
18
18
  name: str | None = None,
19
- venv_backend: Any | None = None,
19
+ venv_backend: str | None = None,
20
20
  venv_params: Sequence[str] = (),
21
21
  tags: Sequence[str] | None = None,
22
22
  default: bool = True,
23
23
  requires: Sequence[str] | None = None,
24
24
  uv_groups: Sequence[str] = (),
25
25
  uv_extras: Sequence[str] = (),
26
+ uv_only_groups: Sequence[str] = (),
26
27
  uv_all_extras: bool = False,
27
28
  uv_all_groups: bool = False,
29
+ uv_sync_locked: bool = True,
28
30
  **kwargs: dict[str, Any],
29
31
  ) -> Callable[..., Callable[..., R]]:
30
32
  """Drop-in replacement for the :func:`nox.session` decorator to add support for `uv`.
@@ -52,27 +54,37 @@ def session(
52
54
  uv_extras=uv_extras,
53
55
  uv_all_extras=uv_all_extras,
54
56
  uv_all_groups=uv_all_groups,
57
+ uv_only_groups=uv_only_groups,
58
+ uv_sync_locked=uv_sync_locked,
55
59
  **kwargs,
56
60
  ) # type: ignore
57
61
 
58
62
  [function] = args
59
63
 
60
64
  # Create the `uv sync` command
61
- sync_cmd = ["uv", "sync", "--no-default-groups", "--locked"]
65
+ sync_cmd = ["uv", "sync", "--no-default-groups"]
66
+ extended_cmd: list[str] = []
67
+
68
+ # Add the --locked flag
69
+ if uv_sync_locked:
70
+ sync_cmd.append("--locked")
62
71
 
63
72
  # Add the groups
64
- for g in uv_groups:
65
- sync_cmd.append(f"--group={g}")
73
+ extended_cmd.extend([f"--group={g}" for g in uv_groups])
66
74
 
67
75
  # Add the extras
68
- for e in uv_extras:
69
- sync_cmd.append(f"--extra={e}")
76
+ extended_cmd.extend([f"--extra={e}" for e in uv_extras])
77
+
78
+ # Add the only-groups
79
+ extended_cmd.extend([f"--only-group={g}" for g in uv_only_groups])
70
80
 
71
81
  if uv_all_groups:
72
- sync_cmd.append("--all-groups")
82
+ extended_cmd.append("--all-groups")
73
83
 
74
84
  if uv_all_extras:
75
- sync_cmd.append("--all-extras")
85
+ extended_cmd.append("--all-extras")
86
+
87
+ sync_cmd += extended_cmd
76
88
 
77
89
  @functools.wraps(function)
78
90
  def wrapper(s: nox.Session, *_args: Any, **_kwargs: Any) -> None:
@@ -82,11 +94,20 @@ def session(
82
94
  # UV called from Nox does not respect the Python version set in the Nox session.
83
95
  # We need to pass the Python version to UV explicitly.
84
96
  if s.python is not None:
85
- # NOTE: casting to string explicitly because implicit casting isn't working
86
- # for the type checker.
87
- s.env["UV_PYTHON"] = str(s.python)
97
+ s.env["UV_PYTHON"] = s.virtualenv.location
88
98
 
99
+ s.debug(
100
+ f"UV_PYTHON={s.env['UV_PYTHON']} | "
101
+ f"UV_PROJECT_ENVIRONMENT={s.env['UV_PROJECT_ENVIRONMENT']}"
102
+ )
89
103
  s.run_install(*sync_cmd)
104
+ else:
105
+ if len(extended_cmd) > 0:
106
+ raise s.error(
107
+ 'Using "uv" specific paramaters is not allowed outside of a "uv" '
108
+ "venv_backend.\n"
109
+ f"Check the venv_backend, or the {extended_cmd} parameters."
110
+ )
90
111
 
91
112
  function(nox.Session(s._runner), *_args, **_kwargs)
92
113
 
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: nox-uv
3
+ Version: 0.5.0
4
+ Summary: Facilitate nox integration with uv for Python projects
5
+ Project-URL: Homepage, https://github.com/dantebben/nox-uv
6
+ Project-URL: Repository, https://github.com/dantebben/nox-uv
7
+ Project-URL: Issues, https://github.com/dantebben/nox-uv/issues
8
+ Author-email: Dan Tebben <dantebben@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE.txt
11
+ Keywords: nox,uv
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Testing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: nox>=2025.05.01
27
+ Description-Content-Type: text/markdown
28
+
29
+ ## Intro
30
+
31
+ [![GitHub Actions][github-actions-badge]](https://github.com/dantebben/nox-uv/actions)
32
+ [![PyPI version][pypi-version-badge]](https://pypi.python.org/pypi/nox-uv)
33
+ [![Python versions][python-versions-badge]](https://pypi.python.org/pypi/nox-uv)
34
+ [![uv][uv-badge]](https://github.com/astral-sh/uv)
35
+ [![Nox][nox-badge]](https://github.com/wntrblm/nox)
36
+ [![Ruff][ruff-badge]](https://github.com/astral-sh/ruff)
37
+ [![Type checked with mypy][mypy-badge]](https://mypy-lang.org/)
38
+
39
+ [github-actions-badge]: https://github.com/dantebben/nox-uv/workflows/CI/badge.svg
40
+ [pypi-version-badge]: https://img.shields.io/pypi/v/nox-uv.svg
41
+ [python-versions-badge]: https://img.shields.io/pypi/pyversions/nox-uv.svg
42
+ [uv-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json
43
+ [nox-badge]: https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg
44
+ [ruff-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
45
+ [mypy-badge]: https://www.mypy-lang.org/static/mypy_badge.svg
46
+
47
+ `nox-uv` is a simple drop-in replacement for [nox](https://nox.thea.codes/)'s `@nox.session` that installs
48
+ dependencies constrained by [uv](https://docs.astral.sh/uv/)'s lockfile.
49
+
50
+ ## Usage
51
+
52
+ Add `nox-uv` as a development dependency. The following example adds it into a `nox`
53
+ `dependency-group`.
54
+
55
+ ```shell
56
+ uv add --group nox nox-uv
57
+ ```
58
+
59
+ Using the following configuration within `pyproject.toml` as an example:
60
+
61
+ ```toml
62
+ [dependency-groups]
63
+ nox = [
64
+ "nox-uv",
65
+ ]
66
+ test = [
67
+ "pytest",
68
+ "pytest-cov",
69
+ ]
70
+ type_check = [
71
+ "mypy",
72
+ ]
73
+ lint = [
74
+ "ruff",
75
+ ]
76
+ ```
77
+
78
+ Within, your `noxfile.py`:
79
+
80
+ 1. Import `session` from `nox_uv`.
81
+ 2. Set `venv_backend` to `"uv"`. This can be done globally using
82
+ `options.default_venv_backend = "uv"`.
83
+ 3. Use the new [`uv_*` parameters](#added-parameters) to `session` to control which dependencies
84
+ are synced into the session's virtual environment in addition to the project's main
85
+ dependencies.
86
+ - `uv sync` is used to install dependencies so that their versions are constrained by
87
+ `uv.lock`.
88
+
89
+ ```py
90
+ from nox import Session, options
91
+ from nox_uv import session
92
+
93
+ options.default_venv_backend = "uv"
94
+
95
+
96
+ @session(
97
+ python=["3.10", "3.11", "3.12", "3.13"],
98
+ uv_groups=["test"],
99
+ )
100
+ def test(s: Session) -> None:
101
+ s.run("python", "-m", "pytest")
102
+
103
+
104
+ @session(uv_groups=["type_check"])
105
+ def type_check(s: Session) -> None:
106
+ s.run("mypy", "src")
107
+
108
+
109
+ @session(uv_only_groups=["lint"])
110
+ def type_check(s: Session) -> None:
111
+ s.run("ruff", "check", ".")
112
+ s.run("ruff", "format", "--check", ".")
113
+ ```
114
+
115
+ > [!NOTE]
116
+ > All `@session(...)` parameters are keywords only, no positional parameters are allowed.
117
+
118
+ > [!NOTE]
119
+ > The `default_groups` defined in `pyproject.toml` are _not_ installed by default. The
120
+ > user must explicitly list the desired groups in the `uv_groups` parameter.
121
+
122
+ ### Added parameters
123
+
124
+ - `uv_groups`: list of `uv` _dependency-groups_
125
+ - `uv_extras`: list of `uv` _optional-dependencies_
126
+ - `uv_only_groups`: list of `uv` _only-groups_ to include. Prevents installation of project
127
+ _dependencies_.
128
+ - `uv_all_extras`: boolean to install all _optional-dependencies_ from `pyproject.toml`
129
+ - `uv_all_groups`: boolean to install all _dependency-groups_
130
+ - `uv_sync_locked`: boolean to validate that `uv.lock` is up-to-date
131
+
132
+
133
+ ## Inspiration
134
+
135
+ This is heavily influenced by, but much more limited than,
136
+ [nox-poetry](https://nox-poetry.readthedocs.io).
@@ -0,0 +1,6 @@
1
+ nox_uv/__init__.py,sha256=saOMVr75kYQRM1F2y0WhswoalybmXaeqyXWiQw1PtOs,3799
2
+ nox_uv/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ nox_uv-0.5.0.dist-info/METADATA,sha256=E0z2X2Ls22uPh4gfkupWkBLlWSAPlAe7LqQGLrlskBM,4599
4
+ nox_uv-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ nox_uv-0.5.0.dist-info/licenses/LICENSE.txt,sha256=iTZ5ALF1isnM6Ey9Tjom0XIGBBysArB0I2NHZ9a-b8I,1067
6
+ nox_uv-0.5.0.dist-info/RECORD,,
@@ -1,50 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: nox-uv
3
- Version: 0.3.0
4
- Summary: Facilitate nox integration with uv for Python projects
5
- Project-URL: Homepage, https://github.com/dantebben/nox-uv
6
- Author-email: Dan Tebben <dantebben@gmail.com>
7
- License-Expression: MIT
8
- License-File: LICENSE.txt
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Intended Audience :: Developers
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
18
- Classifier: Programming Language :: Python :: 3.12
19
- Classifier: Programming Language :: Python :: 3.13
20
- Classifier: Topic :: Software Development :: Testing
21
- Classifier: Typing :: Typed
22
- Requires-Python: >=3.9
23
- Requires-Dist: nox>=2025.05.01
24
- Description-Content-Type: text/markdown
25
-
26
- ## Intro
27
-
28
- This is a basic drop-in replacement for `nox.session` of [nox](https://nox.thea.codes/) to be used
29
- with the [uv](https://docs.astral.sh/uv/) package manager.
30
-
31
- To use, import `session` from `nox_uv` in your `noxfile.py`.
32
-
33
- > [!NOTE]
34
- > All `@session(...)` parameters are keywords only, no positional parameters are allowed.
35
-
36
- > [!NOTE]
37
- > The `default_groups` defined in `pyproject.toml` are _not_ installed by default. The
38
- > user must explicitly list the desired groups in the `uv_groups` parameter.
39
-
40
- ## Added parameters
41
-
42
- - `uv_groups`: list of `uv` dependency groups
43
- - `uv_extras`: list of `uv` extras
44
- - `uv_all_extras`: boolean to install all extras from `pyproject.toml`
45
- - `uv_all_groups`: boolean to install all dependency groups
46
-
47
- ## Inspiration
48
-
49
- This is heavily influenced by, but much more limited than,
50
- [nox-poetry](https://nox-poetry.readthedocs.io).
@@ -1,6 +0,0 @@
1
- nox_uv/__init__.py,sha256=r5KNgONE17jPy66T_MK6caqw5pkNYCHTgxWdcM3NuPQ,3054
2
- nox_uv/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- nox_uv-0.3.0.dist-info/METADATA,sha256=qPBt6LmmykDW1NSS6ig1hcDL5FMIW3E4xZV_LcnZb8o,1844
4
- nox_uv-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
- nox_uv-0.3.0.dist-info/licenses/LICENSE.txt,sha256=iTZ5ALF1isnM6Ey9Tjom0XIGBBysArB0I2NHZ9a-b8I,1067
6
- nox_uv-0.3.0.dist-info/RECORD,,
File without changes