diff options
author | adisbladis <adisbladis@gmail.com> | 2020-01-13 15:45:00 +0000 |
---|---|---|
committer | adisbladis <adisbladis@gmail.com> | 2020-01-13 15:46:46 +0000 |
commit | 386dbd5aea22f34f4902c7fce541586e5236b0bb (patch) | |
tree | 6b245f8c3c678caeb0527afc847c4db1a743f418 /pkgs/development/tools | |
parent | 244c89d537affb759f6509c51a4b81ed6442936a (diff) | |
download | nixpkgs-386dbd5aea22f34f4902c7fce541586e5236b0bb.tar nixpkgs-386dbd5aea22f34f4902c7fce541586e5236b0bb.tar.gz nixpkgs-386dbd5aea22f34f4902c7fce541586e5236b0bb.tar.bz2 nixpkgs-386dbd5aea22f34f4902c7fce541586e5236b0bb.tar.lz nixpkgs-386dbd5aea22f34f4902c7fce541586e5236b0bb.tar.xz nixpkgs-386dbd5aea22f34f4902c7fce541586e5236b0bb.tar.zst nixpkgs-386dbd5aea22f34f4902c7fce541586e5236b0bb.zip |
poetry2nix: 1.2.1 -> 1.3.0
Diffstat (limited to 'pkgs/development/tools')
4 files changed, 225 insertions, 120 deletions
diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/default.nix b/pkgs/development/tools/poetry2nix/poetry2nix/default.nix index 8e0e861fab3..b6d53387552 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/default.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/default.nix @@ -20,16 +20,10 @@ let 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 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 - getLicenseBySpdxId = spdxId: getAttrDefault spdxId spdxLicenses spdxId; + getLicenseBySpdxId = spdxId: spdxLicenses.${spdxId} or spdxId; # # 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 baseOverlay = self: super: let - getDep = depName: if builtins.hasAttr depName self then self."${depName}" else throw "foo"; + getDep = depName: self.${depName}; lockPkgs = builtins.listToAttrs ( builtins.map ( @@ -74,7 +68,7 @@ let value = self.mkPoetryDep ( pkgMeta // { inherit pwd; - source = getAttrDefault "source" pkgMeta null; + source = pkgMeta.source or null; files = lockFiles.${name}; pythonPackages = self; } @@ -159,12 +153,12 @@ let passedAttrs = builtins.removeAttrs attrs specialAttrs; 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); in builtins.map (dep: py.pkgs."${dep}") depAttrs; - getInputs = attr: getAttrDefault attr attrs []; + getInputs = attr: attrs.${attr} or []; mkInput = attr: extraInputs: getInputs attr ++ extraInputs; buildSystemPkgs = poetryLib.getBuildSystemPkgs { @@ -189,7 +183,7 @@ let python = py; }; - postPatch = (getAttrDefault "postPatch" passedAttrs "") + '' + postPatch = (passedAttrs.postPatch or "") + '' # Tell poetry not to resolve the path dependencies. Any version is # fine ! yj -tj < pyproject.toml | python ${./pyproject-without-path.py} > pyproject.json @@ -199,7 +193,7 @@ let meta = meta // { inherit (pyProject.tool.poetry) description homepage; - license = getLicenseBySpdxId (getAttrDefault "license" pyProject.tool.poetry "unknown"); + license = getLicenseBySpdxId (pyProject.tool.poetry.license or "unknown"); }; } diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix b/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix index 559c3051a73..68d854f2648 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix @@ -30,22 +30,24 @@ let in (builtins.foldl' combine initial tokens).state; - fromTOML = toml: if builtins.hasAttr "fromTOML" builtins then builtins.fromTOML toml else - builtins.fromJSON ( - builtins.readFile ( - pkgs.runCommand "from-toml" - { - inherit toml; - allowSubstitutes = false; - preferLocalBuild = true; - } - '' - ${pkgs.remarshal}/bin/remarshal \ - -if toml \ - -i <(echo "$toml") \ - -of json \ - -o $out - '' + fromTOML = builtins.fromTOML or + ( + toml: builtins.fromJSON ( + builtins.readFile ( + pkgs.runCommand "from-toml" + { + inherit toml; + allowSubstitutes = false; + preferLocalBuild = true; + } + '' + ${pkgs.remarshal}/bin/remarshal \ + -if toml \ + -i <(echo "$toml") \ + -of json \ + -o $out + '' + ) ) ); readTOML = path: fromTOML (builtins.readFile path); diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix b/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix index 256e2d90daa..95543ca7359 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix @@ -16,102 +16,112 @@ , pwd , supportedExtensions ? lib.importJSON ./extensions.json , ... -}: let - - inherit (poetryLib) isCompatible getManyLinuxDeps fetchFromPypi; +}: - inherit (import ./pep425.nix { - inherit lib python; - inherit (pkgs) stdenv; - }) selectWheel - ; +pythonPackages.callPackage ( + { preferWheel ? false + }: - fileCandidates = let - 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 && isCompatibleEgg f.file) files; + let - toPath = s: pwd + "/${s}"; + inherit (poetryLib) isCompatible getManyLinuxDeps fetchFromPypi; - isSource = source != null; - isGit = isSource && source.type == "git"; - isLocal = isSource && source.type == "directory"; + inherit (import ./pep425.nix { + inherit lib python; + inherit (pkgs) stdenv; + }) selectWheel + ; - localDepPath = toPath source.url; - pyProject = poetryLib.readTOML (localDepPath + "/pyproject.toml"); + fileCandidates = let + 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 && isCompatibleEgg f.file) files; - buildSystemPkgs = poetryLib.getBuildSystemPkgs { - inherit pythonPackages pyProject; - }; + toPath = s: pwd + "/${s}"; - fileInfo = let - isBdist = f: lib.strings.hasSuffix "whl" f.file; - isSdist = f: ! isBdist f && ! isEgg f; - isEgg = f: lib.strings.hasSuffix ".egg" f.file; + isSource = source != null; + isGit = isSource && source.type == "git"; + isLocal = isSource && source.type == "directory"; - binaryDist = selectWheel fileCandidates; - sourceDist = builtins.filter isSdist fileCandidates; - eggs = builtins.filter isEgg fileCandidates; + localDepPath = toPath source.url; + pyProject = poetryLib.readTOML (localDepPath + "/pyproject.toml"); - lockFileEntry = builtins.head (sourceDist ++ binaryDist ++ eggs); + buildSystemPkgs = poetryLib.getBuildSystemPkgs { + inherit pythonPackages pyProject; + }; - _isEgg = isEgg lockFileEntry; + fileInfo = let + isBdist = f: lib.strings.hasSuffix "whl" f.file; + isSdist = f: ! isBdist f && ! isEgg f; + isEgg = f: lib.strings.hasSuffix ".egg" f.file; - in - rec { - inherit (lockFileEntry) file hash; - name = file; - 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); - }; + binaryDist = selectWheel fileCandidates; + sourceDist = builtins.filter isSdist fileCandidates; + eggs = builtins.filter isEgg fileCandidates; - baseBuildInputs = lib.optional (name != "setuptools_scm" && name != "setuptools-scm") pythonPackages.setuptools_scm; + entries = (if preferWheel then binaryDist ++ sourceDist else sourceDist ++ binaryDist) ++ eggs; -in + lockFileEntry = builtins.head entries; -buildPythonPackage { - pname = name; - version = version; + _isEgg = isEgg lockFileEntry; - doCheck = false; # We never get development deps - dontStrip = true; - format = if isLocal then "pyproject" else if isGit then "setuptools" else fileInfo.format; + in + rec { + inherit (lockFileEntry) file hash; + name = file; + 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); + }; - nativeBuildInputs = if (!isSource && (getManyLinuxDeps fileInfo.name).str != null) then [ autoPatchelfHook ] else []; - buildInputs = baseBuildInputs ++ (if !isSource then (getManyLinuxDeps fileInfo.name).pkg else []); + baseBuildInputs = lib.optional (name != "setuptools_scm" && name != "setuptools-scm") pythonPackages.setuptools_scm; - propagatedBuildInputs = - let - # Some dependencies like django gets the attribute name django - # but dependencies try to access Django - deps = builtins.map (d: lib.toLower d) (builtins.attrNames dependencies); in - (builtins.map (n: pythonPackages.${n}) deps) ++ (if isLocal then buildSystemPkgs else []); - - meta = { - broken = ! isCompatible python.version python-versions; - license = []; - }; - - # 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) - # Here we can then choose a file based on that info. - src = if isGit then ( - builtins.fetchGit { - inherit (source) url; - rev = source.reference; - } - ) else if isLocal then (localDepPath) else fetchFromPypi { - pname = name; - inherit (fileInfo) file hash kind; - }; -} + + buildPythonPackage { + pname = name; + version = version; + + doCheck = false; # We never get development deps + dontStrip = true; + format = if isLocal then "pyproject" else if isGit then "setuptools" else fileInfo.format; + + nativeBuildInputs = if (!isSource && (getManyLinuxDeps fileInfo.name).str != null) then [ autoPatchelfHook ] else []; + buildInputs = baseBuildInputs ++ (if !isSource then (getManyLinuxDeps fileInfo.name).pkg else []); + + propagatedBuildInputs = + let + # Some dependencies like django gets the attribute name django + # but dependencies try to access Django + deps = builtins.map (d: lib.toLower d) (builtins.attrNames dependencies); + in + (builtins.map (n: pythonPackages.${n}) deps) ++ (if isLocal then buildSystemPkgs else []); + + meta = { + broken = ! isCompatible python.version python-versions; + license = []; + }; + + # 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) + # Here we can then choose a file based on that info. + src = if isGit then ( + builtins.fetchGit { + inherit (source) url; + rev = source.reference; + } + ) else if isLocal then (localDepPath) else fetchFromPypi { + pname = name; + inherit (fileInfo) file hash kind; + }; + } + +) {} diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix b/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix index 207841fd005..48b8ff9859b 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix @@ -5,14 +5,6 @@ self: super: -let - - getAttrDefault = attribute: set: default: - if builtins.hasAttr attribute set - then builtins.getAttr attribute set - else default; - -in { av = super.av.overrideAttrs ( old: { @@ -52,7 +44,7 @@ in django = ( super.django.overrideAttrs ( old: { - propagatedNativeBuildInputs = (getAttrDefault "propagatedNativeBuildInputs" old []) + propagatedNativeBuildInputs = (old.propagatedNativeBuildInputs or []) ++ [ pkgs.gettext ]; } ) @@ -64,7 +56,7 @@ in if ! test -e LICENSE; then touch LICENSE 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 ( old: { 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 ( old: { 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 ( old: { 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 wheel = ( pkgs.python3.pkgs.override { |