poetry2nix: 1.3.0 -> 1.4.0

This commit is contained in:
adisbladis 2020-01-27 07:56:23 +00:00
parent 61dbbe4121
commit 45158b5c65
No known key found for this signature in database
GPG Key ID: 110BFAD44C6249B7
5 changed files with 267 additions and 108 deletions

View File

@ -25,7 +25,6 @@ pkgs.stdenv.mkDerivation {
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
${python3.pkgs.black}/bin/black --quiet --check poetry2nix
patchShebangs poetry2nix patchShebangs poetry2nix
runHook postBuild runHook postBuild
''; '';

View File

@ -39,7 +39,11 @@ let
lockData = readTOML poetrylock; lockData = readTOML poetrylock;
lockFiles = lib.getAttrFromPath [ "metadata" "files" ] lockData; lockFiles = lib.getAttrFromPath [ "metadata" "files" ] lockData;
specialAttrs = [ "poetrylock" "overrides" ]; specialAttrs = [
"overrides"
"poetrylock"
"pwd"
];
passedAttrs = builtins.removeAttrs attrs specialAttrs; passedAttrs = builtins.removeAttrs attrs specialAttrs;
evalPep508 = mkEvalPep508 python; evalPep508 = mkEvalPep508 python;
@ -87,6 +91,8 @@ let
inherit pkgs lib python poetryLib; inherit pkgs lib python poetryLib;
}; };
poetry = poetryPkg; poetry = poetryPkg;
# The canonical name is setuptools-scm
setuptools-scm = super.setuptools_scm;
} }
) )
# Null out any filtered packages, we don't want python.pkgs from nixpkgs # Null out any filtered packages, we don't want python.pkgs from nixpkgs
@ -149,7 +155,12 @@ let
pyProject = readTOML pyproject; pyProject = readTOML pyproject;
specialAttrs = [ "pyproject" "poetrylock" "overrides" ]; specialAttrs = [
"overrides"
"poetrylock"
"pwd"
"pyproject"
];
passedAttrs = builtins.removeAttrs attrs specialAttrs; passedAttrs = builtins.removeAttrs attrs specialAttrs;
getDeps = depAttr: let getDeps = depAttr: let
@ -174,9 +185,9 @@ let
format = "pyproject"; format = "pyproject";
nativeBuildInputs = [ pkgs.yj ];
buildInputs = mkInput "buildInputs" buildSystemPkgs; buildInputs = mkInput "buildInputs" buildSystemPkgs;
propagatedBuildInputs = mkInput "propagatedBuildInputs" (getDeps "dependencies") ++ ([ py.pkgs.setuptools ]); propagatedBuildInputs = mkInput "propagatedBuildInputs" (getDeps "dependencies") ++ ([ py.pkgs.setuptools ]);
nativeBuildInputs = mkInput "nativeBuildInputs" [ pkgs.yj ];
checkInputs = mkInput "checkInputs" (getDeps "dev-dependencies"); checkInputs = mkInput "checkInputs" (getDeps "dev-dependencies");
passthru = { passthru = {
@ -186,7 +197,7 @@ let
postPatch = (passedAttrs.postPatch or "") + '' postPatch = (passedAttrs.postPatch or "") + ''
# Tell poetry not to resolve the path dependencies. Any version is # Tell poetry not to resolve the path dependencies. Any version is
# fine ! # fine !
yj -tj < pyproject.toml | python ${./pyproject-without-path.py} > pyproject.json yj -tj < pyproject.toml | ${python.interpreter} ${./pyproject-without-path.py} > pyproject.json
yj -jt < pyproject.json > pyproject.toml yj -jt < pyproject.json > pyproject.toml
rm pyproject.json rm pyproject.json
''; '';

View File

@ -20,7 +20,8 @@
pythonPackages.callPackage ( pythonPackages.callPackage (
{ preferWheel ? false { preferWheel ? false
}: , ...
}@args:
let let
@ -82,7 +83,9 @@ pythonPackages.callPackage (
else (builtins.elemAt (lib.strings.splitString "-" name) 2); else (builtins.elemAt (lib.strings.splitString "-" name) 2);
}; };
baseBuildInputs = lib.optional (name != "setuptools_scm" && name != "setuptools-scm") pythonPackages.setuptools_scm; baseBuildInputs = lib.optional (name != "setuptools_scm" && name != "setuptools-scm") pythonPackages.setuptools-scm;
format = if isLocal then "pyproject" else if isGit then "setuptools" else fileInfo.format;
in in
@ -90,26 +93,34 @@ pythonPackages.callPackage (
pname = name; pname = name;
version = version; version = version;
inherit format;
doCheck = false; # We never get development deps doCheck = false; # We never get development deps
dontStrip = true;
format = if isLocal then "pyproject" else if isGit then "setuptools" else fileInfo.format; # Stripping pre-built wheels lead to `ELF load command address/offset not properly aligned`
dontStrip = format == "wheel";
nativeBuildInputs = if (!isSource && (getManyLinuxDeps fileInfo.name).str != null) then [ autoPatchelfHook ] else []; nativeBuildInputs = if (!isSource && (getManyLinuxDeps fileInfo.name).str != null) then [ autoPatchelfHook ] else [];
buildInputs = baseBuildInputs ++ (if !isSource then (getManyLinuxDeps fileInfo.name).pkg else []); buildInputs = (
baseBuildInputs
++ lib.optional (!isSource) (getManyLinuxDeps fileInfo.name).pkg
++ lib.optional isLocal buildSystemPkgs
);
propagatedBuildInputs = propagatedBuildInputs =
let # Some dependencies like django get the attribute name django
# Some dependencies like django gets the attribute name django # but dependencies try to access Django
# but dependencies try to access Django builtins.map (n: pythonPackages.${lib.toLower n}) (builtins.attrNames dependencies);
deps = builtins.map (d: lib.toLower d) (builtins.attrNames dependencies);
in
(builtins.map (n: pythonPackages.${n}) deps) ++ (if isLocal then buildSystemPkgs else []);
meta = { meta = {
broken = ! isCompatible python.version python-versions; broken = ! isCompatible python.pythonVersion python-versions;
license = []; license = [];
}; };
passthru = {
inherit args;
};
# We need to retrieve kind from the interpreter and the filename of the package # We need to retrieve kind from the interpreter and the filename of the package
# Interpreters should declare what wheel types they're compatible with (python type + ABI) # Interpreters should declare what wheel types they're compatible with (python type + ABI)
# Here we can then choose a file based on that info. # Here we can then choose a file based on that info.

View File

@ -21,11 +21,15 @@ self: super:
} }
); );
cffi = super.cffi.overrideAttrs ( cffi =
old: { # cffi is bundled with pypy
buildInputs = old.buildInputs ++ [ pkgs.libffi ]; if self.python.implementation == "pypy" then null else (
} super.cffi.overrideAttrs (
); old: {
buildInputs = old.buildInputs ++ [ pkgs.libffi ];
}
)
);
cftime = super.cftime.overrideAttrs ( cftime = super.cftime.overrideAttrs (
old: { old: {
@ -60,9 +64,30 @@ self: super:
} }
); );
dlib = super.dlib.overrideAttrs (
old: {
# Parallel building enabled
inherit (pkgs.python.pkgs.dlib) patches;
enableParallelBuilding = true;
dontUseCmakeConfigure = true;
nativeBuildInputs = old.nativeBuildInputs ++ pkgs.dlib.nativeBuildInputs;
buildInputs = old.buildInputs ++ pkgs.dlib.buildInputs;
}
);
# Environment markers are not always included (depending on how a dep was defined) # Environment markers are not always included (depending on how a dep was defined)
enum34 = if self.pythonAtLeast "3.4" then null else super.enum34; enum34 = if self.pythonAtLeast "3.4" then null else super.enum34;
faker = super.faker.overrideAttrs (
old: {
postPatch = ''
substituteInPlace setup.py --replace 'setup_requires=["pytest-runner"],' 'setup_requires=[],' || true
'';
}
);
grandalf = super.grandalf.overrideAttrs ( grandalf = super.grandalf.overrideAttrs (
old: { old: {
postPatch = '' postPatch = ''
@ -135,22 +160,39 @@ self: super:
); );
matplotlib = super.matplotlib.overrideAttrs ( matplotlib = super.matplotlib.overrideAttrs (
old: { old: let
NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${pkgs.libcxx}/include/c++/v1"; enableGhostscript = old.passthru.enableGhostscript or false;
enableGtk3 = old.passthru.enableTk or false;
enableQt = old.passthru.enableQt or false;
enableTk = old.passthru.enableTk or false;
XDG_RUNTIME_DIR = "/tmp"; inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa;
nativeBuildInputs = old.nativeBuildInputs ++ [ in
pkgs.pkgconfig {
]; NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${pkgs.libcxx}/include/c++/v1";
propagatedBuildInputs = old.propagatedBuildInputs ++ [ XDG_RUNTIME_DIR = "/tmp";
pkgs.libpng
pkgs.freetype
];
inherit (super.matplotlib) patches; buildInputs = old.buildInputs
} ++ lib.optional enableGhostscript pkgs.ghostscript
++ lib.optional stdenv.isDarwin [ Cocoa ];
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.pkgconfig
];
propagatedBuildInputs = old.propagatedBuildInputs ++ [
pkgs.libpng
pkgs.freetype
]
++ stdenv.lib.optionals enableGtk3 [ pkgs.cairo self.pycairo pkgs.gtk3 pkgs.gobject-introspection self.pygobject3 ]
++ stdenv.lib.optionals enableTk [ pkgs.tcl pkgs.tk self.tkinter pkgs.libX11 ]
++ stdenv.lib.optionals enableQt [ self.pyqt5 ]
;
inherit (super.matplotlib) patches;
}
); );
# Calls Cargo at build time for source builds and is really tricky to package # Calls Cargo at build time for source builds and is really tricky to package
@ -191,7 +233,7 @@ self: super:
numpy = super.numpy.overrideAttrs ( numpy = super.numpy.overrideAttrs (
old: let old: let
blas = pkgs.openblasCompat; blas = old.passthru.args.blas or pkgs.openblasCompat;
blasImplementation = lib.nameFromURL blas.name "-"; blasImplementation = lib.nameFromURL blas.name "-";
cfg = pkgs.writeTextFile { cfg = pkgs.writeTextFile {
name = "site.cfg"; name = "site.cfg";
@ -222,6 +264,19 @@ self: super:
} }
); );
peewee = super.peewee.overridePythonAttrs (
old: let
withPostgres = old.passthru.withPostgres or false;
withMysql = old.passthru.withMysql or false;
in
{
buildInputs = old.buildInputs ++ [ self.cython pkgs.sqlite ];
propagatedBuildInputs = old.propagatedBuildInputs
++ lib.optional withPostgres self.psycopg2
++ lib.optional withMysql self.mysql-connector;
}
);
pillow = super.pillow.overrideAttrs ( pillow = super.pillow.overrideAttrs (
old: { old: {
nativeBuildInputs = [ pkgs.pkgconfig ] ++ old.nativeBuildInputs; nativeBuildInputs = [ pkgs.pkgconfig ] ++ old.nativeBuildInputs;
@ -297,84 +352,106 @@ self: super:
} }
); );
pyqt5 = super.pyqt5.overridePythonAttrs ( pyqt5 = let
old: { drv = super.pyqt5;
format = "other"; withConnectivity = drv.passthru.args.withConnectivity or false;
withMultimedia = drv.passthru.args.withMultimedia or false;
withWebKit = drv.passthru.args.withWebKit or false;
withWebSockets = drv.passthru.args.withWebSockets or false;
in
super.pyqt5.overridePythonAttrs (
old: {
format = "other";
nativeBuildInputs = old.nativeBuildInputs ++ [ nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.pkgconfig pkgs.pkgconfig
pkgs.qt5.qmake pkgs.qt5.qmake
pkgs.xorg.lndir pkgs.xorg.lndir
pkgs.qt5.qtbase pkgs.qt5.qtbase
pkgs.qt5.qtsvg pkgs.qt5.qtsvg
pkgs.qt5.qtdeclarative pkgs.qt5.qtdeclarative
pkgs.qt5.qtwebchannel pkgs.qt5.qtwebchannel
# self.pyqt5-sip # self.pyqt5-sip
self.sip self.sip
]; ]
++ lib.optional withConnectivity pkgs.qt5.qtconnectivity
++ lib.optional withMultimedia pkgs.qt5.qtmultimedia
++ lib.optional withWebKit pkgs.qt5.qtwebkit
++ lib.optional withWebSockets pkgs.qt5.qtwebsockets
;
buildInputs = old.buildInputs ++ [ buildInputs = old.buildInputs ++ [
pkgs.dbus pkgs.dbus
pkgs.qt5.qtbase pkgs.qt5.qtbase
pkgs.qt5.qtsvg pkgs.qt5.qtsvg
pkgs.qt5.qtdeclarative pkgs.qt5.qtdeclarative
self.sip self.sip
]; ]
++ lib.optional withConnectivity pkgs.qt5.qtconnectivity
++ lib.optional withWebKit pkgs.qt5.qtwebkit
++ lib.optional withWebSockets pkgs.qt5.qtwebsockets
;
# Fix dbus mainloop # Fix dbus mainloop
inherit (pkgs.python3.pkgs.pyqt5) patches; patches = pkgs.python3.pkgs.pyqt5.patches or [];
configurePhase = '' configurePhase = ''
runHook preConfigure runHook preConfigure
export PYTHONPATH=$PYTHONPATH:$out/${self.python.sitePackages} export PYTHONPATH=$PYTHONPATH:$out/${self.python.sitePackages}
mkdir -p $out/${self.python.sitePackages}/dbus/mainloop mkdir -p $out/${self.python.sitePackages}/dbus/mainloop
${self.python.executable} configure.py -w \ ${self.python.executable} configure.py -w \
--confirm-license \ --confirm-license \
--no-qml-plugin \ --no-qml-plugin \
--bindir=$out/bin \ --bindir=$out/bin \
--destdir=$out/${self.python.sitePackages} \ --destdir=$out/${self.python.sitePackages} \
--stubsdir=$out/${self.python.sitePackages}/PyQt5 \ --stubsdir=$out/${self.python.sitePackages}/PyQt5 \
--sipdir=$out/share/sip/PyQt5 \ --sipdir=$out/share/sip/PyQt5 \
--designer-plugindir=$out/plugins/designer --designer-plugindir=$out/plugins/designer
runHook postConfigure runHook postConfigure
'';
postInstall = ''
ln -s ${self.pyqt5-sip}/${self.python.sitePackages}/PyQt5/sip.* $out/${self.python.sitePackages}/PyQt5/
for i in $out/bin/*; do
wrapProgram $i --prefix PYTHONPATH : "$PYTHONPATH"
done
# # Let's make it a namespace package
# cat << EOF > $out/${self.python.sitePackages}/PyQt5/__init__.py
# from pkgutil import extend_path
# __path__ = extend_path(__path__, __name__)
# EOF
'';
installCheckPhase = let
modules = [
"PyQt5"
"PyQt5.QtCore"
"PyQt5.QtQml"
"PyQt5.QtWidgets"
"PyQt5.QtGui"
];
imports = lib.concatMapStrings (module: "import ${module};") modules;
in
''
echo "Checking whether modules can be imported..."
${self.python.interpreter} -c "${imports}"
''; '';
doCheck = true; postInstall = ''
ln -s ${self.pyqt5-sip}/${self.python.sitePackages}/PyQt5/sip.* $out/${self.python.sitePackages}/PyQt5/
for i in $out/bin/*; do
wrapProgram $i --prefix PYTHONPATH : "$PYTHONPATH"
done
enableParallelBuilding = true; # Let's make it a namespace package
} cat << EOF > $out/${self.python.sitePackages}/PyQt5/__init__.py
); from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
EOF
'';
installCheckPhase = let
modules = [
"PyQt5"
"PyQt5.QtCore"
"PyQt5.QtQml"
"PyQt5.QtWidgets"
"PyQt5.QtGui"
]
++ lib.optional withWebSockets "PyQt5.QtWebSockets"
++ lib.optional withWebKit "PyQt5.QtWebKit"
++ lib.optional withMultimedia "PyQt5.QtMultimedia"
++ lib.optional withConnectivity "PyQt5.QtConnectivity"
;
imports = lib.concatMapStrings (module: "import ${module};") modules;
in
''
echo "Checking whether modules can be imported..."
${self.python.interpreter} -c "${imports}"
'';
doCheck = true;
enableParallelBuilding = true;
}
);
pytest-datadir = super.pytest-datadir.overrideAttrs ( pytest-datadir = super.pytest-datadir.overrideAttrs (
old: { old: {
@ -400,9 +477,21 @@ self: super:
} }
); );
# Pybind11 is an undeclared dependency of scipy that we need to pick from nixpkgs
# Make it not fail with infinite recursion
pybind11 = super.pybind11.overridePythonAttrs (
old: {
cmakeFlags = (old.cmakeFlags or []) ++ [
"-DPYBIND11_TEST=off"
];
doCheck = false; # Circular test dependency
}
);
scipy = super.scipy.overrideAttrs ( scipy = super.scipy.overrideAttrs (
old: { old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gfortran ]; nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gfortran ];
propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.pybind11 ];
setupPyBuildFlags = [ "--fcompiler='gnu95'" ]; setupPyBuildFlags = [ "--fcompiler='gnu95'" ];
enableParallelBuilding = true; enableParallelBuilding = true;
buildInputs = old.buildInputs ++ [ self.numpy.blas ]; buildInputs = old.buildInputs ++ [ self.numpy.blas ];
@ -416,10 +505,27 @@ self: super:
} }
); );
scikit-learn = super.scikit-learn.overridePythonAttrs (
old: {
buildInputs = old.buildInputs ++ [
pkgs.gfortran
pkgs.glibcLocales
] ++ lib.optionals stdenv.cc.isClang [
pkgs.llvmPackages.openmp
];
nativeBuildInputs = old.nativeBuildInputs ++ [
self.cython
];
enableParallelBuilding = true;
}
);
shapely = super.shapely.overrideAttrs ( shapely = super.shapely.overrideAttrs (
old: { old: {
buildInputs = old.buildInputs ++ [ pkgs.geos self.cython ]; buildInputs = old.buildInputs ++ [ pkgs.geos self.cython ];
inherit (super.shapely) patches GEOS_LIBRARY_PATH; inherit (pkgs.python3.pkgs.shapely) patches GEOS_LIBRARY_PATH;
} }
); );
@ -431,7 +537,7 @@ self: super:
} }
); );
vose-alias-method = super.pytest-datadir.overrideAttrs ( vose-alias-method = super.vose-alias-method.overrideAttrs (
old: { old: {
postInstall = '' postInstall = ''
rm -f $out/LICENSE rm -f $out/LICENSE
@ -439,6 +545,15 @@ self: super:
} }
); );
uvloop = super.uvloop.overrideAttrs (
old: {
buildInputs = old.buildInputs ++ lib.optionals stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.ApplicationServices
pkgs.darwin.apple_sdk.frameworks.CoreServices
];
}
);
# Stop infinite recursion by using bootstrapped pkg from nixpkgs # Stop infinite recursion by using bootstrapped pkg from nixpkgs
wheel = ( wheel = (
pkgs.python3.pkgs.override { pkgs.python3.pkgs.override {
@ -450,4 +565,17 @@ self: super:
} }
); );
zipp =
if lib.versionAtLeast super.zipp.version "2.0.0" then (
super.zipp.overridePythonAttrs (
old: {
prePatch = ''
substituteInPlace setup.py --replace \
'setuptools.setup()' \
'setuptools.setup(version="${super.zipp.version}")'
'';
}
)
) else super.zipp;
} }

View File

@ -83,14 +83,24 @@ let
# This function also performs variable substitution, replacing environment markers with their explicit values # This function also performs variable substitution, replacing environment markers with their explicit values
transformExpressions = exprs: let transformExpressions = exprs: let
variables = { variables = {
os_name = "posix"; # TODO: Check other platforms os_name = (
if python.pname == "jython" then "java"
else "posix"
);
sys_platform = ( sys_platform = (
if stdenv.isLinux then "linux" if stdenv.isLinux then "linux"
else if stdenv.isDarwin then "darwin" else if stdenv.isDarwin then "darwin"
else throw "Unsupported platform" else throw "Unsupported platform"
); );
platform_machine = stdenv.platform.kernelArch; platform_machine = stdenv.platform.kernelArch;
platform_python_implementation = "CPython"; # Only CPython supported for now platform_python_implementation = let
impl = python.passthru.implementation;
in
(
if impl == "cpython" then "CPython"
else if impl == "pypy" then "PyPy"
else throw "Unsupported implementation ${impl}"
);
platform_release = ""; # Field not reproducible platform_release = ""; # Field not reproducible
platform_system = ( platform_system = (
if stdenv.isLinux then "Linux" if stdenv.isLinux then "Linux"
@ -100,7 +110,7 @@ let
platform_version = ""; # Field not reproducible platform_version = ""; # Field not reproducible
python_version = python.passthru.pythonVersion; python_version = python.passthru.pythonVersion;
python_full_version = python.version; python_full_version = python.version;
implementation_name = "cpython"; # Only cpython supported for now implementation_name = python.implementation;
implementation_version = python.version; implementation_version = python.version;
extra = ""; extra = "";
}; };