From 63bac1fc599cdeac4777bb24d545f21873af3a53 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Thu, 28 May 2020 21:40:34 +0100 Subject: [PATCH] poetry2nix: 1.8.0 -> 1.9.0 --- .../tools/poetry2nix/poetry2nix/default.nix | 107 +- .../tools/poetry2nix/poetry2nix/editable.nix | 54 + .../poetry2nix/poetry2nix/hooks/default.nix | 43 +- .../tools/poetry2nix/poetry2nix/lib.nix | 118 +- .../poetry2nix/poetry2nix/mk-poetry-dep.nix | 8 +- .../tools/poetry2nix/poetry2nix/overrides.nix | 1436 ++++++++--------- .../tools/poetry2nix/poetry2nix/pep508.nix | 55 +- .../tools/poetry2nix/poetry2nix/semver.nix | 12 +- 8 files changed, 965 insertions(+), 868 deletions(-) create mode 100644 pkgs/development/tools/poetry2nix/poetry2nix/editable.nix diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/default.nix b/pkgs/development/tools/poetry2nix/poetry2nix/default.nix index a7fb382c7553..eecad922d4e8 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/default.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/default.nix @@ -69,28 +69,28 @@ let baseOverlay = self: super: let getDep = depName: self.${depName}; - lockPkgs = builtins.listToAttrs - ( - builtins.map - ( - pkgMeta: rec { - name = moduleName pkgMeta.name; - value = self.mkPoetryDep - ( - pkgMeta // { - inherit pwd preferWheels; - source = pkgMeta.source or null; - files = lockFiles.${name}; - pythonPackages = self; - sourceSpec = pyProject.tool.poetry.dependencies.${name} or pyProject.tool.poetry.dev-dependencies.${name}; - } - ); - } - ) compatible - ); + lockPkgs = builtins.listToAttrs ( + builtins.map + ( + pkgMeta: rec { + name = moduleName pkgMeta.name; + value = self.mkPoetryDep ( + pkgMeta // { + inherit pwd preferWheels; + source = pkgMeta.source or null; + files = lockFiles.${name}; + pythonPackages = self; + sourceSpec = pyProject.tool.poetry.dependencies.${name} or pyProject.tool.poetry.dev-dependencies.${name} or { }; + } + ); + } + ) + compatible + ); in lockPkgs; - overlays = builtins.map getFunctorFn + overlays = builtins.map + getFunctorFn ( [ ( @@ -127,6 +127,8 @@ let }; /* Returns a package with a python interpreter and all packages specified in the poetry.lock lock file. + In editablePackageSources you can pass a mapping from package name to source directory to have + those packages available in the resulting environment, whose source changes are immediately available. Example: poetry2nix.mkPoetryEnv { poetrylock = ./poetry.lock; python = python3; } @@ -139,18 +141,31 @@ let , pwd ? projectDir , python ? pkgs.python3 , preferWheels ? false + # Example: { my-app = ./src; } + , editablePackageSources ? { } }: let - py = mkPoetryPackages - ( - { - inherit pyproject poetrylock overrides python pwd preferWheels; - } - ); - in - py.python.withPackages (_: py.poetryPackages); + py = mkPoetryPackages ( + { + inherit pyproject poetrylock overrides python pwd preferWheels; + } + ); - /* Creates a Python application from pyproject.toml and poetry.lock */ + editablePackage = import ./editable.nix { + inherit pkgs lib poetryLib editablePackageSources; + inherit (py) pyProject python; + }; + + in + py.python.withPackages (_: py.poetryPackages ++ lib.optional (editablePackageSources != { }) editablePackage); + + /* Creates a Python application from pyproject.toml and poetry.lock + + The result also contains a .dependencyEnv attribute which is a python + environment of all dependencies and this apps modules. This is useful if + you rely on dependencies to invoke your modules for deployment: e.g. this + allows `gunicorn my-module:app`. + */ mkPoetryApplication = { projectDir ? null , src ? poetryLib.cleanPythonSources { src = projectDir; } @@ -194,17 +209,17 @@ let pkg = py.pkgs."${dep}"; constraints = deps.${dep}.python or ""; isCompat = compat constraints; - in if isCompat then pkg else null - ) depAttrs; + in + if isCompat then pkg else null + ) + depAttrs; getInputs = attr: attrs.${attr} or [ ]; mkInput = attr: extraInputs: getInputs attr ++ extraInputs; buildSystemPkgs = poetryLib.getBuildSystemPkgs { inherit pyProject; pythonPackages = py.pkgs; }; - in - py.pkgs.buildPythonApplication - ( + app = py.pkgs.buildPythonPackage ( passedAttrs // { pname = moduleName pyProject.tool.poetry.name; version = pyProject.tool.poetry.version; @@ -212,6 +227,10 @@ let inherit src; format = "pyproject"; + # Like buildPythonApplication, but without the toPythonModule part + # Meaning this ends up looking like an application but it also + # provides python modules + namePrefix = ""; buildInputs = mkInput "buildInputs" buildSystemPkgs; propagatedBuildInputs = mkInput "propagatedBuildInputs" (getDeps "dependencies") ++ ([ py.pkgs.setuptools ]); @@ -220,16 +239,30 @@ let passthru = { python = py; + dependencyEnv = ( + lib.makeOverridable ({ app, ... }@attrs: + let + args = builtins.removeAttrs attrs [ "app" ] // { + extraLibs = [ app ]; + }; + in + py.buildEnv.override args) + ) { inherit app; }; }; - meta = meta // { - inherit (pyProject.tool.poetry) description homepage; + meta = lib.optionalAttrs (lib.hasAttr "description" pyProject.tool.poetry) { + inherit (pyProject.tool.poetry) description; + } // lib.optionalAttrs (lib.hasAttr "homepage" pyProject.tool.poetry) { + inherit (pyProject.tool.poetry) homepage; + } // { inherit (py.meta) platforms; license = getLicenseBySpdxId (pyProject.tool.poetry.license or "unknown"); - }; + } // meta; } ); + in + app; /* Poetry2nix CLI used to supplement SHA-256 hashes for git dependencies */ cli = import ./cli.nix { inherit pkgs lib version; }; diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/editable.nix b/pkgs/development/tools/poetry2nix/poetry2nix/editable.nix new file mode 100644 index 000000000000..8b0d933e445f --- /dev/null +++ b/pkgs/development/tools/poetry2nix/poetry2nix/editable.nix @@ -0,0 +1,54 @@ +{ pkgs +, lib +, poetryLib +, pyProject +, python +, editablePackageSources +}: +let + name = poetryLib.moduleName pyProject.tool.poetry.name; + + # Just enough standard PKG-INFO fields for an editable installation + pkgInfoFields = { + Metadata-Version = "2.1"; + Name = name; + # While the pyproject.toml could contain arbitrary version strings, for + # simplicity we just use the same one for PKG-INFO, even though that + # should follow follow PEP 440: https://www.python.org/dev/peps/pep-0345/#version + # This is how poetry transforms it: https://github.com/python-poetry/poetry/blob/6cd3645d889f47c10425961661b8193b23f0ed79/poetry/version/version.py + Version = pyProject.tool.poetry.version; + Summary = pyProject.tool.poetry.description; + }; + + pkgInfoFile = builtins.toFile "${name}-PKG-INFO" + (lib.concatStringsSep "\n" (lib.mapAttrsToList (key: value: "${key}: ${value}") pkgInfoFields)); + + entryPointsFile = builtins.toFile "${name}-entry_points.txt" + (lib.generators.toINI { } pyProject.tool.poetry.plugins); + + # A python package that contains simple .egg-info and .pth files for an editable installation + editablePackage = python.pkgs.toPythonModule (pkgs.runCommandNoCC "${name}-editable" + { } '' + mkdir -p "$out/${python.sitePackages}" + cd "$out/${python.sitePackages}" + + # See https://docs.python.org/3.8/library/site.html for info on such .pth files + # These add another site package path for each line + touch poetry2nix-editable.pth + ${lib.concatMapStringsSep "\n" (src: '' + echo "${toString src}" >> poetry2nix-editable.pth + '') + (lib.attrValues editablePackageSources)} + + # Create a very simple egg so pkg_resources can find this package + # See https://setuptools.readthedocs.io/en/latest/formats.html for more info on the egg format + mkdir "${name}.egg-info" + cd "${name}.egg-info" + ln -s ${pkgInfoFile} PKG-INFO + ${lib.optionalString (pyProject.tool.poetry ? plugins) '' + ln -s ${entryPointsFile} entry_points.txt + ''} + '' + ); +in +editablePackage diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix b/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix index ae5867b83372..001a3d09c6b9 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix @@ -14,36 +14,39 @@ in removePathDependenciesHook = callPackage ( {}: - makeSetupHook { - name = "remove-path-dependencies.sh"; - deps = [ ]; - substitutions = { - inherit pythonInterpreter; - yj = "${yj}/bin/yj"; - pyprojectPatchScript = "${./pyproject-without-path.py}"; - }; - } ./remove-path-dependencies.sh + makeSetupHook + { + name = "remove-path-dependencies.sh"; + deps = [ ]; + substitutions = { + inherit pythonInterpreter; + yj = "${yj}/bin/yj"; + pyprojectPatchScript = "${./pyproject-without-path.py}"; + }; + } ./remove-path-dependencies.sh ) { }; pipBuildHook = callPackage ( { pip, wheel }: - makeSetupHook { - name = "pip-build-hook.sh"; - deps = [ pip wheel ]; - substitutions = { - inherit pythonInterpreter pythonSitePackages; - }; - } ./pip-build-hook.sh + makeSetupHook + { + name = "pip-build-hook.sh"; + deps = [ pip wheel ]; + substitutions = { + inherit pythonInterpreter pythonSitePackages; + }; + } ./pip-build-hook.sh ) { }; poetry2nixFixupHook = callPackage ( {}: - makeSetupHook { - name = "fixup-hook.sh"; - deps = [ ]; - } ./fixup-hook.sh + makeSetupHook + { + name = "fixup-hook.sh"; + deps = [ ]; + } ./fixup-hook.sh ) { }; } diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix b/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix index ed47837ee439..39233929abb9 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/lib.nix @@ -20,7 +20,7 @@ let minor = l: lib.elemAt l 1; joinVersion = v: lib.concatStringsSep "." v; in - joinVersion ( if major pyVer == major ver && minor pyVer == minor ver then ver else pyVer); + joinVersion (if major pyVer == major ver && minor pyVer == minor ver then ver else pyVer); # Compare a semver expression with a version isCompatible = version: @@ -45,28 +45,27 @@ let state = operators."${operator}" acc.state (satisfiesSemver version v); }; initial = { operator = "&&"; state = true; }; - in if expr == "" then true else (builtins.foldl' combine initial tokens).state; + in + if expr == "" then true else (builtins.foldl' combine initial tokens).state; 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 - '' - ) + 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); @@ -88,11 +87,10 @@ let # file: filename including extension # hash: SRI hash # kind: Language implementation and version tag - predictURLFromPypi = lib.makeOverridable - ( - { pname, file, hash, kind }: - "https://files.pythonhosted.org/packages/${kind}/${lib.toLower (builtins.substring 0 1 file)}/${pname}/${file}" - ); + predictURLFromPypi = lib.makeOverridable ( + { pname, file, hash, kind }: + "https://files.pythonhosted.org/packages/${kind}/${lib.toLower (builtins.substring 0 1 file)}/${pname}/${file}" + ); # Fetch the wheels from the PyPI index. @@ -102,36 +100,35 @@ let # file: filename including extension # hash: SRI hash # kind: Language implementation and version tag - fetchWheelFromPypi = lib.makeOverridable - ( - { pname, file, hash, kind, curlOpts ? "" }: - let - version = builtins.elemAt (builtins.split "-" file) 2; - in - (pkgs.stdenvNoCC.mkDerivation { - name = file; - nativeBuildInputs = [ - pkgs.curl - pkgs.jq - ]; - isWheel = true; - system = "builtin"; + fetchWheelFromPypi = lib.makeOverridable ( + { pname, file, hash, kind, curlOpts ? "" }: + let + version = builtins.elemAt (builtins.split "-" file) 2; + in + (pkgs.stdenvNoCC.mkDerivation { + name = file; + nativeBuildInputs = [ + pkgs.curl + pkgs.jq + ]; + isWheel = true; + system = "builtin"; - preferLocalBuild = true; - impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ - "NIX_CURL_FLAGS" - ]; + preferLocalBuild = true; + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ + "NIX_CURL_FLAGS" + ]; - predictedURL = predictURLFromPypi { inherit pname file hash kind; }; - inherit pname file version curlOpts; + predictedURL = predictURLFromPypi { inherit pname file hash kind; }; + inherit pname file version curlOpts; - builder = ./fetch-wheel.sh; + builder = ./fetch-wheel.sh; - outputHashMode = "flat"; - outputHashAlgo = "sha256"; - outputHash = hash; - }) - ); + outputHashMode = "flat"; + outputHashAlgo = "sha256"; + outputHash = hash; + }) + ); # Fetch the artifacts from the PyPI index. Since we get all # info we need from the lock file we don't use nixpkgs' fetchPyPi @@ -143,16 +140,15 @@ let # file: filename including extension # hash: SRI hash # kind: Language implementation and version tag https://www.python.org/dev/peps/pep-0427/#file-name-convention - fetchFromPypi = lib.makeOverridable - ( - { pname, file, hash, kind }: - if lib.strings.hasSuffix "whl" file then fetchWheelFromPypi { inherit pname file hash kind; } - else - pkgs.fetchurl { - url = predictURLFromPypi { inherit pname file hash kind; }; - inherit hash; - } - ); + fetchFromPypi = lib.makeOverridable ( + { pname, file, hash, kind }: + if lib.strings.hasSuffix "whl" file then fetchWheelFromPypi { inherit pname file hash kind; } + else + pkgs.fetchurl { + url = predictURLFromPypi { inherit pname file hash kind; }; + inherit hash; + } + ); getBuildSystemPkgs = { pythonPackages , pyProject diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix b/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix index 2467dad31e1a..20175f6bade4 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix @@ -58,7 +58,7 @@ pythonPackages.callPackage binaryDist = selectWheel fileCandidates; sourceDist = builtins.filter isSdist fileCandidates; eggs = builtins.filter isEgg fileCandidates; - entries = ( if preferWheel then binaryDist ++ sourceDist else sourceDist ++ binaryDist) ++ eggs; + entries = (if preferWheel then binaryDist ++ sourceDist else sourceDist ++ binaryDist) ++ eggs; lockFileEntry = builtins.head entries; _isEgg = isEgg lockFileEntry; in @@ -111,7 +111,8 @@ pythonPackages.callPackage propagatedBuildInputs = let compat = isCompatible (poetryLib.getPythonVersion python); - deps = lib.filterAttrs (n: v: v) + deps = lib.filterAttrs + (n: v: v) ( lib.mapAttrs ( @@ -120,7 +121,8 @@ pythonPackages.callPackage constraints = v.python or ""; in compat constraints - ) dependencies + ) + dependencies ); depAttrs = lib.attrNames deps; in diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix b/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix index d18e6b8293f3..ccb8d9342f63 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix @@ -6,520 +6,536 @@ self: super: { - astroid = super.astroid.overridePythonAttrs - ( - old: rec { - buildInputs = old.buildInputs ++ [ self.pytest-runner ]; - doCheck = false; - } - ); + astroid = super.astroid.overridePythonAttrs ( + old: rec { + buildInputs = old.buildInputs ++ [ self.pytest-runner ]; + doCheck = false; + } + ); - av = super.av.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ - pkgs.pkgconfig - ]; - buildInputs = old.buildInputs ++ [ pkgs.ffmpeg_4 ]; - } - ); + av = super.av.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ + pkgs.pkgconfig + ]; + buildInputs = old.buildInputs ++ [ pkgs.ffmpeg_4 ]; + } + ); - bcrypt = super.bcrypt.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ pkgs.libffi ]; - } - ); + bcrypt = super.bcrypt.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ pkgs.libffi ]; + } + ); cffi = # cffi is bundled with pypy if self.python.implementation == "pypy" then null else ( - super.cffi.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ pkgs.libffi ]; - } - ) - ); - - cftime = super.cftime.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ - self.cython - ]; - } - ); - - configparser = super.configparser.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ - self.toml - ]; - - postPatch = '' - substituteInPlace setup.py --replace 'setuptools.setup()' 'setuptools.setup(version="${old.version}")' - ''; - } - ); - - cryptography = super.cryptography.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ pkgs.openssl ]; - } - ); - - django = ( - super.django.overridePythonAttrs - ( + super.cffi.overridePythonAttrs ( old: { - propagatedNativeBuildInputs = (old.propagatedNativeBuildInputs or [ ]) - ++ [ pkgs.gettext ]; + buildInputs = old.buildInputs ++ [ pkgs.libffi ]; } ) + ); + + cftime = super.cftime.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ + self.cython + ]; + } ); - django-bakery = super.django-bakery.overridePythonAttrs - ( + configparser = super.configparser.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ + self.toml + ]; + + postPatch = '' + substituteInPlace setup.py --replace 'setuptools.setup()' 'setuptools.setup(version="${old.version}")' + ''; + } + ); + + cryptography = super.cryptography.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ pkgs.openssl ]; + } + ); + + django = ( + super.django.overridePythonAttrs ( old: { - configurePhase = '' - if ! test -e LICENSE; then - touch LICENSE - fi - '' + (old.configurePhase or ""); + propagatedNativeBuildInputs = (old.propagatedNativeBuildInputs or [ ]) + ++ [ pkgs.gettext ]; } - ); + ) + ); - dlib = super.dlib.overridePythonAttrs - ( - old: { - # Parallel building enabled - inherit (pkgs.python.pkgs.dlib) patches; + django-bakery = super.django-bakery.overridePythonAttrs ( + old: { + configurePhase = '' + if ! test -e LICENSE; then + touch LICENSE + fi + '' + (old.configurePhase or ""); + } + ); - enableParallelBuilding = true; - dontUseCmakeConfigure = true; + dlib = super.dlib.overridePythonAttrs ( + old: { + # Parallel building enabled + inherit (pkgs.python.pkgs.dlib) patches; - nativeBuildInputs = old.nativeBuildInputs ++ pkgs.dlib.nativeBuildInputs; - buildInputs = old.buildInputs ++ pkgs.dlib.buildInputs; - } - ); + 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) enum34 = if self.pythonAtLeast "3.4" then null else super.enum34; - faker = super.faker.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ self.pytest-runner ]; - doCheck = false; - } - ); + faker = super.faker.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ self.pytest-runner ]; + doCheck = false; + } + ); - fancycompleter = super.fancycompleter.overridePythonAttrs - ( - old: { - postPatch = '' - substituteInPlace setup.py \ - --replace 'setup_requires="setupmeta"' 'setup_requires=[]' \ - --replace 'versioning="devcommit"' 'version="${old.version}"' - ''; - } - ); + fancycompleter = super.fancycompleter.overridePythonAttrs ( + old: { + postPatch = '' + substituteInPlace setup.py \ + --replace 'setup_requires="setupmeta"' 'setup_requires=[]' \ + --replace 'versioning="devcommit"' 'version="${old.version}"' + ''; + } + ); - fastparquet = super.fastparquet.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ self.pytest-runner ]; - } - ); + fastparquet = super.fastparquet.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ self.pytest-runner ]; + } + ); - grandalf = super.grandalf.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ self.pytest-runner ]; - doCheck = false; - } - ); + grandalf = super.grandalf.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ self.pytest-runner ]; + doCheck = false; + } + ); - h5py = super.h5py.overridePythonAttrs - ( - old: - if old.format != "wheel" then rec { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; - buildInputs = old.buildInputs ++ [ pkgs.hdf5 self.pkgconfig self.cython ]; - configure_flags = "--hdf5=${pkgs.hdf5}"; - postConfigure = '' - ${self.python.executable} setup.py configure ${configure_flags} - ''; - } else old - ); + h5py = super.h5py.overridePythonAttrs ( + old: + if old.format != "wheel" then rec { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; + buildInputs = old.buildInputs ++ [ pkgs.hdf5 self.pkgconfig self.cython ]; + configure_flags = "--hdf5=${pkgs.hdf5}"; + postConfigure = '' + ${self.python.executable} setup.py configure ${configure_flags} + ''; + } else old + ); - horovod = super.horovod.overridePythonAttrs - ( - old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ [ pkgs.openmpi ]; - } - ); + horovod = super.horovod.overridePythonAttrs ( + old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ [ pkgs.openmpi ]; + } + ); + + imagecodecs = super.imagecodecs.overridePythonAttrs ( + old: { + patchPhase = '' + substituteInPlace setup.py \ + --replace "/usr/include/openjpeg-2.3" \ + "${pkgs.openjpeg.dev}/include/openjpeg-2.3" + substituteInPlace setup.py \ + --replace "/usr/include/jxrlib" \ + "$out/include/libjxr" + substituteInPlace imagecodecs/_zopfli.c \ + --replace '"zopfli/zopfli.h"' \ + '' + substituteInPlace imagecodecs/_zopfli.c \ + --replace '"zopfli/zlib_container.h"' \ + '' + substituteInPlace imagecodecs/_zopfli.c \ + --replace '"zopfli/gzip_container.h"' \ + '' + ''; + + preBuild = '' + mkdir -p $out/include/libjxr + ln -s ${pkgs.jxrlib}/include/libjxr/**/* $out/include/libjxr + + ''; + + buildInputs = old.buildInputs ++ [ + # Commented out packages are declared required, but not actually + # needed to build. They are not yet packaged for nixpkgs. + # bitshuffle + pkgs.brotli + # brunsli + pkgs.bzip2 + pkgs.c-blosc + # charls + pkgs.giflib + pkgs.jxrlib + pkgs.lcms + pkgs.libaec + pkgs.libaec + pkgs.libjpeg_turbo + # liblzf + # liblzma + pkgs.libpng + pkgs.libtiff + pkgs.libwebp + pkgs.lz4 + pkgs.openjpeg + pkgs.snappy + # zfp + pkgs.zopfli + pkgs.zstd + pkgs.zlib + ]; + } + ); # importlib-metadata has an incomplete dependency specification - importlib-metadata = super.importlib-metadata.overridePythonAttrs - ( - old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ lib.optional self.python.isPy2 self.pathlib2; - } - ); + importlib-metadata = super.importlib-metadata.overridePythonAttrs ( + old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ lib.optional self.python.isPy2 self.pathlib2; + } + ); - isort = super.isort.overridePythonAttrs - ( - old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.setuptools ]; - } - ); + isort = super.isort.overridePythonAttrs ( + old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.setuptools ]; + } + ); - jupyter = super.jupyter.overridePythonAttrs - ( - old: rec { - # jupyter is a meta-package. Everything relevant comes from the - # dependencies. It does however have a jupyter.py file that conflicts - # with jupyter-core so this meta solves this conflict. - meta.priority = 100; - } - ); + jupyter = super.jupyter.overridePythonAttrs ( + old: rec { + # jupyter is a meta-package. Everything relevant comes from the + # dependencies. It does however have a jupyter.py file that conflicts + # with jupyter-core so this meta solves this conflict. + meta.priority = 100; + } + ); - kiwisolver = super.kiwisolver.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ - # cppy is at the time of writing not in nixpkgs - (self.cppy or null) - ]; - } - ); + kiwisolver = super.kiwisolver.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ + # cppy is at the time of writing not in nixpkgs + (self.cppy or null) + ]; + } + ); - lap = super.lap.overridePythonAttrs - ( - old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ [ - self.numpy - ]; - } - ); + lap = super.lap.overridePythonAttrs ( + old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ [ + self.numpy + ]; + } + ); - llvmlite = super.llvmlite.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.llvm ]; + llvmlite = super.llvmlite.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.llvm ]; - # Disable static linking - # https://github.com/numba/llvmlite/issues/93 - postPatch = '' - substituteInPlace ffi/Makefile.linux --replace "-static-libstdc++" "" + # Disable static linking + # https://github.com/numba/llvmlite/issues/93 + postPatch = '' + substituteInPlace ffi/Makefile.linux --replace "-static-libstdc++" "" - substituteInPlace llvmlite/tests/test_binding.py --replace "test_linux" "nope" - ''; + substituteInPlace llvmlite/tests/test_binding.py --replace "test_linux" "nope" + ''; - # Set directory containing llvm-config binary - preConfigure = '' - export LLVM_CONFIG=${pkgs.llvm}/bin/llvm-config - ''; + # Set directory containing llvm-config binary + preConfigure = '' + export LLVM_CONFIG=${pkgs.llvm}/bin/llvm-config + ''; - __impureHostDeps = pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [ "/usr/lib/libm.dylib" ]; + __impureHostDeps = pkgs.stdenv.lib.optionals pkgs.stdenv.isDarwin [ "/usr/lib/libm.dylib" ]; - passthru = old.passthru // { llvm = pkgs.llvm; }; - } - ); + passthru = old.passthru // { llvm = pkgs.llvm; }; + } + ); - lockfile = super.lockfile.overridePythonAttrs - ( - old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.pbr ]; - } - ); + lockfile = super.lockfile.overridePythonAttrs ( + old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.pbr ]; + } + ); - lxml = super.lxml.overridePythonAttrs - ( - old: { - nativeBuildInputs = with pkgs; old.nativeBuildInputs ++ [ pkgconfig libxml2.dev libxslt.dev ]; - buildInputs = with pkgs; old.buildInputs ++ [ libxml2 libxslt ]; - } - ); + lxml = super.lxml.overridePythonAttrs ( + old: { + nativeBuildInputs = with pkgs; old.nativeBuildInputs ++ [ pkgconfig libxml2.dev libxslt.dev ]; + buildInputs = with pkgs; old.buildInputs ++ [ libxml2 libxslt ]; + } + ); - markupsafe = super.markupsafe.overridePythonAttrs - ( - old: { - src = old.src.override { pname = builtins.replaceStrings [ "markupsafe" ] [ "MarkupSafe" ] old.pname; }; - } - ); + markupsafe = super.markupsafe.overridePythonAttrs ( + old: { + src = old.src.override { pname = builtins.replaceStrings [ "markupsafe" ] [ "MarkupSafe" ] old.pname; }; + } + ); - matplotlib = super.matplotlib.overridePythonAttrs - ( - old: - let - enableGhostscript = old.passthru.enableGhostscript or false; - enableGtk3 = old.passthru.enableTk or false; - enableQt = old.passthru.enableQt or false; - enableTk = old.passthru.enableTk or false; + matplotlib = super.matplotlib.overridePythonAttrs ( + old: + let + enableGhostscript = old.passthru.enableGhostscript or false; + enableGtk3 = old.passthru.enableTk or false; + enableQt = old.passthru.enableQt or false; + enableTk = old.passthru.enableTk or false; - inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa; - in - { - NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${pkgs.libcxx}/include/c++/v1"; + inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa; + in + { + NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${pkgs.libcxx}/include/c++/v1"; - XDG_RUNTIME_DIR = "/tmp"; + XDG_RUNTIME_DIR = "/tmp"; - buildInputs = old.buildInputs - ++ lib.optional enableGhostscript pkgs.ghostscript - ++ lib.optional stdenv.isDarwin [ Cocoa ]; + buildInputs = old.buildInputs + ++ lib.optional enableGhostscript pkgs.ghostscript + ++ lib.optional stdenv.isDarwin [ Cocoa ]; - nativeBuildInputs = old.nativeBuildInputs ++ [ - pkgs.pkgconfig - ]; + 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 ] - ; + 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; - } - ); + inherit (super.matplotlib) patches; + } + ); # Calls Cargo at build time for source builds and is really tricky to package maturin = super.maturin.override { preferWheel = true; }; - mccabe = super.mccabe.overridePythonAttrs - ( + mccabe = super.mccabe.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ self.pytest-runner ]; + doCheck = false; + } + ); + + netcdf4 = super.netcdf4.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ + self.cython + ]; + + propagatedBuildInputs = old.propagatedBuildInputs ++ [ + pkgs.zlib + pkgs.netcdf + pkgs.hdf5 + pkgs.curl + pkgs.libjpeg + ]; + + # Variables used to configure the build process + USE_NCCONFIG = "0"; + HDF5_DIR = lib.getDev pkgs.hdf5; + NETCDF4_DIR = pkgs.netcdf; + CURL_DIR = pkgs.curl.dev; + JPEG_DIR = pkgs.libjpeg.dev; + } + ); + + numpy = super.numpy.overridePythonAttrs ( + old: + let + blas = old.passthru.args.blas or pkgs.openblasCompat; + blasImplementation = lib.nameFromURL blas.name "-"; + cfg = pkgs.writeTextFile { + name = "site.cfg"; + text = ( + lib.generators.toINI + { } { + ${blasImplementation} = { + include_dirs = "${blas}/include"; + library_dirs = "${blas}/lib"; + } // lib.optionalAttrs (blasImplementation == "mkl") { + mkl_libs = "mkl_rt"; + lapack_libs = ""; + }; + } + ); + }; + in + { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gfortran ]; + buildInputs = old.buildInputs ++ [ blas self.cython ]; + enableParallelBuilding = true; + preBuild = '' + ln -s ${cfg} site.cfg + ''; + passthru = old.passthru // { + blas = blas; + inherit blasImplementation cfg; + }; + } + ); + + openexr = super.openexr.overridePythonAttrs ( + old: rec { + buildInputs = old.buildInputs ++ [ pkgs.openexr pkgs.ilmbase ]; + NIX_CFLAGS_COMPILE = [ "-I${pkgs.openexr.dev}/include/OpenEXR" "-I${pkgs.ilmbase.dev}/include/OpenEXR" ]; + } + ); + + 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.overridePythonAttrs ( + old: { + nativeBuildInputs = [ pkgs.pkgconfig ] ++ old.nativeBuildInputs; + buildInputs = with pkgs; [ freetype libjpeg zlib libtiff libwebp tcl lcms2 ] ++ old.buildInputs; + } + ); + + psycopg2 = super.psycopg2.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.postgresql ]; + } + ); + + psycopg2-binary = super.psycopg2-binary.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.postgresql ]; + } + ); + + pyarrow = + if lib.versionAtLeast super.pyarrow.version "0.16.0" then super.pyarrow.overridePythonAttrs ( + old: + let + parseMinor = drv: lib.concatStringsSep "." (lib.take 2 (lib.splitVersion drv.version)); + _arrow-cpp = pkgs.arrow-cpp.override { inherit (self) python; }; + ARROW_HOME = _arrow-cpp; + arrowCppVersion = parseMinor pkgs.arrow-cpp; + pyArrowVersion = parseMinor super.pyarrow; + errorMessage = "arrow-cpp version (${arrowCppVersion}) mismatches pyarrow version (${pyArrowVersion})"; + in + if arrowCppVersion != pyArrowVersion then throw errorMessage else { + + nativeBuildInputs = old.nativeBuildInputs ++ [ + self.cython + pkgs.pkgconfig + pkgs.cmake + ]; + + preBuild = '' + export PYARROW_PARALLEL=$NIX_BUILD_CORES + ''; + + PARQUET_HOME = _arrow-cpp; + inherit ARROW_HOME; + + buildInputs = old.buildInputs ++ [ + pkgs.arrow-cpp + ]; + + PYARROW_BUILD_TYPE = "release"; + PYARROW_WITH_PARQUET = true; + PYARROW_CMAKE_OPTIONS = [ + "-DCMAKE_INSTALL_RPATH=${ARROW_HOME}/lib" + + # This doesn't use setup hook to call cmake so we need to workaround #54606 + # ourselves + "-DCMAKE_POLICY_DEFAULT_CMP0025=NEW" + ]; + + dontUseCmakeConfigure = true; + } + ) else super.pyarrow.overridePythonAttrs ( old: { - buildInputs = old.buildInputs ++ [ self.pytest-runner ]; - doCheck = false; + nativeBuildInputs = old.nativeBuildInputs ++ [ + self.cython + ]; } ); - netcdf4 = super.netcdf4.overridePythonAttrs - ( + pycairo = ( + drv: ( + drv.overridePythonAttrs ( + _: { + format = "other"; + } + ) + ).overridePythonAttrs ( old: { - buildInputs = old.buildInputs ++ [ - self.cython + + nativeBuildInputs = old.nativeBuildInputs ++ [ + pkgs.meson + pkgs.ninja + pkgs.pkgconfig ]; propagatedBuildInputs = old.propagatedBuildInputs ++ [ - pkgs.zlib - pkgs.netcdf - pkgs.hdf5 - pkgs.curl - pkgs.libjpeg + pkgs.cairo + pkgs.xlibsWrapper ]; - # Variables used to configure the build process - USE_NCCONFIG = "0"; - HDF5_DIR = lib.getDev pkgs.hdf5; - NETCDF4_DIR = pkgs.netcdf; - CURL_DIR = pkgs.curl.dev; - JPEG_DIR = pkgs.libjpeg.dev; + mesonFlags = [ "-Dpython=${if self.isPy3k then "python3" else "python"}" ]; } - ); + ) + ) + super.pycairo; - numpy = super.numpy.overridePythonAttrs - ( - old: - let - blas = old.passthru.args.blas or pkgs.openblasCompat; - blasImplementation = lib.nameFromURL blas.name "-"; - cfg = pkgs.writeTextFile { - name = "site.cfg"; - text = ( - lib.generators.toINI { } { - ${blasImplementation} = { - include_dirs = "${blas}/include"; - library_dirs = "${blas}/lib"; - } // lib.optionalAttrs (blasImplementation == "mkl") { - mkl_libs = "mkl_rt"; - lapack_libs = ""; - }; - } - ); - }; - in - { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gfortran ]; - buildInputs = old.buildInputs ++ [ blas self.cython ]; - enableParallelBuilding = true; - preBuild = '' - ln -s ${cfg} site.cfg - ''; - passthru = old.passthru // { - blas = blas; - inherit blasImplementation cfg; - }; - } - ); + pycocotools = super.pycocotools.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ + self.cython + self.numpy + ]; + } + ); - openexr = super.openexr.overridePythonAttrs - ( - old: rec { - buildInputs = old.buildInputs ++ [ pkgs.openexr pkgs.ilmbase ]; - NIX_CFLAGS_COMPILE = [ "-I${pkgs.openexr.dev}/include/OpenEXR" "-I${pkgs.ilmbase.dev}/include/OpenEXR" ]; - } - ); + pygobject = super.pygobject.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; + buildInputs = old.buildInputs ++ [ pkgs.glib pkgs.gobject-introspection ]; + } + ); - 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; - } - ); + pylint = super.pylint.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ self.pytest-runner ]; + doCheck = false; + } + ); - pillow = super.pillow.overridePythonAttrs - ( - old: { - nativeBuildInputs = [ pkgs.pkgconfig ] ++ old.nativeBuildInputs; - buildInputs = with pkgs; [ freetype libjpeg zlib libtiff libwebp tcl lcms2 ] ++ old.buildInputs; - } - ); - - psycopg2 = super.psycopg2.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.postgresql ]; - } - ); - - psycopg2-binary = super.psycopg2-binary.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.postgresql ]; - } - ); - - pyarrow = - if lib.versionAtLeast super.pyarrow.version "0.16.0" then super.pyarrow.overridePythonAttrs - ( - old: - let - parseMinor = drv: lib.concatStringsSep "." (lib.take 2 (lib.splitVersion drv.version)); - _arrow-cpp = pkgs.arrow-cpp.override { inherit (self) python; }; - ARROW_HOME = _arrow-cpp; - arrowCppVersion = parseMinor pkgs.arrow-cpp; - pyArrowVersion = parseMinor super.pyarrow; - errorMessage = "arrow-cpp version (${arrowCppVersion}) mismatches pyarrow version (${pyArrowVersion})"; - in - if arrowCppVersion != pyArrowVersion then throw errorMessage else { - - nativeBuildInputs = old.nativeBuildInputs ++ [ - self.cython - pkgs.pkgconfig - pkgs.cmake - ]; - - preBuild = '' - export PYARROW_PARALLEL=$NIX_BUILD_CORES - ''; - - PARQUET_HOME = _arrow-cpp; - inherit ARROW_HOME; - - buildInputs = old.buildInputs ++ [ - pkgs.arrow-cpp - ]; - - PYARROW_BUILD_TYPE = "release"; - PYARROW_WITH_PARQUET = true; - PYARROW_CMAKE_OPTIONS = [ - "-DCMAKE_INSTALL_RPATH=${ARROW_HOME}/lib" - - # This doesn't use setup hook to call cmake so we need to workaround #54606 - # ourselves - "-DCMAKE_POLICY_DEFAULT_CMP0025=NEW" - ]; - - dontUseCmakeConfigure = true; - } - ) else super.pyarrow.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ - self.cython - ]; - } - ); - - pycairo = - ( - drv: ( - drv.overridePythonAttrs - ( - _: { - format = "other"; - } - ) - ).overridePythonAttrs - ( - old: { - - nativeBuildInputs = old.nativeBuildInputs ++ [ - pkgs.meson - pkgs.ninja - pkgs.pkgconfig - ]; - - propagatedBuildInputs = old.propagatedBuildInputs ++ [ - pkgs.cairo - pkgs.xlibsWrapper - ]; - - mesonFlags = [ "-Dpython=${ if self.isPy3k then "python3" else "python"}" ]; - } - ) - ) super.pycairo; - - pycocotools = super.pycocotools.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ - self.cython - self.numpy - ]; - } - ); - - pygobject = super.pygobject.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; - buildInputs = old.buildInputs ++ [ pkgs.glib pkgs.gobject-introspection ]; - } - ); - - pylint = super.pylint.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ self.pytest-runner ]; - doCheck = false; - } - ); - - pyopenssl = super.pyopenssl.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ pkgs.openssl ]; - } - ); + pyopenssl = super.pyopenssl.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ pkgs.openssl ]; + } + ); pyqt5 = let @@ -529,318 +545,302 @@ self: super: withWebKit = drv.passthru.args.withWebKit or false; withWebSockets = drv.passthru.args.withWebSockets or false; in - 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 - ] - ++ 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 ++ [ - pkgs.dbus - pkgs.qt5.qtbase - pkgs.qt5.qtsvg - pkgs.qt5.qtdeclarative - self.sip - ] - ++ lib.optional withConnectivity pkgs.qt5.qtconnectivity - ++ lib.optional withWebKit pkgs.qt5.qtwebkit - ++ lib.optional withWebSockets pkgs.qt5.qtwebsockets - ; - - # Fix dbus mainloop - patches = pkgs.python3.pkgs.pyqt5.patches or [ ]; - - 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" - ] - ++ 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.overridePythonAttrs - ( + super.pyqt5.overridePythonAttrs ( old: { - postInstall = '' - rm -f $out/LICENSE + 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 + ] + ++ 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 ++ [ + pkgs.dbus + pkgs.qt5.qtbase + pkgs.qt5.qtsvg + pkgs.qt5.qtdeclarative + self.sip + ] + ++ lib.optional withConnectivity pkgs.qt5.qtconnectivity + ++ lib.optional withWebKit pkgs.qt5.qtwebkit + ++ lib.optional withWebSockets pkgs.qt5.qtwebsockets + ; + + # Fix dbus mainloop + patches = pkgs.python3.pkgs.pyqt5.patches or [ ]; + + 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" + ] + ++ 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 = super.pytest.overridePythonAttrs - ( - old: { - doCheck = false; - } - ); + pytest-datadir = super.pytest-datadir.overridePythonAttrs ( + old: { + postInstall = '' + rm -f $out/LICENSE + ''; + } + ); + + pytest = super.pytest.overridePythonAttrs ( + old: { + doCheck = false; + } + ); pytest-runner = super.pytest-runner or super.pytestrunner; - python-jose = super.python-jose.overridePythonAttrs - ( - old: { - postPath = '' - substituteInPlace setup.py --replace "'pytest-runner'," "" - substituteInPlace setup.py --replace "'pytest-runner'" "" - ''; - } - ); + python-jose = super.python-jose.overridePythonAttrs ( + old: { + postPath = '' + substituteInPlace setup.py --replace "'pytest-runner'," "" + substituteInPlace setup.py --replace "'pytest-runner'" "" + ''; + } + ); - python-prctl = super.python-prctl.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ - pkgs.libcap - ]; - } - ); + python-prctl = super.python-prctl.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ + pkgs.libcap + ]; + } + ); - pyzmq = super.pyzmq.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; - propagatedBuildInputs = old.propagatedBuildInputs ++ [ pkgs.zeromq ]; - } - ); + pyzmq = super.pyzmq.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; + propagatedBuildInputs = old.propagatedBuildInputs ++ [ pkgs.zeromq ]; + } + ); - rockset = super.rockset.overridePythonAttrs - ( - old: rec { - postPatch = '' - cp ./setup_rockset.py ./setup.py - ''; - } - ); + rockset = super.rockset.overridePythonAttrs ( + old: rec { + postPatch = '' + cp ./setup_rockset.py ./setup.py + ''; + } + ); - scaleapi = super.scaleapi.overridePythonAttrs - ( - old: { - postPatch = '' - substituteInPlace setup.py --replace "install_requires = ['requests>=2.4.2', 'enum34']" "install_requires = ['requests>=2.4.2']" || true - ''; - } - ); + scaleapi = super.scaleapi.overridePythonAttrs ( + old: { + postPatch = '' + substituteInPlace setup.py --replace "install_requires = ['requests>=2.4.2', 'enum34']" "install_requires = ['requests>=2.4.2']" || true + ''; + } + ); - pandas = super.pandas.overridePythonAttrs - ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ self.cython ]; - } - ); + pandas = super.pandas.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ self.cython ]; + } + ); + + panel = super.panel.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.nodejs ]; + } + ); # 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 - } - ); + pybind11 = super.pybind11.overridePythonAttrs ( + old: { + cmakeFlags = (old.cmakeFlags or [ ]) ++ [ + "-DPYBIND11_TEST=off" + ]; + doCheck = false; # Circular test dependency + } + ); - scipy = super.scipy.overridePythonAttrs - ( - old: - if old.format != "wheel" then { - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gfortran ]; - propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.pybind11 ]; - setupPyBuildFlags = [ "--fcompiler='gnu95'" ]; - enableParallelBuilding = true; - buildInputs = old.buildInputs ++ [ self.numpy.blas ]; - preConfigure = '' - sed -i '0,/from numpy.distutils.core/s//import setuptools;from numpy.distutils.core/' setup.py - export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES - ''; - preBuild = '' - ln -s ${self.numpy.cfg} site.cfg - ''; - } else old - ); + scipy = super.scipy.overridePythonAttrs ( + old: + if old.format != "wheel" then { + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gfortran ]; + propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.pybind11 ]; + setupPyBuildFlags = [ "--fcompiler='gnu95'" ]; + enableParallelBuilding = true; + buildInputs = old.buildInputs ++ [ self.numpy.blas ]; + preConfigure = '' + sed -i '0,/from numpy.distutils.core/s//import setuptools;from numpy.distutils.core/' setup.py + export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES + ''; + preBuild = '' + ln -s ${self.numpy.cfg} site.cfg + ''; + } else old + ); - scikit-learn = super.scikit-learn.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ - pkgs.gfortran - pkgs.glibcLocales - ] ++ lib.optionals stdenv.cc.isClang [ - pkgs.llvmPackages.openmp - ]; + 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 - ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ + self.cython + ]; - enableParallelBuilding = true; - } - ); + enableParallelBuilding = true; + } + ); - shapely = super.shapely.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ [ pkgs.geos self.cython ]; - inherit (pkgs.python3.pkgs.shapely) patches GEOS_LIBRARY_PATH; - } - ); + shapely = super.shapely.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ pkgs.geos self.cython ]; + inherit (pkgs.python3.pkgs.shapely) patches GEOS_LIBRARY_PATH; + } + ); shellingham = if lib.versionAtLeast super.shellingham.version "1.3.2" then ( - super.shellingham.overridePythonAttrs - ( - old: { - format = "pyproject"; - } - ) + super.shellingham.overridePythonAttrs ( + old: { + format = "pyproject"; + } + ) ) else super.shellingham; - tables = super.tables.overridePythonAttrs - ( - old: { - HDF5_DIR = "${pkgs.hdf5}"; - nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; - propagatedBuildInputs = old.nativeBuildInputs ++ [ pkgs.hdf5 self.numpy self.numexpr ]; - } - ); + tables = super.tables.overridePythonAttrs ( + old: { + HDF5_DIR = "${pkgs.hdf5}"; + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkgconfig ]; + propagatedBuildInputs = old.nativeBuildInputs ++ [ pkgs.hdf5 self.numpy self.numexpr ]; + } + ); - tensorpack = super.tensorpack.overridePythonAttrs - ( - old: { - postPatch = '' - substituteInPlace setup.cfg --replace "# will call find_packages()" "" - ''; - } - ); + tensorpack = super.tensorpack.overridePythonAttrs ( + old: { + postPatch = '' + substituteInPlace setup.cfg --replace "# will call find_packages()" "" + ''; + } + ); - urwidtrees = super.urwidtrees.overridePythonAttrs - ( - old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ [ - self.urwid - ]; - } - ); + urwidtrees = super.urwidtrees.overridePythonAttrs ( + old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ [ + self.urwid + ]; + } + ); - vose-alias-method = super.vose-alias-method.overridePythonAttrs - ( - old: { - postInstall = '' - rm -f $out/LICENSE - ''; - } - ); + vose-alias-method = super.vose-alias-method.overridePythonAttrs ( + old: { + postInstall = '' + rm -f $out/LICENSE + ''; + } + ); - uvloop = super.uvloop.overridePythonAttrs - ( - old: { - buildInputs = old.buildInputs ++ lib.optionals stdenv.isDarwin [ - pkgs.darwin.apple_sdk.frameworks.ApplicationServices - pkgs.darwin.apple_sdk.frameworks.CoreServices - ]; - } - ); + uvloop = super.uvloop.overridePythonAttrs ( + 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 wheel = ( pkgs.python3.pkgs.override { python = self.python; } - ).wheel.overridePythonAttrs - ( - old: - if old.format == "other" then old else { - inherit (super.wheel) pname name version src; - } - ); + ).wheel.overridePythonAttrs ( + old: + if old.format == "other" then old else { + inherit (super.wheel) pname name version src; + } + ); 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}")' - ''; - } - ) + super.zipp.overridePythonAttrs ( + old: { + prePatch = '' + substituteInPlace setup.py --replace \ + 'setuptools.setup()' \ + 'setuptools.setup(version="${super.zipp.version}")' + ''; + } + ) ) else super.zipp - ).overridePythonAttrs - ( - old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ [ - self.toml - ]; - } - ); + ).overridePythonAttrs ( + old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ [ + self.toml + ]; + } + ); } diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/pep508.nix b/pkgs/development/tools/poetry2nix/poetry2nix/pep508.nix index 773e0a60e093..fad0b782c4be 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/pep508.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/pep508.nix @@ -37,14 +37,17 @@ let # Make a tree out of expression groups (parens) findSubExpressions = expr: let - acc = builtins.foldl' findSubExpressionsFun { - exprs = [ ]; - expr = expr; - pos = 0; - openP = 0; - exprPos = 0; - startPos = 0; - } (lib.stringToCharacters expr); + acc = builtins.foldl' + findSubExpressionsFun + { + exprs = [ ]; + expr = expr; + pos = 0; + openP = 0; + exprPos = 0; + startPos = 0; + } + (lib.stringToCharacters expr); tailExpr = (substr acc.exprPos acc.pos expr); tailExprs = if tailExpr != "" then [ tailExpr ] else [ ]; in @@ -53,7 +56,7 @@ let let splitCond = ( s: builtins.map - (x: stripStr ( if builtins.typeOf x == "list" then (builtins.elemAt x 0) else x)) + (x: stripStr (if builtins.typeOf x == "list" then (builtins.elemAt x 0) else x)) (builtins.split " (and|or) " (s + " ")) ); mapfn = expr: ( @@ -71,8 +74,9 @@ let in builtins.foldl' ( - acc: v: acc ++ ( if builtins.typeOf v == "string" then parse v else [ (parseExpressions v) ]) - ) [ ] exprs; + acc: v: acc ++ (if builtins.typeOf v == "string" then parse v else [ (parseExpressions v) ]) + ) [ ] + exprs; # Transform individual expressions to structured expressions # This function also performs variable substitution, replacing environment markers with their explicit values @@ -159,10 +163,9 @@ let let parts = builtins.splitVersion c; pruned = lib.take ((builtins.length parts) - 1) parts; - upper = builtins.toString - ( - (lib.toInt (builtins.elemAt pruned (builtins.length pruned - 1))) + 1 - ); + upper = builtins.toString ( + (lib.toInt (builtins.elemAt pruned (builtins.length pruned - 1))) + 1 + ); upperConstraint = builtins.concatStringsSep "." (ireplace (builtins.length pruned - 1) upper pruned); in op.">=" v c && op."<" v upperConstraint; @@ -207,10 +210,13 @@ let ) else throw "Unsupported type" ) else if builtins.typeOf v == "list" then ( let - ret = builtins.foldl' reduceExpressionsFun { - value = true; - cond = "and"; - } v; + ret = builtins.foldl' + reduceExpressionsFun + { + value = true; + cond = "and"; + } + v; in acc // { value = cond."${acc.cond}" acc.value ret.value; @@ -219,10 +225,13 @@ let ); in ( - builtins.foldl' reduceExpressionsFun { - value = true; - cond = "and"; - } exprs + builtins.foldl' + reduceExpressionsFun + { + value = true; + cond = "and"; + } + exprs ).value; in e: builtins.foldl' (acc: v: v acc) e [ diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/semver.nix b/pkgs/development/tools/poetry2nix/poetry2nix/semver.nix index e86b1d3ac660..bf001392e6af 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/semver.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/semver.nix @@ -39,10 +39,9 @@ let # Prune constraint parts = builtins.splitVersion c; pruned = lib.take ((builtins.length parts) - 1) parts; - upper = builtins.toString - ( - (lib.toInt (builtins.elemAt pruned (builtins.length pruned - 1))) + 1 - ); + upper = builtins.toString ( + (lib.toInt (builtins.elemAt pruned (builtins.length pruned - 1))) + 1 + ); upperConstraint = builtins.concatStringsSep "." (ireplace (builtins.length pruned - 1) upper pruned); in operators.">=" v c && operators."<" v upperConstraint; @@ -69,7 +68,7 @@ let op = elemAt mPre 0; v = elemAt mPre 1; } - # Infix operators are range matches + # Infix operators are range matches else if mIn != null then { op = elemAt mIn 1; v = { @@ -82,6 +81,7 @@ let satisfiesSemver = version: constraint: let inherit (parseConstraint constraint) op v; - in if constraint == "*" then true else operators."${op}" version v; + in + if constraint == "*" then true else operators."${op}" version v; in { inherit satisfiesSemver; }