poetry2nix: 1.2.1 -> 1.3.0

This commit is contained in:
adisbladis 2020-01-13 15:45:00 +00:00
parent 244c89d537
commit 386dbd5aea
No known key found for this signature in database
GPG Key ID: 110BFAD44C6249B7
4 changed files with 237 additions and 132 deletions

View File

@ -20,16 +20,10 @@ let
getFunctorFn = fn: if builtins.typeOf fn == "set" then fn.__functor else fn; getFunctorFn = fn: if builtins.typeOf fn == "set" then fn.__functor else fn;
getAttrDefault = attribute: set: default: (
if builtins.hasAttr attribute set
then builtins.getAttr attribute set
else default
);
# Map SPDX identifiers to license names # Map SPDX identifiers to license names
spdxLicenses = lib.listToAttrs (lib.filter (pair: pair.name != null) (builtins.map (v: { name = if lib.hasAttr "spdxId" v then v.spdxId else null; value = v; }) (lib.attrValues lib.licenses))); spdxLicenses = lib.listToAttrs (lib.filter (pair: pair.name != null) (builtins.map (v: { name = if lib.hasAttr "spdxId" v then v.spdxId else null; value = v; }) (lib.attrValues lib.licenses)));
# Get license by id falling back to input string # Get license by id falling back to input string
getLicenseBySpdxId = spdxId: getAttrDefault spdxId spdxLicenses spdxId; getLicenseBySpdxId = spdxId: spdxLicenses.${spdxId} or spdxId;
# #
# Returns an attrset { python, poetryPackages } for the given lockfile # Returns an attrset { python, poetryPackages } for the given lockfile
@ -65,7 +59,7 @@ let
# closure as python can only ever have one version of a dependency # closure as python can only ever have one version of a dependency
baseOverlay = self: super: baseOverlay = self: super:
let let
getDep = depName: if builtins.hasAttr depName self then self."${depName}" else throw "foo"; getDep = depName: self.${depName};
lockPkgs = builtins.listToAttrs ( lockPkgs = builtins.listToAttrs (
builtins.map ( builtins.map (
@ -74,7 +68,7 @@ let
value = self.mkPoetryDep ( value = self.mkPoetryDep (
pkgMeta // { pkgMeta // {
inherit pwd; inherit pwd;
source = getAttrDefault "source" pkgMeta null; source = pkgMeta.source or null;
files = lockFiles.${name}; files = lockFiles.${name};
pythonPackages = self; pythonPackages = self;
} }
@ -159,12 +153,12 @@ let
passedAttrs = builtins.removeAttrs attrs specialAttrs; passedAttrs = builtins.removeAttrs attrs specialAttrs;
getDeps = depAttr: let getDeps = depAttr: let
deps = getAttrDefault depAttr pyProject.tool.poetry {}; deps = pyProject.tool.poetry.${depAttr} or {};
depAttrs = builtins.map (d: lib.toLower d) (builtins.attrNames deps); depAttrs = builtins.map (d: lib.toLower d) (builtins.attrNames deps);
in in
builtins.map (dep: py.pkgs."${dep}") depAttrs; builtins.map (dep: py.pkgs."${dep}") depAttrs;
getInputs = attr: getAttrDefault attr attrs []; getInputs = attr: attrs.${attr} or [];
mkInput = attr: extraInputs: getInputs attr ++ extraInputs; mkInput = attr: extraInputs: getInputs attr ++ extraInputs;
buildSystemPkgs = poetryLib.getBuildSystemPkgs { buildSystemPkgs = poetryLib.getBuildSystemPkgs {
@ -189,7 +183,7 @@ let
python = py; python = py;
}; };
postPatch = (getAttrDefault "postPatch" passedAttrs "") + '' 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 ${./pyproject-without-path.py} > pyproject.json
@ -199,7 +193,7 @@ let
meta = meta // { meta = meta // {
inherit (pyProject.tool.poetry) description homepage; inherit (pyProject.tool.poetry) description homepage;
license = getLicenseBySpdxId (getAttrDefault "license" pyProject.tool.poetry "unknown"); license = getLicenseBySpdxId (pyProject.tool.poetry.license or "unknown");
}; };
} }

View File

