From 3789a1bdb732a718992d0371c6e2a232a484b0cc Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 29 Oct 2023 19:34:13 +0000 Subject: [PATCH] pdm: allow selecting multiple groups --- modules/dream2nix/WIP-python-pdm/default.nix | 5 ++-- modules/dream2nix/WIP-python-pdm/lib.nix | 13 +++++---- .../nix-unit/test_python-pdm-lib/default.nix | 29 ++++++++++++++----- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/modules/dream2nix/WIP-python-pdm/default.nix b/modules/dream2nix/WIP-python-pdm/default.nix index 6ea45fb1..1a3a3b3a 100644 --- a/modules/dream2nix/WIP-python-pdm/default.nix +++ b/modules/dream2nix/WIP-python-pdm/default.nix @@ -70,8 +70,9 @@ in { }; groups = let populateGroup = groupname: deps: let - deps' = libpdm.selectForGroup { - inherit groupname parsed_lock_data groups_with_deps; + deps' = libpdm.selectForGroups { + inherit parsed_lock_data groups_with_deps; + groupNames = lib.unique ["default" groupname]; }; packages = lib.flip lib.mapAttrs deps' (name: pkg: { diff --git a/modules/dream2nix/WIP-python-pdm/lib.nix b/modules/dream2nix/WIP-python-pdm/lib.nix index cf340282..f5ff6dcd 100644 --- a/modules/dream2nix/WIP-python-pdm/lib.nix +++ b/modules/dream2nix/WIP-python-pdm/lib.nix @@ -82,7 +82,7 @@ in is_valid; - # Check that the given filenameis a valid wheel for our environment. + # Check that the given filename is a valid wheel for our environment. isUsableWheelFilename = { environ, filename, @@ -238,14 +238,17 @@ # Select the dependencies we need in our group. # Here we recurse so we get a set with all dependencies. - # selectForGroup :: {Attrset, Attrset, String} - selectForGroup = { + # selectForGroups :: {Attrset, Attrset, String} + selectForGroups = { parsed_lock_data, groups_with_deps, - groupname, + groupNames, }: let # List of top-level package names we need. - deps_top_level = groups_with_deps.${groupname}; + deps_top_level = + lib.concatMap + (groupName: groups_with_deps.${groupName}) + groupNames; getDeps = getDepsRecursively parsed_lock_data; in lib.attrsets.mergeAttrsList (map getDeps deps_top_level); diff --git a/tests/nix-unit/test_python-pdm-lib/default.nix b/tests/nix-unit/test_python-pdm-lib/default.nix index 44d043cf..2c878b4e 100644 --- a/tests/nix-unit/test_python-pdm-lib/default.nix +++ b/tests/nix-unit/test_python-pdm-lib/default.nix @@ -248,7 +248,7 @@ }; }; - tests_selectForGroup = let + tests_selectForGroups = let environ = linux_environ; pyproject = libpdm.loadPdmPyProject (lib.importTOML ./../../../examples/dream2nix-repo-flake-pdm/pyproject.toml); lock_data = lib.importTOML ./../../../examples/dream2nix-repo-flake-pdm/pdm.lock; @@ -260,16 +260,20 @@ environ = linux_environ; selector = libpdm.preferWheelSelector; }; - deps_default = libpdm.selectForGroup { + deps_default = libpdm.selectForGroups { inherit parsed_lock_data groups_with_deps; - groupname = "default"; + groupNames = ["default"]; + }; + deps_dev = libpdm.selectForGroups { + inherit parsed_lock_data groups_with_deps; + groupNames = ["default" "dev"]; }; in { - test_selectForGroup_names = { + test_selectForGroups_names = { expr = lib.attrNames deps_default; expected = ["certifi" "charset-normalizer" "idna" "requests" "urllib3"]; }; - test_selectForGroup_versions = { + test_selectForGroups_versions = { expr = lib.mapAttrs (key: value: value.version) deps_default; expected = { certifi = "2023.7.22"; @@ -279,7 +283,7 @@ urllib3 = "2.0.5"; }; }; - test_selectForGroup_sources = { + test_selectForGroups_sources = { expr = lib.mapAttrs (key: value: value.source.file) deps_default; expected = { certifi = "certifi-2023.7.22-py3-none-any.whl"; @@ -289,6 +293,17 @@ urllib3 = "urllib3-2.0.5-py3-none-any.whl"; }; }; + test_selectForGroups_dev_versions = { + expr = lib.mapAttrs (key: value: value.version) deps_dev; + expected = { + certifi = "2023.7.22"; + charset-normalizer = "3.2.0"; + idna = "3.4"; + requests = "2.31.0"; + urllib3 = "2.0.5"; + pi = "0.1.2"; + }; + }; }; in - test_isDependencyRequired // tests_isUsableFilename // tests_isValidUniversalWheel // tests_selectExtension // tests_selectSdist // tests_preferWheelSelector // tests_preferSdistSelector // tests_parseLockData // tests_groupsWithDeps // tests_getDepsRecursively // tests_selectForGroup + test_isDependencyRequired // tests_isUsableFilename // tests_isValidUniversalWheel // tests_selectExtension // tests_selectSdist // tests_preferWheelSelector // tests_preferSdistSelector // tests_parseLockData // tests_groupsWithDeps // tests_getDepsRecursively // tests_selectForGroups