Merge pull request #105477 from adisbladis/poetry2nix-1_14_0

poetry2nix: 1.13.0 -> 1.14.0
This commit is contained in:
adisbladis 2020-12-01 14:52:43 +01:00 committed by GitHub
commit 25b43c2c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 270 additions and 80 deletions

View File

@ -7,60 +7,127 @@ import toml
import json import json
import sys import sys
from typing import Dict, Any, Tuple, List
argparser = argparse.ArgumentParser(description="Poetry2nix CLI")
subparsers = argparser.add_subparsers(dest="subcommand")
subparsers.required = True
parser_lock = subparsers.add_parser("lock", help="Generate overrides for git hashes",)
parser_lock.add_argument(
"--lock", default="poetry.lock", help="Path to input poetry.lock",
)
parser_lock.add_argument(
"--out", default="poetry-git-overlay.nix", help="Output file",
)
def fetch_git(pkg): class Package:
return ( def __init__(self, attrs: Dict[str, Any]) -> None:
pkg["name"], self.attrs = attrs
subprocess.run( self.name = attrs["name"]
[ self.source = self.attrs["source"]
"nix-prefetch-git",
"--fetch-submodules", def fetch(self) -> Tuple["Package", subprocess.CompletedProcess]:
"--url", raise NotImplementedError()
pkg["source"]["url"],
"--rev", def expression(self, output: str) -> str:
pkg["source"]["reference"], raise NotImplementedError()
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, class UrlPackage(Package):
), def fetch(self) -> Tuple[Package, subprocess.CompletedProcess]:
return (
self,
subprocess.run(
[
"nix-prefetch-url",
"--unpack",
self.source["url"],
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
),
)
def expression(self, output: str) -> str:
sha256 = output.rstrip()
return textwrap.dedent("""
%s = super.%s.overridePythonAttrs (
_: {
src = pkgs.fetchzip {
url = "%s";
sha256 = "%s";
};
}
);""" % (self.name, self.name, self.source["url"], sha256))
class GitPackage(Package):
def fetch(self) -> Tuple[Package, subprocess.CompletedProcess]:
reference = self.source.get("resolved_reference", self.source["reference"])
return (
self,
subprocess.run(
[
"nix-prefetch-git",
"--fetch-submodules",
"--url",
self.source["url"],
"--rev",
reference,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
),
)
def expression(self, output: str) -> str:
meta = json.loads(output)
return textwrap.dedent("""
%s = super.%s.overridePythonAttrs (
_: {
src = pkgs.fetchgit {
url = "%s";
rev = "%s";
sha256 = "%s";
};
}
);""" % (self.name, self.name, meta["url"], meta["rev"], meta["sha256"]))
def parse_args() -> argparse.Namespace:
argparser = argparse.ArgumentParser(description="Poetry2nix CLI")
subparsers = argparser.add_subparsers(dest="subcommand")
subparsers.required = True
parser_lock = subparsers.add_parser("lock", help="Generate overrides for git hashes",)
parser_lock.add_argument(
"--lock", default="poetry.lock", help="Path to input poetry.lock",
) )
parser_lock.add_argument(
"--out", default="poetry-git-overlay.nix", help="Output file",
)
return argparser.parse_args()
def indent(expr, spaces=2): def indent(expr: str, spaces: int = 2) -> str:
i = " " * spaces i = " " * spaces
return "\n".join([(i if l != "" else "") + l for l in expr.split("\n")]) return "\n".join([(i if l != "" else "") + l for l in expr.split("\n")])
if __name__ == "__main__": def main() -> None:
args = argparser.parse_args() args = parse_args()
with open(args.lock) as lockf: with open(args.lock) as lockf:
lock = toml.load(lockf) lock = toml.load(lockf)
pkgs = [] pkgs: List[Package] = []
for pkg in lock["package"]: for pkg in lock["package"]:
if "source" in pkg: if "source" in pkg:
pkgs.append(pkg) source_type = pkg["source"]["type"]
if source_type == "git":
pkgs.append(GitPackage(pkg))
elif source_type == "url":
pkgs.append(UrlPackage(pkg))
with ThreadPoolExecutor() as e: with ThreadPoolExecutor() as e:
futures = [] futures = []
for pkg in pkgs: for pkg in pkgs:
futures.append(e.submit(fetch_git, pkg)) futures.append(e.submit(pkg.fetch))
lines = [ lines = [
"{ pkgs }:", "{ pkgs }:",
@ -68,30 +135,13 @@ if __name__ == "__main__":
] ]
for f in futures: for f in futures:
drv_name, p = f.result() package, p = f.result()
if p.returncode != 0: if p.returncode != 0:
sys.stderr.buffer.write(p.stderr) sys.stderr.write(p.stderr)
sys.stderr.buffer.flush() sys.stderr.flush()
exit(p.returncode) exit(p.returncode)
expr = package.expression(p.stdout)
meta = json.loads(p.stdout.decode()) lines.append(indent(expr))
lines.append(
indent(
textwrap.dedent(
"""
%s = super.%s.overridePythonAttrs (
_: {
src = pkgs.fetchgit {
url = "%s";
rev = "%s";
sha256 = "%s";
};
}
);"""
% (drv_name, drv_name, meta["url"], meta["rev"], meta["sha256"])
)
)
)
lines.extend(["", "}", ""]) lines.extend(["", "}", ""])
@ -101,3 +151,7 @@ if __name__ == "__main__":
fout.write(expr) fout.write(expr)
print(f"Wrote {args.out}") print(f"Wrote {args.out}")
if __name__ == "__main__":
main()

View File

@ -71,7 +71,7 @@ in
lib.makeScope pkgs.newScope (self: { lib.makeScope pkgs.newScope (self: {
# Poetry2nix version # Poetry2nix version
version = "1.13.0"; version = "1.14.0";
/* /*
Returns an attrset { python, poetryPackages, pyProject, poetryLock } for the given pyproject/lockfile. Returns an attrset { python, poetryPackages, pyProject, poetryLock } for the given pyproject/lockfile.

View File

@ -1,11 +1,11 @@
{ python { python
, callPackage , buildPackages
, makeSetupHook , makeSetupHook
, yj
, wheel , wheel
, pip , pip
}: }:
let let
callPackage = python.pythonForBuild.pkgs.callPackage;
pythonInterpreter = python.pythonForBuild.interpreter; pythonInterpreter = python.pythonForBuild.interpreter;
pythonSitePackages = python.sitePackages; pythonSitePackages = python.sitePackages;
in in
@ -20,7 +20,7 @@ in
deps = [ ]; deps = [ ];
substitutions = { substitutions = {
inherit pythonInterpreter; inherit pythonInterpreter;
yj = "${yj}/bin/yj"; yj = "${buildPackages.yj}/bin/yj";
pyprojectPatchScript = "${./pyproject-without-path.py}"; pyprojectPatchScript = "${./pyproject-without-path.py}";
}; };
} ./remove-path-dependencies.sh } ./remove-path-dependencies.sh

View File

@ -27,6 +27,7 @@ pythonPackages.callPackage
, ... , ...
}@args: }@args:
let let
inherit (pkgs) stdenv;
inherit (poetryLib) isCompatible getManyLinuxDeps fetchFromPypi moduleName; inherit (poetryLib) isCompatible getManyLinuxDeps fetchFromPypi moduleName;
inherit (import ./pep425.nix { inherit (import ./pep425.nix {
@ -45,6 +46,7 @@ pythonPackages.callPackage
toPath = s: pwd + "/${s}"; toPath = s: pwd + "/${s}";
isSource = source != null; isSource = source != null;
isGit = isSource && source.type == "git"; isGit = isSource && source.type == "git";
isUrl = isSource && source.type == "url";
isLocal = isSource && source.type == "directory"; isLocal = isSource && source.type == "directory";
localDepPath = toPath source.url; localDepPath = toPath source.url;
@ -91,7 +93,7 @@ pythonPackages.callPackage
"toml" # Toml is an extra for setuptools-scm "toml" # Toml is an extra for setuptools-scm
]; ];
baseBuildInputs = lib.optional (! lib.elem name skipSetupToolsSCM) pythonPackages.setuptools-scm; baseBuildInputs = lib.optional (! lib.elem name skipSetupToolsSCM) pythonPackages.setuptools-scm;
format = if isLocal then "pyproject" else if isGit then "pyproject" else fileInfo.format; format = if isLocal || isGit || isUrl then "pyproject" else fileInfo.format;
in in
buildPythonPackage { buildPythonPackage {
pname = moduleName name; pname = moduleName name;
@ -113,9 +115,10 @@ pythonPackages.callPackage
buildInputs = ( buildInputs = (
baseBuildInputs baseBuildInputs
++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) pythonPackages.setuptools
++ lib.optional (!isSource) (getManyLinuxDeps fileInfo.name).pkg ++ lib.optional (!isSource) (getManyLinuxDeps fileInfo.name).pkg
++ lib.optional isLocal buildSystemPkgs ++ lib.optional isLocal buildSystemPkgs
++ lib.optional (!__isBootstrap) [ pythonPackages.poetry ] ++ lib.optional (!__isBootstrap) pythonPackages.poetry
); );
propagatedBuildInputs = propagatedBuildInputs =
@ -157,14 +160,22 @@ pythonPackages.callPackage
( (
builtins.fetchGit { builtins.fetchGit {
inherit (source) url; inherit (source) url;
rev = source.reference; rev = source.resolved_reference or source.reference;
ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD"; ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD";
} }
) else if isLocal then (poetryLib.cleanPythonSources { src = localDepPath; }) else )
fetchFromPypi { else if isUrl then
pname = name; builtins.fetchTarball
inherit (fileInfo) file hash kind; {
}; inherit (source) url;
}
else if isLocal then
(poetryLib.cleanPythonSources { src = localDepPath; })
else
fetchFromPypi {
pname = name;
inherit (fileInfo) file hash kind;
};
} }
) )
{ } { }

View File

@ -93,7 +93,7 @@ self: super:
( (
super.cffi.overridePythonAttrs ( super.cffi.overridePythonAttrs (
old: { old: {
buildInputs = old.buildInputs ++ [ pkgs.libffi ]; buildInputs = old.buildInputs or [ ] ++ [ pkgs.libffi ];
} }
) )
); );
@ -106,6 +106,12 @@ self: super:
} }
); );
colour = super.colour.overridePythonAttrs (
old: {
buildInputs = old.buildInputs ++ [ self.d2to1 ];
}
);
configparser = super.configparser.overridePythonAttrs ( configparser = super.configparser.overridePythonAttrs (
old: { old: {
buildInputs = old.buildInputs ++ [ buildInputs = old.buildInputs ++ [
@ -120,6 +126,8 @@ self: super:
cryptography = super.cryptography.overridePythonAttrs ( cryptography = super.cryptography.overridePythonAttrs (
old: { old: {
nativeBuildInputs = old.nativeBuildInputs or [ ]
++ stdenv.lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) self.python.pythonForBuild.pkgs.cffi;
buildInputs = old.buildInputs ++ [ pkgs.openssl ]; buildInputs = old.buildInputs ++ [ pkgs.openssl ];
} }
); );
@ -324,6 +332,17 @@ self: super:
} }
); );
jira = super.jira.overridePythonAttrs (
old: {
inherit (pkgs.python3Packages.jira) patches;
buildInputs = old.buildInputs ++ [
self.pytestrunner
self.cryptography
self.pyjwt
];
}
);
jsonpickle = super.jsonpickle.overridePythonAttrs ( jsonpickle = super.jsonpickle.overridePythonAttrs (
old: { old: {
dontPreferSetupPy = true; dontPreferSetupPy = true;
@ -499,6 +518,31 @@ self: super:
buildInputs = oa.buildInputs ++ [ self.pbr ]; buildInputs = oa.buildInputs ++ [ self.pbr ];
}); });
mpi4py = super.mpi4py.overridePythonAttrs (
old:
let
cfg = pkgs.writeTextFile {
name = "mpi.cfg";
text = (
lib.generators.toINI
{ }
{
mpi = {
mpicc = "${pkgs.openmpi.outPath}/bin/mpicc";
};
}
);
};
in
{
propagatedBuildInputs = old.propagatedBuildInputs ++ [ pkgs.openmpi ];
enableParallelBuilding = true;
preBuild = ''
ln -sf ${cfg} mpi.cfg
'';
}
);
multiaddr = super.multiaddr.overridePythonAttrs ( multiaddr = super.multiaddr.overridePythonAttrs (
old: { old: {
buildInputs = old.buildInputs ++ [ self.pytest-runner ]; buildInputs = old.buildInputs ++ [ self.pytest-runner ];
@ -584,8 +628,8 @@ self: super:
withMysql = old.passthru.withMysql or false; withMysql = old.passthru.withMysql or false;
in in
{ {
buildInputs = old.buildInputs ++ [ self.cython pkgs.sqlite ]; buildInputs = old.buildInputs or [ ] ++ [ pkgs.sqlite ];
propagatedBuildInputs = old.propagatedBuildInputs propagatedBuildInputs = old.propagatedBuildInputs or [ ]
++ lib.optional withPostgres self.psycopg2 ++ lib.optional withPostgres self.psycopg2
++ lib.optional withMysql self.mysql-connector; ++ lib.optional withMysql self.mysql-connector;
} }
@ -602,8 +646,8 @@ self: super:
# "Vendor" dependencies (for build-system support) # "Vendor" dependencies (for build-system support)
postPatch = '' postPatch = ''
echo "import sys" >> poetry/__init__.py echo "import sys" >> poetry/__init__.py
for path in ''${PYTHONPATH//:/ }; do echo $path; done | uniq | while read path; do for path in $propagatedBuildInputs; do
echo "sys.path.insert(0, \"$path\")" >> poetry/__init__.py echo "sys.path.insert(0, \"$path\")" >> poetry/__init__.py
done done
''; '';
@ -796,6 +840,14 @@ self: super:
} }
); );
python-bugzilla = super.python-bugzilla.overridePythonAttrs (
old: {
nativeBuildInputs = old.nativeBuildInputs ++ [
self.docutils
];
}
);
python-ldap = super.python-ldap.overridePythonAttrs ( python-ldap = super.python-ldap.overridePythonAttrs (
old: { old: {
buildInputs = old.buildInputs ++ [ pkgs.openldap pkgs.cyrus_sasl ]; buildInputs = old.buildInputs ++ [ pkgs.openldap pkgs.cyrus_sasl ];
@ -924,6 +976,15 @@ self: super:
} }
); );
pytest-django = super.pytest-django.overridePythonAttrs (
old: {
postPatch = ''
substituteInPlace setup.py --replace "'pytest>=3.6'," ""
substituteInPlace setup.py --replace "'pytest>=3.6'" ""
'';
}
);
pytest-runner = super.pytest-runner or super.pytestrunner; pytest-runner = super.pytest-runner or super.pytestrunner;
python-jose = super.python-jose.overridePythonAttrs ( python-jose = super.python-jose.overridePythonAttrs (
@ -1090,6 +1151,43 @@ self: super:
} }
); );
torch = lib.makeOverridable
({ enableCuda ? false
, cudatoolkit ? pkgs.cudatoolkit_10_1
, pkg ? super.torch
}: pkg.overrideAttrs (old:
{
preConfigure =
if (!enableCuda) then ''
export USE_CUDA=0
'' else ''
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${cudatoolkit}/targets/x86_64-linux/lib"
'';
preFixup = lib.optionalString (!enableCuda) ''
# For some reason pytorch retains a reference to libcuda even if it
# is explicitly disabled with USE_CUDA=0.
find $out -name "*.so" -exec ${pkgs.patchelf}/bin/patchelf --remove-needed libcuda.so.1 {} \;
'';
buildInputs = old.buildInputs ++ lib.optionals enableCuda [
pkgs.linuxPackages.nvidia_x11
pkgs.nccl.dev
pkgs.nccl.out
];
propagatedBuildInputs = [
super.numpy
super.future
];
})
)
{ };
typeguard = super.typeguard.overridePythonAttrs (old: {
postPatch = ''
substituteInPlace setup.py \
--replace 'setup()' 'setup(version="${old.version}")'
'';
});
# nix uses a dash, poetry uses an underscore # nix uses a dash, poetry uses an underscore
typing_extensions = super.typing_extensions or self.typing-extensions; typing_extensions = super.typing_extensions or self.typing-extensions;
@ -1193,4 +1291,30 @@ self: super:
} }
); );
credis = super.credis.overridePythonAttrs (
old: {
buildInputs = old.buildInputs ++ [ self.cython ];
}
);
hashids = super.hashids.overridePythonAttrs (
old: {
buildInputs = old.buildInputs ++ [ self.flit-core ];
}
);
supervisor = super.supervisor.overridePythonAttrs (
old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ [
self.meld3
self.setuptools
];
}
);
cytoolz = super.cytoolz.overridePythonAttrs (
old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.toolz ];
}
);
} }

View File

@ -87,7 +87,7 @@ let
filtered = builtins.filter filterWheel filesWithoutSources; filtered = builtins.filter filterWheel filesWithoutSources;
choose = files: choose = files:
let let
osxMatches = [ "10_12" "10_11" "10_10" "10_9" "any" ]; osxMatches = [ "10_12" "10_11" "10_10" "10_9" "10_8" "10_7" "any" ];
linuxMatches = [ "manylinux1_" "manylinux2010_" "manylinux2014_" "any" ]; linuxMatches = [ "manylinux1_" "manylinux2010_" "manylinux2014_" "any" ];
chooseLinux = x: lib.take 1 (findBestMatches linuxMatches x); chooseLinux = x: lib.take 1 (findBestMatches linuxMatches x);
chooseOSX = x: lib.take 1 (findBestMatches osxMatches x); chooseOSX = x: lib.take 1 (findBestMatches osxMatches x);

View File

@ -15,8 +15,8 @@ poetry2nix.mkPoetryApplication {
# "Vendor" dependencies (for build-system support) # "Vendor" dependencies (for build-system support)
postPatch = '' postPatch = ''
echo "import sys" >> poetry/__init__.py echo "import sys" >> poetry/__init__.py
for path in ''${PYTHONPATH//:/ }; do echo $path; done | uniq | while read path; do for path in $propagatedBuildInputs; do
echo "sys.path.insert(0, \"$path\")" >> poetry/__init__.py echo "sys.path.insert(0, \"$path\")" >> poetry/__init__.py
done done
''; '';

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "poetry" name = "poetry"
version = "1.1.0" version = "1.1.4"
description = "Python dependency management and packaging made easy." description = "Python dependency management and packaging made easy."
authors = [ authors = [
"Sébastien Eustace <sebastien@eustace.io>" "Sébastien Eustace <sebastien@eustace.io>"

View File

@ -1,7 +1,7 @@
{ {
"owner": "python-poetry", "owner": "python-poetry",
"repo": "poetry", "repo": "poetry",
"rev": "539d7f732c34c821258a9853cd3078cbda34a717", "rev": "8312e3f2dbfa126cd311c666fea30656941e1bd3",
"sha256": "0kl23dkq9n112z1pqjg6f1wv3qk77ij6q5glg15lwrj7yrl9k65c", "sha256": "0lx3qpz5dad0is7ki5a4vxphvc8cm8fnv4bmrx226a6nvvaj6ahs",
"fetchSubmodules": true "fetchSubmodules": true
} }

View File

@ -23,6 +23,7 @@ let
dontConfigure = true; dontConfigure = true;
dontBuild = true; dontBuild = true;
dontUsePythonRecompileBytecode = true;
passthru = { passthru = {
inherit (drv.passthru) withPlugins; inherit (drv.passthru) withPlugins;

View File

@ -1,4 +1,4 @@
{ lib, python3, fetchFromGitHub, poetry, nixosTests }: { lib, python3, fetchFromGitHub, nixosTests }:
let let
python = python3.override { python = python3.override {