@ -30,8 +30,9 @@ let
in in
(builtins.foldl' combine initial tokens).state; (builtins.foldl' combine initial tokens).state;
fromTOML = toml: if builtins.hasAttr "fromTOML" builtins then builtins.fromTOML toml else fromTOML = builtins.fromTOML or
builtins.fromJSON ( (
toml: builtins.fromJSON (
builtins.readFile ( builtins.readFile (
pkgs.runCommand "from-toml" pkgs.runCommand "from-toml"
{ {
@ -47,6 +48,7 @@ let
-o $out -o $out
'' ''
) )
)
); );
readTOML = path: fromTOML (builtins.readFile path); readTOML = path: fromTOML (builtins.readFile path);

View File

@ -16,7 +16,13 @@
, pwd , pwd
, supportedExtensions ? lib.importJSON ./extensions.json , supportedExtensions ? lib.importJSON ./extensions.json
, ... , ...
}: let }:
pythonPackages.callPackage (
{ preferWheel ? false
}:
let
inherit (poetryLib) isCompatible getManyLinuxDeps fetchFromPypi; inherit (poetryLib) isCompatible getManyLinuxDeps fetchFromPypi;
@ -56,7 +62,9 @@
sourceDist = builtins.filter isSdist fileCandidates; sourceDist = builtins.filter isSdist fileCandidates;
eggs = builtins.filter isEgg fileCandidates; eggs = builtins.filter isEgg fileCandidates;
lockFileEntry = builtins.head (sourceDist ++ binaryDist ++ eggs); entries = (if preferWheel then binaryDist ++ sourceDist else sourceDist ++ binaryDist) ++ eggs;
lockFileEntry = builtins.head entries;
_isEgg = isEgg lockFileEntry; _isEgg = isEgg lockFileEntry;
@ -115,3 +123,5 @@ buildPythonPackage {
inherit (fileInfo) file hash kind; inherit (fileInfo) file hash kind;
}; };
} }
) {}

View File

@ -5,14 +5,6 @@
self: super: self: super:
let
getAttrDefault = attribute: set: default:
if builtins.hasAttr attribute set
then builtins.getAttr attribute set
else default;
in
{ {
av = super.av.overrideAttrs ( av = super.av.overrideAttrs (
old: { old: {
@ -52,7 +44,7 @@ in
django = ( django = (
super.django.overrideAttrs ( super.django.overrideAttrs (
old: { old: {
propagatedNativeBuildInputs = (getAttrDefault "propagatedNativeBuildInputs" old []) propagatedNativeBuildInputs = (old.propagatedNativeBuildInputs or [])
++ [ pkgs.gettext ]; ++ [ pkgs.gettext ];
} }
) )
@ -64,7 +56,7 @@ in
if ! test -e LICENSE; then if ! test -e LICENSE; then
touch LICENSE touch LICENSE
fi fi
'' + (getAttrDefault "configurePhase" old ""); '' + (old.configurePhase or "");
} }
); );
@ -85,6 +77,13 @@ in
} }
); );
# importlib-metadata has an incomplete dependency specification
importlib-metadata = super.importlib-metadata.overrideAttrs (
old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ lib.optional self.python.isPy2 self.pathlib2;
}
);
lap = super.lap.overrideAttrs ( lap = super.lap.overrideAttrs (
old: { old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ [ propagatedBuildInputs = old.propagatedBuildInputs ++ [
@ -154,6 +153,11 @@ in
} }
); );
# Calls Cargo at build time for source builds and is really tricky to package
maturin = super.maturin.override {
preferWheel = true;
};
mccabe = super.mccabe.overrideAttrs ( mccabe = super.mccabe.overrideAttrs (
old: { old: {
postPatch = '' postPatch = ''
@ -293,6 +297,93 @@ in
} }
); );
pyqt5 = super.pyqt5.overridePythonAttrs (
old: {
format = "other";
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.pkgconfig
pkgs.qt5.qmake
pkgs.xorg.lndir
pkgs.qt5.qtbase
pkgs.qt5.qtsvg
pkgs.qt5.qtdeclarative
pkgs.qt5.qtwebchannel
# self.pyqt5-sip
self.sip
];
buildInputs = old.buildInputs ++ [
pkgs.dbus
pkgs.qt5.qtbase
pkgs.qt5.qtsvg
pkgs.qt5.qtdeclarative
self.sip
];
# Fix dbus mainloop
inherit (pkgs.python3.pkgs.pyqt5) patches;
configurePhase = ''
runHook preConfigure
export PYTHONPATH=$PYTHONPATH:$out/${self.python.sitePackages}
mkdir -p $out/${self.python.sitePackages}/dbus/mainloop
${self.python.executable} configure.py -w \
--confirm-license \
--no-qml-plugin \
--bindir=$out/bin \
--destdir=$out/${self.python.sitePackages} \
--stubsdir=$out/${self.python.sitePackages}/PyQt5 \
--sipdir=$out/share/sip/PyQt5 \
--designer-plugindir=$out/plugins/designer
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;
enableParallelBuilding = true;
}
);
pytest-datadir = super.pytest-datadir.overrideAttrs (
old: {
postInstall = ''
rm -f $out/LICENSE
'';
}
);
python-prctl = super.python-prctl.overrideAttrs ( python-prctl = super.python-prctl.overrideAttrs (
old: { old: {
buildInputs = old.buildInputs ++ [ buildInputs = old.buildInputs ++ [
@ -340,6 +431,14 @@ in
} }
); );
vose-alias-method = super.pytest-datadir.overrideAttrs (
old: {
postInstall = ''
rm -f $out/LICENSE
'';
}
);
# 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 {