mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 14:31:55 +03:00
fix(pdm/parseLockData): filter deps properly
This commit is contained in:
parent
4eeee078f7
commit
fc86213f00
@ -12,12 +12,18 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Evaluates a parsed dependency against an environment to determine if it is required.
|
||||||
|
isDependencyRequired = environ: dependency:
|
||||||
|
if dependency.markers != null
|
||||||
|
then libpyproject.pep508.evalMarkers environ dependency.markers
|
||||||
|
else true;
|
||||||
|
|
||||||
# Convert sources to mapping with filename as key.
|
# Convert sources to mapping with filename as key.
|
||||||
sourcesToAttrs = sources:
|
sourcesToAttrs = sources:
|
||||||
lib.listToAttrs (
|
lib.listToAttrs (
|
||||||
map (
|
map (
|
||||||
source:
|
source:
|
||||||
lib.nameValuePair (getFilename source.url) source
|
lib.nameValuePair (getFilename source.file) source
|
||||||
)
|
)
|
||||||
sources
|
sources
|
||||||
);
|
);
|
||||||
@ -129,8 +135,8 @@
|
|||||||
selector,
|
selector,
|
||||||
}: let
|
}: let
|
||||||
# TODO: validate against lock file version.
|
# TODO: validate against lock file version.
|
||||||
func = item: let
|
parsePackage = item: let
|
||||||
sources = sourcesToAttrs lock-data.metadata.files."${item.name} ${item.version}";
|
sources = sourcesToAttrs item.files;
|
||||||
compatibleSources =
|
compatibleSources =
|
||||||
lib.filterAttrs
|
lib.filterAttrs
|
||||||
(
|
(
|
||||||
@ -138,18 +144,14 @@
|
|||||||
isUsableFilename {inherit environ filename;}
|
isUsableFilename {inherit environ filename;}
|
||||||
)
|
)
|
||||||
sources;
|
sources;
|
||||||
evalDep = dep:
|
parsedDeps = (
|
||||||
libpyproject.pep508.evalMarkers
|
|
||||||
environ
|
|
||||||
(libpyproject.pep508.parseString dep);
|
|
||||||
dependencies =
|
|
||||||
map
|
map
|
||||||
(dep: {
|
libpyproject.pep508.parseString
|
||||||
inherit (dep) name;
|
item.dependencies or []
|
||||||
})
|
);
|
||||||
(lib.filter evalDep item.dependencies);
|
requiredDeps = lib.filter (isDependencyRequired environ) parsedDeps;
|
||||||
value = {
|
value = {
|
||||||
inherit dependencies;
|
dependencies = map (dep: dep.name) requiredDeps;
|
||||||
inherit (item) version;
|
inherit (item) version;
|
||||||
source = sources.${selector (lib.attrNames compatibleSources)};
|
source = sources.${selector (lib.attrNames compatibleSources)};
|
||||||
# In the future we could add additional meta data fields
|
# In the future we could add additional meta data fields
|
||||||
@ -159,33 +161,5 @@
|
|||||||
lib.nameValuePair item.name value;
|
lib.nameValuePair item.name value;
|
||||||
in
|
in
|
||||||
# TODO: packages need to be filtered on environment.
|
# TODO: packages need to be filtered on environment.
|
||||||
lib.listToAttrs (map func lock-data.package);
|
lib.listToAttrs (map parsePackage lock-data.package);
|
||||||
|
|
||||||
# }
|
|
||||||
# # Function that parses pyproject.toml and pdm.lock
|
|
||||||
# # and returns the package sets that are described.
|
|
||||||
# { pyproject-data
|
|
||||||
# , pdm-lock-data
|
|
||||||
# , lib # nixpkgs.lib
|
|
||||||
# , lib-pyproject
|
|
||||||
# }: let
|
|
||||||
# # Collect the attributes for a given package name.
|
|
||||||
# get-pkg-attrs-from-lock = pkgname: let
|
|
||||||
# # Collect version, python constraint and dependencies.
|
|
||||||
# package = lib.findSingle (pkg: pkg.name == pkgname) pkgname;
|
|
||||||
# # Collect source
|
|
||||||
# get-source = {
|
|
||||||
# version,
|
|
||||||
# }:
|
|
||||||
# attrs = pdm-lock-data.
|
|
||||||
# in {
|
|
||||||
# }
|
|
||||||
# get-group-pkgnames = groupname:
|
|
||||||
# # Collect group attributes for a given group name.
|
|
||||||
# get-group-attrs = groupname: let
|
|
||||||
# in { }
|
|
||||||
# groups = pdm-lock-data.metadata.groups;
|
|
||||||
# # Whether the project defines a library or only optional groups.
|
|
||||||
# providesLibrary = lib.elem "default" groups;
|
|
||||||
# in { }
|
|
||||||
}
|
}
|
||||||
|
@ -10,16 +10,30 @@
|
|||||||
pyproject-nix = inputs.pyproject-nix;
|
pyproject-nix = inputs.pyproject-nix;
|
||||||
libpyproject = import (pyproject-nix + "/lib") {inherit lib;};
|
libpyproject = import (pyproject-nix + "/lib") {inherit lib;};
|
||||||
|
|
||||||
|
linux_environ = lib.importJSON ./environ.json;
|
||||||
|
|
||||||
|
test_isDependencyRequired = {
|
||||||
|
test_isDependencyRequired__not_required = {
|
||||||
|
expr =
|
||||||
|
libpdm.isDependencyRequired
|
||||||
|
linux_environ
|
||||||
|
(libpyproject.pep508.parseString "foo==1.0.0; sys_platform == 'win32'");
|
||||||
|
expected = false;
|
||||||
|
};
|
||||||
|
test_isDependencyRequired__required = {
|
||||||
|
expr =
|
||||||
|
libpdm.isDependencyRequired
|
||||||
|
linux_environ
|
||||||
|
(libpyproject.pep508.parseString "foo==1.0.0; sys_platform == 'linux'");
|
||||||
|
expected = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
testIsUsableSdistFilename = filename: let
|
testIsUsableSdistFilename = filename: let
|
||||||
environ = libpyproject.pep508.mkEnviron pkgs.python3;
|
environ = libpyproject.pep508.mkEnviron pkgs.python3;
|
||||||
in
|
in
|
||||||
libpdm.isUsableSdistFilename {inherit environ filename;};
|
libpdm.isUsableSdistFilename {inherit environ filename;};
|
||||||
|
|
||||||
# test_data = {
|
|
||||||
# "sdist" = "certifi-2023.7.22.tar.gz";
|
|
||||||
# ""
|
|
||||||
# };
|
|
||||||
|
|
||||||
tests_isUsableFilename = let
|
tests_isUsableFilename = let
|
||||||
testIsUsableWheelFilename = filename: let
|
testIsUsableWheelFilename = filename: let
|
||||||
environ = libpyproject.pep508.mkEnviron pkgs.python3;
|
environ = libpyproject.pep508.mkEnviron pkgs.python3;
|
||||||
@ -148,7 +162,7 @@
|
|||||||
};
|
};
|
||||||
tests_parseLockData = let
|
tests_parseLockData = let
|
||||||
lock-data = lib.importTOML ./../../../examples/dream2nix-repo-flake-pdm/pdm.lock;
|
lock-data = lib.importTOML ./../../../examples/dream2nix-repo-flake-pdm/pdm.lock;
|
||||||
version = "2023.7.22";
|
version = "2.31.0";
|
||||||
parsed = libpdm.parseLockData {
|
parsed = libpdm.parseLockData {
|
||||||
inherit lock-data;
|
inherit lock-data;
|
||||||
environ = lib.importJSON ./environ.json;
|
environ = lib.importJSON ./environ.json;
|
||||||
@ -157,13 +171,26 @@
|
|||||||
in {
|
in {
|
||||||
test_parseLockData = {
|
test_parseLockData = {
|
||||||
expr =
|
expr =
|
||||||
(parsed ? "certifi")
|
(parsed ? "requests")
|
||||||
&& (parsed.certifi.version == version)
|
&& (parsed.requests.version == version)
|
||||||
&& (parsed.certifi ? source)
|
&& (parsed.requests ? source);
|
||||||
&& (parsed.certifi.source.url == "https://files.pythonhosted.org/packages/4c/dd/2234eab22353ffc7d94e8d13177aaa050113286e93e7b40eae01fbf7c3d9/certifi-2023.7.22-py3-none-any.whl")
|
|
||||||
&& (parsed.certifi.dependencies == []);
|
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test_parseLockData_file = {
|
||||||
|
expr = parsed.requests.source.file;
|
||||||
|
expected = "requests-2.31.0-py3-none-any.whl";
|
||||||
|
};
|
||||||
|
|
||||||
|
test_parseLockData_dependencies = {
|
||||||
|
expr = parsed.requests.dependencies;
|
||||||
|
expected = [
|
||||||
|
"certifi"
|
||||||
|
"charset-normalizer"
|
||||||
|
"idna"
|
||||||
|
"urllib3"
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
tests_isUsableFilename // tests_isValidUniversalWheel // tests_selectExtension // tests_selectSdist // tests_preferWheelSelector // tests_preferSdistSelector // tests_parseLockData
|
test_isDependencyRequired // tests_isUsableFilename // tests_isValidUniversalWheel // tests_selectExtension // tests_selectSdist // tests_preferWheelSelector // tests_preferSdistSelector // tests_parseLockData
|
||||||
|
Loading…
Reference in New Issue
Block a user