vendor: Bump pyproject.nix

This commit is contained in:
adisbladis 2023-10-30 14:32:21 +13:00
parent f439d199fc
commit 307f2c4c7c
7 changed files with 335 additions and 62 deletions

View file

@ -18,6 +18,8 @@
includes = [ "overrides/build-systems.json" ];
excludes = [ ];
};
black.excludes = [ "vendor/**.py" ];
};
programs.deadnix.enable = true;

View file

@ -77,9 +77,7 @@ req = urllib.request.Request(index_url)
if username and password:
import base64
password_b64 = base64.b64encode(":".join((username, password)).encode()).decode(
"utf-8"
)
password_b64 = base64.b64encode(":".join((username, password)).encode()).decode("utf-8")
req.add_header("Authorization", "Basic {}".format(password_b64))
response = urllib.request.urlopen(req, context=context)
index = response.read()
@ -87,9 +85,7 @@ index = response.read()
parser = Pep503()
parser.feed(str(index, "utf-8"))
if package_filename not in parser.sources:
print(
"The file %s has not be found in the index %s" % (package_filename, index_url)
)
print("The file %s has not be found in the index %s" % (package_filename, index_url))
exit(1)
package_file = open(package_filename, "wb")

View file

@ -12,11 +12,11 @@ fix (self: mapAttrs (_: path: import path ({ inherit lib; } // self)) {
validators = ./validators.nix;
poetry = ./poetry.nix;
pep427 = ./pep427.nix;
pep440 = ./pep440.nix;
pep508 = ./pep508.nix;
pep518 = ./pep518.nix;
pep599 = ./pep599.nix;
pep600 = ./pep600.nix;
pep621 = ./pep621.nix;
pep656 = ./pep656.nix;
})

View file

@ -1,49 +0,0 @@
_:
let
inherit (builtins) match elemAt split filter isString;
matchFileName = match "([^-]+)-([^-]+)(-([[:digit:]][^-]*))?-([^-]+)-([^-]+)-(.+).whl";
in
{
/* Check whether string is a wheel file or not.
Type: isWheelFileName :: string -> bool
Example:
# isWheelFileName "cryptography-41.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
true
*/
isWheelFileName = name: matchFileName name != null;
/* Parse PEP-427 wheel file names.
Type: parseFileName :: string -> AttrSet
Example:
# parseFileName "cryptography-41.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
{
abiTag = "abi3";
buildTag = null;
distribution = "cryptography";
languageTag = "cp37";
platformTags = [ "manylinux_2_17_aarch64" "manylinux2014_aarch64" ];
version = "41.0.1";
}
*/
parseFileName =
# The wheel filename is `{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl`.
name:
let
m = matchFileName name;
mAt = elemAt m;
in
assert m != null; {
distribution = mAt 0;
version = mAt 1;
buildTag = mAt 3;
languageTag = mAt 4;
abiTag = mAt 5;
platformTags = filter isString (split "\\." (mAt 6));
};
}

View file

@ -13,8 +13,8 @@ _:
i686 = "i686";
aarch64 = "aarch64";
armv7l = "armv7l";
powerpc64 = "ppc64";
powerpc64le = "ppc64le";
ppc64 = "powerpc64";
ppc64le = "powerpc64le";
s390x = "s390x";
};
}

33
vendor/pyproject.nix/lib/pep656.nix vendored Normal file
View file

@ -0,0 +1,33 @@
{ pep599, ... }:
let
inherit (builtins) match elemAt compareVersions splitVersion;
in
{
/* Check if a musllinux tag is compatible with a given stdenv.
Type: muslLinuxTagCompatible :: AttrSet -> string -> bool
Example:
# muslLinuxTagCompatible pkgs.stdenv "musllinux_1_1_x86_64"
true
*/
muslLinuxTagCompatible = stdenv: tag:
let
m = match "musllinux_([0-9]+)_([0-9]+)_(.*)" tag;
mAt = elemAt m;
tagMajor = mAt 0;
tagMinor = mAt 1;
tagArch = mAt 2;
sysVersion' = elemAt (splitVersion stdenv.cc.libc.version);
sysMajor = sysVersion' 0;
sysMinor = sysVersion' 1;
in
if m == null then throw "'${tag}' is not a valid musllinux tag."
else if stdenv.cc.libc.pname != "musl" then false
else if compareVersions "${sysMajor}.${sysMinor}" "${tagMajor}.${tagMinor}" < 0 then false
else if pep599.manyLinuxTargetMachines.${tagArch} != stdenv.targetPlatform.parsed.cpu.name then false
else true;
}

