feat(python-pdm): initialize wheel filtering

This commit is contained in:
DavHau 2023-09-28 20:42:34 +01:00
parent 98f7fac5a1
commit 6b89285dbc
3 changed files with 125 additions and 6 deletions

View File

@ -2,6 +2,18 @@
lib,
libpyproject,
}: rec {
getFilename = url: lib.lists.last (lib.splitString "/" url);
# Convert sources to mapping with filename as key.
sourcesToAttrs = sources:
lib.listToAttrs (
map (
source:
lib.nameValuePair (getFilename source.url) source
)
sources
);
isUsableFilename = {
environ,
filename,
@ -41,6 +53,7 @@
environ,
filename,
}: let
# TODO: implement it
parsed_filename = libpyproject.pep427.parseFileName filename;
is_valid_build = true;
is_valid_implementation = true;
@ -102,19 +115,31 @@
# Returns a set with package name as key
# and as value the version, sources and dependencies
# The packages are not yet divided into groups.
parseLockData = {lock-data}: let
parseLockData = {
lock-data,
environ,
selector,
}: let
# TODO: validate against lock file version.
func = item: let
sources = sourcesToAttrs lock-data.metadata.files."${item.name} ${item.version}";
compatibleSources =
lib.filterAttrs
(
filename: source:
isUsableFilename {inherit environ filename;}
)
sources;
value = {
inherit (item) version;
requires_python = item.requires_python or null; # check already here against Python version?
sources = lock-data.metadata.files."${item.name} ${item.version}";
source = sources.${selector (lib.attrNames compatibleSources)};
# In the future we could add additional meta data fields
# such as summary
};
in
lib.nameValuePair item.name value;
in
# TODO: packages need to be filtered on environment.
lib.listToAttrs (map func lock-data.package);
# }

View File

@ -148,11 +148,20 @@
};
tests_parseLockData = let
lock-data = lib.importTOML ./../../../examples/dream2nix-repo-flake-pdm/pdm.lock;
parsed = libpdm.parseLockData {inherit lock-data;};
version = "2023.7.22";
parsed = libpdm.parseLockData {
inherit lock-data;
environ = lib.importJSON ./environ.json;
selector = libpdm.preferWheelSelector;
};
in {
test_parseLockData = {
expr = lib.elemAt (lib.attrNames parsed) 0;
expected = "certifi";
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");
expected = true;
};
};
in

View File

@ -0,0 +1,85 @@
{
"implementation_name": {
"type": "string",
"value": "cpython"
},
"implementation_version": {
"type": "version",
"value": {
"dev": null,
"epoch": 0,
"local": null,
"post": null,
"pre": null,
"release": [
3,
10,
12
]
}
},
"os_name": {
"type": "string",
"value": "posix"
},
"platform_machine": {
"type": "string",
"value": "x86_64"
},
"platform_python_implementation": {
"type": "string",
"value": "CPython"
},
"platform_release": {
"type": "string",
"value": ""
},
"platform_system": {
"type": "string",
"value": "Linux"
},
"platform_version": {
"type": "version",
"value": {
"dev": null,
"epoch": 0,
"local": null,
"post": null,
"pre": null,
"release": []
}
},
"python_full_version": {
"type": "version",
"value": {
"dev": null,
"epoch": 0,
"local": null,
"post": null,
"pre": null,
"release": [
3,
10,
12
]
}
},
"python_version": {
"type": "version",
"value": {
"dev": null,
"epoch": 0,
"local": null,
"post": null,
"pre": null,
"release": [
3,
10
]
}
},
"sys_platform": {
"type": "string",
"value": "linux"
}
}