Skip to content

Commit

Permalink
feat: treat default dependencies as main group
Browse files Browse the repository at this point in the history
Poetry documentation on dependency groups [1] says:
  "The dependencies declared in tool.poetry.dependencies are part of an
implicit main group."

The current implementation does not account for that and in particular
does not allow to skip installation of default dependencies like in one
of
`poetry install --without main`
`poetry install --only-root`
`poetry install --only othergroup`.

This commit adds main as an implicit group and also adds it as a default
value where applicable.

[1]
https://python-poetry.org/docs/managing-dependencies#dependency-groups

Closes #1578
  • Loading branch information
Lykos153 committed Sep 2, 2024
1 parent 7619e43 commit 30ef3fe
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let
, pyProject
, attrs
, includeBuildSystem ? true
, groups ? [ ]
, groups ? [ "main" ]
, checkGroups ? checkGroupsDefault
, extras ? [ "*" ] # * means all extras, otherwise include the dependencies for a given extra
}:
Expand Down Expand Up @@ -82,12 +82,9 @@ let
{
buildInputs = mkInput "buildInputs" (if includeBuildSystem then buildSystemPkgs else [ ]);
propagatedBuildInputs = mkInput "propagatedBuildInputs" (
getDeps allRawDeps ++ (
# >=poetry-1.2.0 dependency groups
if pyProject.tool.poetry.group or { } != { }
then lib.flatten (map (g: getDeps pyProject.tool.poetry.group.${g}.dependencies) groups)
else [ ]
)
let
availableGroups = {main.dependencies = allRawDeps;} // pyProject.tool.poetry.group or { };
in lib.flatten (map (g: getDeps availableGroups.${g}.dependencies) (lib.traceVal groups))
);
nativeBuildInputs = mkInput "nativeBuildInputs" [ ];
checkInputs = mkInput "checkInputs" checkInputs';
Expand Down Expand Up @@ -145,7 +142,7 @@ lib.makeScope pkgs.newScope (self: {
# Example: { my-app = ./src; }
, editablePackageSources ? { }
, pyProject ? readTOML pyproject
, groups ? [ ]
, groups ? [ "main" ]
, checkGroups ? checkGroupsDefault
, extras ? [ "*" ]
}:
Expand Down Expand Up @@ -314,7 +311,7 @@ lib.makeScope pkgs.newScope (self: {
, preferWheels ? false
, editablePackageSources ? { }
, extraPackages ? _ps: [ ]
, groups ? [ "dev" ]
, groups ? [ "main" "dev" ]
, checkGroups ? checkGroupsDefault
, extras ? [ "*" ]
}:
Expand All @@ -332,13 +329,12 @@ lib.makeScope pkgs.newScope (self: {
(pkg: editablePackageSources."${pkg}" == null)
(builtins.attrNames editablePackageSources);

allEditablePackageSources = (getEditableDeps (pyProject.tool.poetry."dependencies" or { }))
// (getEditableDeps (pyProject.tool.poetry."dev-dependencies" or { }))
allEditablePackageSources = (getEditableDeps (pyProject.tool.poetry."dev-dependencies" or { }))
// (
# Poetry>=1.2.0
if pyProject.tool.poetry.group or { } != { } then
builtins.foldl' (acc: g: acc // getEditableDeps pyProject.tool.poetry.group.${g}.dependencies) { } groups
else { }
let
deps = pyProject.tool.poetry."dependencies" or { };
availableGroups = {main.dependencies = deps;} // pyProject.tool.poetry.group or { };
in builtins.foldl' (acc: g: acc // getEditableDeps availableGroups.${g}.dependencies) { } groups
)
// editablePackageSources;

Expand Down Expand Up @@ -380,7 +376,7 @@ lib.makeScope pkgs.newScope (self: {
, python ? pkgs.python3
, pwd ? projectDir
, preferWheels ? false
, groups ? [ ]
, groups ? [ "main" ]
, checkGroups ? checkGroupsDefault
, extras ? [ "*" ]
, ...
Expand Down

0 comments on commit 30ef3fe

Please sign in to comment.