Skip to content

Commit

Permalink
Add support for eggs
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Jan 8, 2020
1 parent c814121 commit cebf3ce
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 9 deletions.
3 changes: 2 additions & 1 deletion extensions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"egg",
"tar",
"tar.bz2",
"tar.gz",
Expand All @@ -11,4 +12,4 @@
"txz",
"whl",
"zip"
]
]
7 changes: 4 additions & 3 deletions generate.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,5 +10,6 @@

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')
25 changes: 20 additions & 5 deletions mk-poetry-dep.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/eggs/default.nix
Original file line number Diff line number Diff line change
@@ -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
''
9 changes: 9 additions & 0 deletions tests/eggs/eggs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pyasn1


def main():
print("egg-test")


if __name__ == '__main__':
main()
26 changes: 26 additions & 0 deletions tests/eggs/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/eggs/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "eggs"
version = "0.1.0"
description = "poetry2nix test"
authors = ["Your Name <[email protected]>"]

[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"

0 comments on commit cebf3ce

Please sign in to comment.