From cebf3ced84568d650fed1c3172f2d9831c21f861 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Tue, 7 Jan 2020 23:40:40 +0000 Subject: [PATCH] Add support for eggs --- extensions.json | 3 ++- generate.py | 7 ++++--- mk-poetry-dep.nix | 25 ++++++++++++++++++++----- tests/default.nix | 3 +++ tests/eggs/default.nix | 14 ++++++++++++++ tests/eggs/eggs.py | 9 +++++++++ tests/eggs/poetry.lock | 26 ++++++++++++++++++++++++++ tests/eggs/pyproject.toml | 16 ++++++++++++++++ 8 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 tests/eggs/default.nix create mode 100644 tests/eggs/eggs.py create mode 100644 tests/eggs/poetry.lock create mode 100644 tests/eggs/pyproject.toml diff --git a/extensions.json b/extensions.json index 2cce8e2..33052ef 100644 --- a/extensions.json +++ b/extensions.json @@ -1,4 +1,5 @@ [ + "egg", "tar", "tar.bz2", "tar.gz", @@ -11,4 +12,4 @@ "txz", "whl", "zip" -] \ No newline at end of file +] diff --git a/generate.py b/generate.py index 3149db5..76a6114 100755 --- a/generate.py +++ b/generate.py @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#! nix-shell -i python3 -p python3Packages.poetry +#! nix-shell -i python3 -p python3 poetry # Run code generation used by poetry2nix @@ -10,5 +10,6 @@ EXT_FILE = 'extensions.json' if __name__ == '__main__': with open(EXT_FILE, 'w') as f: - ext = sorted(ext.lstrip('.') for ext in SUPPORTED_EXTENSIONS) - f.write(json.dumps(ext, indent=2)) + ext = set(ext.lstrip('.') for ext in SUPPORTED_EXTENSIONS) + ext.add('egg') + f.write(json.dumps(sorted(ext), indent=2) + '\n') diff --git a/mk-poetry-dep.nix b/mk-poetry-dep.nix index 3631cbd..dcba409 100644 --- a/mk-poetry-dep.nix +++ b/mk-poetry-dep.nix @@ -30,8 +30,9 @@ supportedRegex = ("^.*?(" + builtins.concatStringsSep "|" supportedExtensions + ")"); matchesVersion = fname: builtins.match ("^.*" + builtins.replaceStrings [ "." ] [ "\\." ] version + ".*$") fname != null; hasSupportedExtension = fname: builtins.match supportedRegex fname != null; + isCompatibleEgg = fname: ! lib.strings.hasSuffix ".egg" fname || lib.strings.hasSuffix "py${python.pythonVersion}.egg" fname; in - builtins.filter (f: matchesVersion f.file && hasSupportedExtension f.file) files; + builtins.filter (f: matchesVersion f.file && hasSupportedExtension f.file && isCompatibleEgg f.file) files; toPath = s: pwd + "/${s}"; @@ -48,19 +49,33 @@ fileInfo = let isBdist = f: lib.strings.hasSuffix "whl" f.file; - isSdist = f: ! isBdist f; + isSdist = f: ! isBdist f && ! isEgg f; + isEgg = f: lib.strings.hasSuffix ".egg" f.file; + binaryDist = selectWheel fileCandidates; sourceDist = builtins.filter isSdist fileCandidates; - lockFileEntry = if (builtins.length sourceDist) > 0 then builtins.head sourceDist else builtins.head binaryDist; + eggs = builtins.filter isEgg fileCandidates; + + lockFileEntry = builtins.head (sourceDist ++ binaryDist ++ eggs); + + _isEgg = isEgg lockFileEntry; + in rec { inherit (lockFileEntry) file hash; name = file; - format = if lib.strings.hasSuffix ".whl" name then "wheel" else "setuptools"; - kind = if format == "setuptools" then "source" else (builtins.elemAt (lib.strings.splitString "-" name) 2); + format = + if _isEgg then "egg" + else if lib.strings.hasSuffix ".whl" name then "wheel" + else "setuptools"; + kind = + if _isEgg then python.pythonVersion + else if format == "setuptools" then "source" + else (builtins.elemAt (lib.strings.splitString "-" name) 2); }; in + buildPythonPackage { pname = name; version = version; diff --git a/tests/default.nix b/tests/default.nix index 8e3aacb..1edeca1 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -21,6 +21,9 @@ in cli = poetry2nix; path-deps = pkgs.callPackage ./path-deps { inherit poetry2nix; }; + # Egg support not yet in channel, uncomment when channel progressed + # eggs = pkgs.callPackage ./eggs { inherit poetry2nix; }; + inherit (poetry2nix) doc; # manylinux requires nixpkgs with https://github.com/NixOS/nixpkgs/pull/75763 diff --git a/tests/eggs/default.nix b/tests/eggs/default.nix new file mode 100644 index 0000000..3f900f5 --- /dev/null +++ b/tests/eggs/default.nix @@ -0,0 +1,14 @@ +{ lib, poetry2nix, python3, runCommandNoCC }: +let + drv = poetry2nix.mkPoetryApplication { + python = python3; + pyproject = ./pyproject.toml; + poetrylock = ./poetry.lock; + src = lib.cleanSource ./.; + }; + +in +runCommandNoCC "egg-test" {} '' + ${drv}/bin/egg-test + touch $out +'' diff --git a/tests/eggs/eggs.py b/tests/eggs/eggs.py new file mode 100644 index 0000000..0d4571c --- /dev/null +++ b/tests/eggs/eggs.py @@ -0,0 +1,9 @@ +import pyasn1 + + +def main(): + print("egg-test") + + +if __name__ == '__main__': + main() diff --git a/tests/eggs/poetry.lock b/tests/eggs/poetry.lock new file mode 100644 index 0000000..64fcaa7 --- /dev/null +++ b/tests/eggs/poetry.lock @@ -0,0 +1,26 @@ +[[package]] +category = "main" +description = "ASN.1 types and codecs" +name = "pyasn1" +optional = false +python-versions = "*" +version = "0.4.8" + +[metadata] +content-hash = "298cfae3c2c9739a70741fb47853558fcdda285eb1d561fedf8a36b79d3f64f1" +python-versions = "^3.6" + +[metadata.files] +pyasn1 = [ + {file = "pyasn1-0.4.8-py2.4.egg", hash = "sha256:fec3e9d8e36808a28efb59b489e4528c10ad0f480e57dcc32b4de5c9d8c9fdf3"}, + {file = "pyasn1-0.4.8-py2.5.egg", hash = "sha256:0458773cfe65b153891ac249bcf1b5f8f320b7c2ce462151f8fa74de8934becf"}, + {file = "pyasn1-0.4.8-py2.6.egg", hash = "sha256:5c9414dcfede6e441f7e8f81b43b34e834731003427e5b09e4e00e3172a10f00"}, + {file = "pyasn1-0.4.8-py2.7.egg", hash = "sha256:6e7545f1a61025a4e58bb336952c5061697da694db1cae97b116e9c46abcf7c8"}, + {file = "pyasn1-0.4.8-py3.1.egg", hash = "sha256:78fa6da68ed2727915c4767bb386ab32cdba863caa7dbe473eaae45f9959da86"}, + {file = "pyasn1-0.4.8-py3.2.egg", hash = "sha256:08c3c53b75eaa48d71cf8c710312316392ed40899cb34710d092e96745a358b7"}, + {file = "pyasn1-0.4.8-py3.3.egg", hash = "sha256:03840c999ba71680a131cfaee6fab142e1ed9bbd9c693e285cc6aca0d555e576"}, + {file = "pyasn1-0.4.8-py3.4.egg", hash = "sha256:7ab8a544af125fb704feadb008c99a88805126fb525280b2270bb25cc1d78a12"}, + {file = "pyasn1-0.4.8-py3.5.egg", hash = "sha256:e89bf84b5437b532b0803ba5c9a5e054d21fec423a89952a74f87fa2c9b7bce2"}, + {file = "pyasn1-0.4.8-py3.6.egg", hash = "sha256:014c0e9976956a08139dc0712ae195324a75e142284d5f87f1a87ee1b068a359"}, + {file = "pyasn1-0.4.8-py3.7.egg", hash = "sha256:99fcc3c8d804d1bc6d9a099921e39d827026409a58f2a720dcdb89374ea0c776"}, +] diff --git a/tests/eggs/pyproject.toml b/tests/eggs/pyproject.toml new file mode 100644 index 0000000..c96b164 --- /dev/null +++ b/tests/eggs/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "eggs" +version = "0.1.0" +description = "poetry2nix test" +authors = ["Your Name "] + +[tool.poetry.dependencies] +python = "^3.6" +pyasn1 = "^0.4.8" + +[tool.poetry.scripts] +egg-test = "eggs:main" + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api"