Skip to content

Commit 6be59f6

Browse files
committed
Add PEP-735 dependency groups
This introduces a breaking change. Previously `dev-dependencies` were remapped as optional dependencies, still named `dev-dependencies`: ``` nix virtualenv = editablePythonSet.mkVirtualEnv "hello-world-dev-env" { hello-world = [ "dev-dependencies" ]; }; ``` Will now be written simply as `dev`, refering to a dependency group, and not an optional feature: ``` nix virtualenv = editablePythonSet.mkVirtualEnv "hello-world-dev-env" { hello-world = [ "dev" ]; }; ``` This mirrors new Uv behaviour introduced in astral-sh/uv#8272. See pyproject-nix/pyproject.nix#170 for pyproject.nix changes.
1 parent 07711a7 commit 6be59f6

File tree

9 files changed

+97
-28
lines changed

9 files changed

+97
-28
lines changed

flake.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
nix-github-actions.url = "github:nix-community/nix-github-actions";
1111
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
1212

13-
pyproject-nix.url = "github:nix-community/pyproject.nix";
13+
pyproject-nix.url = "github:nix-community/pyproject.nix/pep735";
1414
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
1515
pyproject-nix.inputs.nix-github-actions.follows = "nix-github-actions";
1616
pyproject-nix.inputs.mdbook-nixdoc.follows = "mdbook-nixdoc";

lib/build.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ in
100100
passthru = {
101101
dependencies = mkSpec package.dependencies;
102102
optional-dependencies = mapAttrs (_: mkSpec) package.optional-dependencies;
103+
dependency-groups = mapAttrs (_: mkSpec) package.dev-dependencies;
103104
inherit format;
104105
};
105106

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[project]
2+
name = "dependency-groups"
3+
version = "0.1.0"
4+
description = "Testing dependency groups"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = []
8+
9+
# Dependency groups are rendered in uv.lock as package.dev-dependencies
10+
[dependency-groups]
11+
group-a = ["urllib3"]
12+
13+
# Special older syntax for dependency groups
14+
# tool.uv.dev-dependencies are rendered in lock file as:
15+
#
16+
# [package.dev-dependencies]
17+
# dev = [
18+
# { name = "arpeggio" },
19+
# ]
20+
[tool.uv]
21+
dev-dependencies = [
22+
"arpeggio"
23+
]
24+
25+
[build-system]
26+
requires = ["hatchling"]
27+
build-backend = "hatchling.build"

lib/fixtures/dependency-groups/uv.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/lock1.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
let
44
inherit (pyproject-nix.lib.pep508) parseMarkers evalMarkers;
55
inherit (pyproject-nix.lib.pypa) parseWheelFileName;
6-
inherit (pyproject-nix.lib) pep440 pypa;
6+
inherit (pyproject-nix.lib) pep440;
77
inherit (builtins) baseNameOf toJSON;
88
inherit (lib)
99
mapAttrs
@@ -23,7 +23,6 @@ let
2323
elem
2424
head
2525
listToAttrs
26-
nameValuePair
2726
any
2827
;
2928

@@ -91,7 +90,8 @@ fix (self: {
9190
# Recurse into top-level dependencies.
9291
startSet =
9392
filterTopLevelDeps dependencies.dependencies
94-
++ filterTopLevelDeps (concatLists (attrValues dependencies.extras));
93+
++ filterTopLevelDeps (concatLists (attrValues dependencies.extras))
94+
++ filterTopLevelDeps (concatLists (attrValues dependencies.groups));
9595

9696
operator =
9797
{ key, ... }:

lib/workspace.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ fix (self: {
138138
dependencies = topLevelDependencies;
139139
extras = { };
140140
build-systems = [ ];
141+
groups = { };
141142
};
142143
lock = uvLock;
143144
environ = environ';

templates/hello-world/flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114

115115
# Build virtual environment
116116
virtualenv = editablePythonSet.mkVirtualEnv "hello-world-dev-env" {
117-
# Add hello world with it's dev dependencies
118-
hello-world = [ "dev-dependencies" ];
117+
# Add hello world with it's dev dependency group
118+
hello-world = [ "dev" ];
119119
};
120120

121121
in

templates/hello-world/uv.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)