mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 06:21:30 +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.
|
||||
sourcesToAttrs = sources:
|
||||
lib.listToAttrs (
|
||||
map (
|
||||
source:
|
||||
lib.nameValuePair (getFilename source.url) source
|
||||
lib.nameValuePair (getFilename source.file) source
|
||||
)
|
||||
sources
|
||||
);
|
||||
@ -129,8 +135,8 @@
|
||||
selector,
|
||||
}: let
|
||||
# TODO: validate against lock file version.
|
||||
func = item: let
|
||||
sources = sourcesToAttrs lock-data.metadata.files."${item.name} ${item.version}";
|
||||
parsePackage = item: let
|
||||
sources = sourcesToAttrs item.files;
|
||||
compatibleSources =
|
||||
lib.filterAttrs
|
||||
(
|
||||
@ -138,18 +144,14 @@
|
||||
isUsableFilename {inherit environ filename;}
|
||||
)
|
||||
sources;
|
||||
evalDep = dep:
|
||||
libpyproject.pep508.evalMarkers
|
||||
environ
|
||||
(libpyproject.pep508.parseString dep);
|
||||
dependencies =
|
||||
parsedDeps = (
|
||||
map
|
||||
(dep: {
|
||||
inherit (dep) name;
|
||||
})
|
||||
(lib.filter evalDep item.dependencies);
|
||||
libpyproject.pep508.parseString
|
||||
item.dependencies or []
|
||||
);
|
||||
requiredDeps = lib.filter (isDependencyRequired environ) parsedDeps;
|
||||
value = {
|
||||
inherit dependencies;
|
||||
dependencies = map (dep: dep.name) requiredDeps;
|
||||
inherit (item) version;
|
||||
source = sources.${selector (lib.attrNames compatibleSources)};
|
||||
# In the future we could add additional meta data fields
|
||||
@ -159,33 +161,5 @@
|
||||
lib.nameValuePair item.name value;
|
||||
in
|
||||
# TODO: packages need to be filtered on environment.
|
||||
lib.listToAttrs (map func 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 { }
|
||||
lib.listToAttrs (map parsePackage lock-data.package);
|
||||
}
|
||||
|
@ -10,16 +10,30 @@
|
||||
pyproject-nix = inputs.pyproject-nix;
|
||||
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
|
||||
environ = libpyproject.pep508.mkEnviron pkgs.python3;
|
||||
in
|
||||
libpdm.isUsableSdistFilename {inherit environ filename;};
|
||||
|
||||
# test_data = {
|
||||
# "sdist" = "certifi-2023.7.22.tar.gz";
|
||||
# ""
|
||||
# };
|
||||
|
||||
tests_isUsableFilename = let
|
||||
testIsUsableWheelFilename = filename: let
|
||||
environ = libpyproject.pep508.mkEnviron pkgs.python3;
|
||||
@ -148,7 +162,7 @@
|
||||
};
|
||||
tests_parseLockData = let
|
||||
lock-data = lib.importTOML ./../../../examples/dream2nix-repo-flake-pdm/pdm.lock;
|
||||
version = "2023.7.22";
|
||||
version = "2.31.0";
|
||||
parsed = libpdm.parseLockData {
|
||||
inherit lock-data;
|
||||
environ = lib.importJSON ./environ.json;
|
||||
@ -157,13 +171,26 @@
|
||||
in {
|
||||
test_parseLockData = {
|
||||
expr =
|
||||
(parsed ? "certifi")
|
||||
&& (parsed.certifi.version == version)
|
||||
&& (parsed.certifi ? source)
|
||||
&& (parsed.certifi.source.url == "https://files.pythonhosted.org/packages/4c/dd/2234eab22353ffc7d94e8d13177aaa050113286e93e7b40eae01fbf7c3d9/certifi-2023.7.22-py3-none-any.whl")
|
||||
&& (parsed.certifi.dependencies == []);
|
||||
(parsed ? "requests")
|
||||
&& (parsed.requests.version == version)
|
||||
&& (parsed.requests ? source);
|
||||
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
|
||||
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