View file

@ -1,10 +1,45 @@
{ lib, ... }:
{ lib, pep600, pep656, ... }:
let
inherit (builtins) concatStringsSep filter split;
inherit (builtins) concatStringsSep filter split match elemAt compareVersions;
inherit (lib) isString toLower;
inherit (lib.strings) hasPrefix;
matchWheelFileName = match "([^-]+)-([^-]+)(-([[:digit:]][^-]*))?-([^-]+)-([^-]+)-(.+).whl";
# Tag normalization documented in
# https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#details
normalizedImpls = {
py = "python";
cp = "cpython";
ip = "ironpython";
pp = "pypy";
jy = "jython";
};
normalizeImpl = t: normalizedImpls.${t} or t;
optionalString = s: if s != "" then s else null;
parseTagVersion = v:
let
m = match "([0-9])([0-9]*)" v;
mAt = elemAt m;
in
if v == "" then null else assert m != null; {
major = mAt 0;
minor = optionalString (mAt 1);
};
checkTagVersion = sourceVersion: tagVersion: tagVersion == null || (
tagVersion.major == sourceVersion.major && (
tagVersion.minor == null || (
(compareVersions sourceVersion.minor tagVersion.minor) >= 0
)
)
);
in
{
lib.fix (self: {
/* Normalize package name as documented in https://packaging.python.org/en/latest/specifications/name-normalization/#normalization
Type: normalizePackageName :: string -> string
@ -19,4 +54,260 @@ in
splitSep = split "[-_\.]+";
in
name: toLower (concatDash (filter isString (splitSep name)));
}
/* Parse Python tags.
As described in https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#python-tag.
Type: parsePythonTag :: string -> AttrSet
Example:
# parsePythonTag "cp37"
{
implementation = "cpython";
version = {
major = "3";
minor = "7";
};
}
*/
parsePythonTag =
tag:
let
m = match "([a-z]+)([0-9]*)" tag;
mAt = elemAt m;
in
assert m != null; {
implementation = normalizeImpl (mAt 0);
version = parseTagVersion (mAt 1);
};
/* Parse ABI tags.
As described in https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#python-tag.
Type: parseABITag :: string -> AttrSet
Example:
# parseABITag "cp37dmu"
{
rest = "dmu";
implementation = "cp";
version = {
major = "3";
minor = "7";
};
}
*/
parseABITag =
tag:
let
m = match "([a-z]+)([0-9]*)_?([a-z0-9]*)" tag;
mAt = elemAt m;
in
assert m != null; {
implementation = normalizeImpl (mAt 0);
version = parseTagVersion (mAt 1);
rest = mAt 2;
};
/* Check whether string is a wheel file or not.
Type: isWheelFileName :: string -> bool
Example:
# isWheelFileName "cryptography-41.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
true
*/
isWheelFileName = name: matchWheelFileName name != null;
/* Parse PEP-427 wheel file names.
Type: parseFileName :: string -> AttrSet
Example:
# parseFileName "cryptography-41.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
{
abiTag = { # Parsed by pypa.parseABITag
implementation = "abi";
version = {
major = "3";
minor = null;
};
flags = [ ];
};
buildTag = null;
distribution = "cryptography";
languageTags = [ # Parsed by pypa.parsePythonTag
{
implementation = "cpython";
version = {
major = "3";
minor = "7";
};
}
];
platformTags = [ "manylinux_2_17_aarch64" "manylinux2014_aarch64" ];
version = "41.0.1";
}
*/
parseWheelFileName =
# The wheel filename is `{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl`.
name:
let
m = matchWheelFileName name;
mAt = elemAt m;
in
assert m != null; {
distribution = mAt 0;
version = mAt 1;
buildTag = mAt 3;
languageTags = map self.parsePythonTag (filter isString (split "\\." (mAt 4)));
abiTag = self.parseABITag (mAt 5);
platformTags = filter isString (split "\\." (mAt 6));
};
/* Check whether an ABI tag is compatible with this python interpreter.
Type: isABITagCompatible :: derivation -> string -> bool
Example:
# isABITagCompatible pkgs.python3 (pypa.parseABITag "cp37")
true
*/
isABITagCompatible =
# Python interpreter derivation
python:
# ABI tag string
abiTag:
let
inherit (python.passthru) sourceVersion implementation;
in
(
# None is a wildcard compatible with any implementation
(abiTag.implementation == "none" || abiTag.implementation == "any")
||
# implementation == sys.implementation.name
abiTag.implementation == implementation
||
# The CPython stable ABI is abi3 as in the shared library suffix.
(abiTag.implementation == "abi" && implementation == "cpython")
)
&&
# Check version
(
checkTagVersion sourceVersion abiTag.version
);
/* Check whether a platform tag is compatible with this python interpreter.
Type: isPlatformTagCompatible :: derivation -> string -> bool
Example:
# isPlatformTagCompatible pkgs.python3 "manylinux2014_x86_64"
true
*/
isPlatformTagCompatible =
# Python interpreter derivation
python:
# Python tag
platformTag:
let
platform = python.stdenv.targetPlatform;
in
if platformTag == "any" then true
else if hasPrefix "manylinux" platformTag then pep600.manyLinuxTagCompatible python.stdenv platformTag
else if hasPrefix "musllinux" platformTag then pep656.muslLinuxTagCompatible python.stdenv platformTag
else if hasPrefix "macosx" platformTag then
(
let
m = match "macosx_([0-9]+)_([0-9]+)_(.+)" platformTag;
mAt = elemAt m;
major = mAt 0;
minor = mAt 1;
arch = mAt 2;
in
assert m != null; (
platform.isDarwin
&&
((arch == "universal2" && (platform.darwinArch == "arm64" || platform.darwinArch == "x86_64")) || arch == platform.darwinArch)
&&
compareVersions platform.darwinSdkVersion "${major}.${minor}" >= 0
)
)
else if platformTag == "win32" then (platform.isWindows && platform.is32Bit && platform.isx86)
else if hasPrefix "win_" platformTag then
(
let
m = match "win_(.+)" platformTag;
arch = elemAt m 0;
in
assert m != null;
platform.isWindows && (
# Note that these platform mappings are incomplete.
# Nixpkgs should gain windows platform tags so we don't have to map them manually here.
if arch == "amd64" then platform.isx86_64
else if arch == "arm64" then platform.isAarch64
else false
)
)
else if hasPrefix "linux" platformTag then
(
let
m = match "linux_(.+)" platformTag;
arch = elemAt m 0;
in
assert m != null;
platform.isLinux && arch == platform.linuxArch
)
else throw "Unknown platform tag: '${platformTag}'";
/* Check whether a Python language tag is compatible with this Python interpreter.
Type: isPythonTagCompatible :: derivation -> AttrSet -> bool
Example:
# isPlatformTagCompatible pkgs.python3 (pypa.parsePythonTag "py3")
true
*/
isPythonTagCompatible =
# Python interpreter derivation
python:
# Python tag
pythonTag:
let
inherit (python.passthru) sourceVersion implementation;
in
(
# Python is a wildcard compatible with any implementation
pythonTag.implementation == "python"
||
# implementation == sys.implementation.name
pythonTag.implementation == implementation
)
&&
# Check version
checkTagVersion sourceVersion pythonTag.version
;
/* Check whether wheel file name is compatible with this python interpreter.
Type: isWheelFileCompatible :: derivation -> AttrSet -> bool
Example:
# isWheelFileCompatible pkgs.python3 (pypa.parseWheelFileName "Pillow-9.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl")
true
*/
isWheelFileCompatible =
# Python interpreter derivation
python:
# The parsed wheel filename
file:
(
self.isABITagCompatible python file.abiTag
&&
lib.any (self.isPythonTagCompatible python) file.languageTags
&&
lib.any (self.isPlatformTagCompatible python) file.platformTags
);
})