Skip to content

Commit

Permalink
vendor: Bump pyproject.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Nov 8, 2023
1 parent 7a001e0 commit 4ccb497
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 56 deletions.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ lib.makeScope pkgs.newScope (self: {
super)

(
self: super:
self: _super:
{
mkPoetryDep = self.callPackage ./mk-poetry-dep.nix {
inherit lib python poetryLib pep508Env pyVersion;
Expand Down
8 changes: 2 additions & 6 deletions mk-poetry-dep.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let
wheelFiles = builtins.filter (fileEntry: pypa.isWheelFileName fileEntry.file) files;
# Group wheel files by their file name
wheelFilesByFileName = lib.listToAttrs (map (fileEntry: lib.nameValuePair fileEntry.file fileEntry) wheelFiles);
selectedWheels = pypa.selectWheels python (map (fileEntry: pypa.parseWheelFileName fileEntry.file) wheelFiles);
selectedWheels = pypa.selectWheels python.stdenv.targetPlatform python (map (fileEntry: pypa.parseWheelFileName fileEntry.file) wheelFiles);
in map (wheel: wheelFilesByFileName.${wheel.filename}) selectedWheels);

in
Expand Down Expand Up @@ -102,10 +102,6 @@ pythonPackages.callPackage
if _isEgg then "egg"
else if lib.strings.hasSuffix ".whl" name then "wheel"
else "pyproject";
kind =
if _isEgg then python.pythonVersion
else if format == "pyproject" then "source"
else (builtins.elemAt (lib.strings.splitString "-" name) 2);
};

format = if isWheelUrl then "wheel" else if isDirectory || isGit || isUrl then "pyproject" else fileInfo.format;
Expand Down Expand Up @@ -234,7 +230,7 @@ pythonPackages.callPackage
else
pyproject-nix.fetchers.fetchFromPypi {
pname = name;
inherit (fileInfo) file hash kind;
inherit (fileInfo) file hash;
inherit version;
};
in
Expand Down
2 changes: 1 addition & 1 deletion vendor/pyproject.nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ pkgs, lib }:
{
lib = import ./lib { inherit lib; };
fetchers = import ./fetchers { inherit pkgs lib; };
fetchers = pkgs.callPackage ./fetchers { };
}
39 changes: 24 additions & 15 deletions vendor/pyproject.nix/fetchers/default.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{ pkgs
{ curl
, jq
, lib
,
, python3
, runCommand
, stdenvNoCC
}:
let
inherit (builtins) substring filter head nixPath;
inherit (builtins) substring filter head nixPath elemAt;
inherit (lib) toLower;

pyproject = import ../lib { inherit lib; };

# Predict URL from the PyPI index.
# Args:
# pname: package name
Expand All @@ -18,10 +23,16 @@ let
pname
, # filename including extension
file
, # Language implementation and version tag
kind
,
}: "https://files.pythonhosted.org/packages/${kind}/${toLower (substring 0 1 file)}/${pname}/${file}";
}:
let
matchedWheel = pyproject.pypa.matchWheelFileName file;
matchedEgg = pyproject.pypa.matchEggFileName file;
kind =
if matchedWheel != null then "wheel"
else if matchedEgg != null then elemAt matchedEgg 2
else "source";
in
"https://files.pythonhosted.org/packages/${kind}/${toLower (substring 0 1 file)}/${pname}/${file}";
in
lib.mapAttrs (_: func: lib.makeOverridable func) {
/*
Expand All @@ -42,20 +53,18 @@ lib.mapAttrs (_: func: lib.makeOverridable func) {
version
, # SRI hash
hash
, # Language implementation and version tag
kind
, # Options to pass to `curl`
curlOpts ? ""
,
}:
let
predictedURL = predictURLFromPypi { inherit pname file kind; };
predictedURL = predictURLFromPypi { inherit pname file; };
in
pkgs.stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation {
name = file;
nativeBuildInputs = [
pkgs.buildPackages.curl
pkgs.buildPackages.jq
curl
jq
];
isWheel = lib.strings.hasSuffix "whl" file;
system = "builtin";
Expand Down Expand Up @@ -106,9 +115,9 @@ lib.mapAttrs (_: func: lib.makeOverridable func) {
then (head pathParts).path
else "";
in
pkgs.runCommand file
runCommand file
{
nativeBuildInputs = [ pkgs.buildPackages.python3 ];
nativeBuildInputs = [ python3 ];
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
outputHashMode = "flat";
outputHashAlgo = "sha256";
Expand Down
51 changes: 44 additions & 7 deletions vendor/pyproject.nix/lib/pep440.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ lib, ... }:
let
inherit (builtins) split filter match length elemAt head tail foldl' fromJSON typeOf;
inherit (builtins) split filter match length elemAt head foldl' fromJSON typeOf;
inherit (lib) fix isString toInt toLower sublist;
inherit (import ./util.nix { inherit lib; }) splitComma;

filterNull = filter (x: x != null);
filterEmpty = filter (x: length x > 0);
Expand Down Expand Up @@ -54,19 +55,19 @@ let
parseLocal = parseReleaseSuffix "\\+";

# Compare the release fields from the parsed version
compareRelease = ra: rb:
compareRelease = offset: ra: rb:
let
x = head ra;
y = head rb;
x = elemAt ra offset;
y = elemAt rb offset;
in
if length ra == 0 || length rb == 0 then 0 else
if length ra == offset || length rb == offset then 0 else
(
if x == "*" || y == "*" then 0 # Wildcards are always considered equal
else
(
if x > y then 1
else if x < y then -1
else compareRelease (tail ra) (tail rb)
else compareRelease (offset + 1) ra rb
)
);

Expand Down Expand Up @@ -160,6 +161,42 @@ fix (self: {
}
);

/* Parse a list of version conditionals separated by commas.
Type: parseVersionConds :: string -> [AttrSet]
Example:
# parseVersionConds ">=3.0.0rc1,<=4.0"
[
{
op = ">=";
version = {
dev = null;
epoch = 0;
local = null;
post = null;
pre = {
type = "rc";
value = 1;
};
release = [ 3 0 0 ];
};
}
{
op = "<=";
version = {
dev = null;
epoch = 0;
local = null;
post = null;
pre = null;
release = [ 4 0 ];
};
}
]
*/
parseVersionConds = conds: map self.parseVersionCond (splitComma conds);

/* Compare two versions as parsed by `parseVersion` according to PEP-440.
Returns:
Expand All @@ -180,7 +217,7 @@ fix (self: {
# is valid and we need to consider them all.

# Compare release field
(compareRelease a.release b.release)
(compareRelease 0 a.release b.release)

# Compare pre release
(
Expand Down
2 changes: 1 addition & 1 deletion vendor/pyproject.nix/lib/pep508.nix
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ fix (self:
m2 = match "([a-zA-Z0-9_\\.-]+)(.*)" tokens.packageSegment;

# The version conditions as a list of strings
conditions = map pep440.parseVersionCond (splitComma (if m1 != null then elemAt m1 2 else elemAt m2 1));
conditions = pep440.parseVersionConds (if m1 != null then elemAt m1 2 else elemAt m2 1);

# Extras as a list of strings
#
Expand Down
19 changes: 13 additions & 6 deletions vendor/pyproject.nix/lib/pep600.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,35 @@ fix (self: {

/* Check if a manylinux tag is compatible with a given stdenv.
Type: manyLinuxTagCompatible :: AttrSet -> string -> bool
Type: manyLinuxTagCompatible :: AttrSet -> derivation -> string -> bool
Example:
# manyLinuxTagCompatible pkgs.stdenv "manylinux_2_5_x86_64"
# manyLinuxTagCompatible pkgs.stdenv.targetPlatform pkgs.stdenv.cc.libc "manylinux_2_5_x86_64"
true
*/
manyLinuxTagCompatible = stdenv: tag:
manyLinuxTagCompatible =
# Platform attrset (`lib.systems.elaborate "x86_64-linux"`)
platform:
# Libc derivation
libc:
# Platform tag string
tag:
let
tag' = self.legacyAliases.${tag} or tag;
m = match "manylinux_([0-9]+)_([0-9]+)_(.*)" tag';
mAt = elemAt m;
tagMajor = mAt 0;
tagMinor = mAt 1;
tagArch = mAt 2;
sysVersion' = elemAt (splitVersion stdenv.cc.libc.version);
sysVersion' = elemAt (splitVersion libc.version);
sysMajor = sysVersion' 0;
sysMinor = sysVersion' 1;
in
if m == null then throw "'${tag'}' is not a valid manylinux tag."
else if stdenv.cc.libc.pname != "glibc" then false
else if platform.libc != "glibc" then false
else if libc.pname != "glibc" 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 if pep599.manyLinuxTargetMachines.${tagArch} != platform.parsed.cpu.name then false
else true;

})
2 changes: 1 addition & 1 deletion vendor/pyproject.nix/lib/pep621.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fix (self: {
# parseRequiresPython (lib.importTOML ./pyproject.toml)
[ ] # List of conditions as returned by `lib.pep440.parseVersionCond`
*/
parseRequiresPython = pyproject: map pep440.parseVersionCond (filter isString (split "," (pyproject.project.requires-python or "")));
parseRequiresPython = pyproject: pep440.parseVersionConds (pyproject.project.requires-python or "");

/* Takes a dependency structure as returned by `lib.pep621.parseDependencies` and transforms it into
a structure with it's package names.
Expand Down
19 changes: 13 additions & 6 deletions vendor/pyproject.nix/lib/pep656.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,34 @@ in
{
/* Check if a musllinux tag is compatible with a given stdenv.
Type: muslLinuxTagCompatible :: AttrSet -> string -> bool
Type: muslLinuxTagCompatible :: AttrSet -> derivation -> string -> bool
Example:
# muslLinuxTagCompatible pkgs.stdenv "musllinux_1_1_x86_64"
# muslLinuxTagCompatible pkgs.stdenv.targetPlatform pkgs.stdenv.cc.libc "musllinux_1_1_x86_64"
true
*/
muslLinuxTagCompatible = stdenv: tag:
muslLinuxTagCompatible =
# Platform attrset (`lib.systems.elaborate "x86_64-linux"`)
platform:
# Libc derivation
libc:
# Platform tag string
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);
sysVersion' = elemAt (splitVersion 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 platform.libc != "musl" then false
else if 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 if pep599.manyLinuxTargetMachines.${tagArch} != platform.parsed.cpu.name then false
else true;

}
Loading

0 comments on commit 4ccb497

Please sign in to comment.