Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def lint(s: Session) -> None:
- `uv_all_groups`: boolean to install all _dependency-groups_
- `uv_no_groups`: list of groups to exclude during install of `uv_all_groups`
- `uv_no_install_project`: boolean to not install the current project
- `uv_packages`: list of `uv` _packages_ to install, only valid in a `uv` workspace.
- `uv_all_packages`: boolean to install all `uv` _packages_, only valid in a `uv` workspace.
- `uv_sync_locked`: boolean to validate that `uv.lock` is up to date
- `uv_quiet`: boolean to silence `uv sync` command

Expand Down
13 changes: 13 additions & 0 deletions src/nox_uv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def session(
uv_no_install_project: bool = False,
uv_sync_locked: bool = True,
uv_quiet: bool = False,
uv_packages: Sequence[str] = (),
uv_all_packages: bool = False,
**kwargs: dict[str, Any],
) -> Callable[..., Callable[..., R]]:
"""Drop-in replacement for the :func:`nox.session` decorator to add support for `uv`.
Expand Down Expand Up @@ -62,6 +64,8 @@ def session(
uv_no_groups=uv_no_groups,
uv_only_groups=uv_only_groups,
uv_no_install_project=uv_no_install_project,
uv_packages=uv_packages,
uv_all_packages=uv_all_packages,
uv_sync_locked=uv_sync_locked,
uv_quiet=uv_quiet,
**kwargs,
Expand Down Expand Up @@ -103,10 +107,19 @@ def session(
if uv_no_install_project:
extended_cmd.append("--no-install-project")

for pkg in uv_packages:
extended_cmd.append(f"--package={pkg}")

if uv_all_packages:
extended_cmd.append("--all-packages")

sync_cmd += extended_cmd

@functools.wraps(function)
def wrapper(s: nox.Session, *_args: Any, **_kwargs: Any) -> None:
if uv_packages and uv_all_packages:
Comment thread
huin marked this conversation as resolved.
raise s.error("uv_packages and uv_all_packages are mututally exclusive")

if s.venv_backend == "uv":
s.env["UV_PROJECT_ENVIRONMENT"] = s.virtualenv.location

Expand Down
1 change: 1 addition & 0 deletions tests/subworkspace/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
Empty file added tests/subworkspace/README.md
Empty file.
43 changes: 43 additions & 0 deletions tests/subworkspace/noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from nox import Session, options

from nox_uv import session

options.default_venv_backend = "uv"

PKG_ONE = "package-one"
PKG_TWO = "package-two"


def _run_binaries(s: Session) -> None:
for run_binary in s.posargs:
s.run(run_binary)


@session
def run_with_no_packages(s: Session) -> None:
_run_binaries(s)


@session(uv_packages=[PKG_ONE])
def run_with_package_one(s: Session) -> None:
_run_binaries(s)


@session(uv_packages=[PKG_TWO])
def run_with_package_two(s: Session) -> None:
_run_binaries(s)


@session(uv_packages=[PKG_ONE, PKG_TWO])
def run_with_packages_one_and_two(s: Session) -> None:
_run_binaries(s)


@session(uv_all_packages=True)
def run_with_all_packages(s: Session) -> None:
_run_binaries(s)


@session(uv_packages=[PKG_ONE], uv_all_packages=True)
def run_explicit_and_all_packages(s: Session) -> None:
_run_binaries(s)
Empty file.
23 changes: 23 additions & 0 deletions tests/subworkspace/package-one/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system]
build-backend = "uv_build"
requires = [ "uv-build>=0.9,<0.10" ]
Comment thread
johnthagen marked this conversation as resolved.
Outdated

[project]
name = "package-one"
version = "0.1.0"
description = "Project for testing nox-uv"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
"Private :: Do Not Upload",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]

[project.scripts]
package-one-bin = "package_one.main:main"
Empty file.
6 changes: 6 additions & 0 deletions tests/subworkspace/package-one/src/package_one/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main() -> None:
print("Hello from package-one!")


if __name__ == "__main__":
main()
Empty file.
23 changes: 23 additions & 0 deletions tests/subworkspace/package-two/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system]
build-backend = "uv_build"
requires = [ "uv-build>=0.9,<0.10" ]
Comment thread
johnthagen marked this conversation as resolved.
Outdated

[project]
name = "package-two"
version = "0.1.0"
description = "Project for testing nox-uv"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
"Private :: Do Not Upload",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]

[project.scripts]
package-two-bin = "package_two.main:main"
Empty file.
6 changes: 6 additions & 0 deletions tests/subworkspace/package-two/src/package_two/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main() -> None:
print("Hello from package-two!")


if __name__ == "__main__":
main()
26 changes: 26 additions & 0 deletions tests/subworkspace/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[project]
name = "subworkspace"
version = "0.1.0"
description = "Workspace for testing nox-uv"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
"Private :: Do Not Upload",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
dependencies = ["nox-uv"]

[tool.uv]
sources.nox-uv = { path = "../../", editable = true }

[tool.uv.workspace]
members = [
"package-one",
"package-two",
]
Loading
Loading