Skip to content

Commit

Permalink
pypa: Add isSdistFileName
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Nov 3, 2023
1 parent 8929485 commit f1e9fee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lib/pypa.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ let

matchWheelFileName = match "([^-]+)-([^-]+)(-([[:digit:]][^-]*))?-([^-]+)-([^-]+)-(.+).whl";

# PEP-625 only specifies .tar.gz as valid extension but .zip is also fairly widespread.
matchSdistFileName = match "([^-]+)-(.+)(\.tar\.gz|\.zip)";

# Tag normalization documented in
# https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#details
normalizedImpls = {
Expand Down Expand Up @@ -92,6 +95,18 @@ lib.fix (self: {
rest = mAt 2;
};

/* Check whether string is a sdist file or not.
Type: isSdistFileName :: string -> bool
Example:
# isSdistFileName "cryptography-41.0.1.tar.gz"
true
*/
isSdistFileName =
# The filename string
name: matchSdistFileName name != null;

/* Check whether string is a wheel file or not.
Type: isWheelFileName :: string -> bool
Expand All @@ -100,7 +115,9 @@ lib.fix (self: {
# isWheelFileName "cryptography-41.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
true
*/
isWheelFileName = name: matchWheelFileName name != null;
isWheelFileName =
# The filename string
name: matchWheelFileName name != null;

/* Parse PEP-427 wheel file names.
Expand Down
29 changes: 28 additions & 1 deletion lib/test_pypa.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, pypa, mocks, ... }:
let
inherit (pypa) normalizePackageName parsePythonTag parseABITag parseWheelFileName isWheelFileName isPythonTagCompatible isABITagCompatible isPlatformTagCompatible isWheelFileCompatible selectWheels;
inherit (pypa) normalizePackageName parsePythonTag parseABITag parseWheelFileName isWheelFileName isPythonTagCompatible isABITagCompatible isPlatformTagCompatible isWheelFileCompatible selectWheels isSdistFileName;
inherit (lib) mapAttrs';

in
Expand Down Expand Up @@ -145,6 +145,33 @@ in
};
};

isSdistFileName = {
testSimpleZip = {
expr = isSdistFileName "debugpy-1.6.7.zip";
expected = true;
};

testSimpleTarGz = {
expr = isSdistFileName "debugpy-1.6.7.tar.gz";
expected = true;
};

testSimpleTarBz2 = {
expr = isSdistFileName "debugpy-1.6.7.tar.bz2";
expected = false;
};

testUniversalWheel = {
expr = isSdistFileName "distribution-1.0-1-py27-none-any.whl";
expected = false;
};

testWheel = {
expr = isSdistFileName "cryptography-41.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl";
expected = false;
};
};

isPythonTagCompatible = {
testPython = {
expr = isPythonTagCompatible mocks.cpythonLinux38 (parsePythonTag "py3");
Expand Down

0 comments on commit f1e9fee

Please sign in to comment.