Merge pull request #111649 from tweag/poetry2nix-1_15_0

poetry2nix: 1.14.0 -> 1.15.2

authored by

adisbladis and committed by
GitHub
eeea7b19 add90df4

+234 -53
+1
.github/CODEOWNERS
··· 76 76 /pkgs/development/interpreters/python @FRidh 77 77 /pkgs/development/python-modules @FRidh @jonringer 78 78 /doc/languages-frameworks/python.section.md @FRidh 79 + /pkgs/development/tools/poetry2nix @adisbladis 79 80 80 81 # Haskell 81 82 /pkgs/development/compilers/ghc @cdepillabout
+57 -28
pkgs/development/tools/poetry2nix/poetry2nix/default.nix
··· 1 1 { pkgs ? import <nixpkgs> { } 2 2 , lib ? pkgs.lib 3 3 , poetry ? null 4 - , poetryLib ? import ./lib.nix { inherit lib pkgs; } 4 + , poetryLib ? import ./lib.nix { inherit lib pkgs; stdenv = pkgs.stdenv; } 5 5 }: 6 6 let 7 7 inherit (poetryLib) isCompatible readTOML moduleName; ··· 71 71 lib.makeScope pkgs.newScope (self: { 72 72 73 73 # Poetry2nix version 74 - version = "1.14.0"; 74 + version = "1.15.2"; 75 + 76 + /* Returns a package of editable sources whose changes will be available without needing to restart the 77 + nix-shell. 78 + In editablePackageSources you can pass a mapping from package name to source directory to have 79 + those packages available in the resulting environment, whose source changes are immediately available. 80 + 81 + */ 82 + mkPoetryEditablePackage = 83 + { projectDir ? null 84 + , pyproject ? projectDir + "/pyproject.toml" 85 + , python ? pkgs.python3 86 + , pyProject ? readTOML pyproject 87 + # Example: { my-app = ./src; } 88 + , editablePackageSources 89 + }: 90 + assert editablePackageSources != { }; 91 + import ./editable.nix { 92 + inherit pyProject python pkgs lib poetryLib editablePackageSources; 93 + }; 94 + 95 + /* Returns a package containing scripts defined in tool.poetry.scripts. 96 + */ 97 + mkPoetryScriptsPackage = 98 + { projectDir ? null 99 + , pyproject ? projectDir + "/pyproject.toml" 100 + , python ? pkgs.python3 101 + , pyProject ? readTOML pyproject 102 + , scripts ? pyProject.tool.poetry.scripts 103 + }: 104 + assert scripts != { }; 105 + import ./shell-scripts.nix { 106 + inherit lib python scripts; 107 + }; 75 108 76 109 /* 77 110 Returns an attrset { python, poetryPackages, pyProject, poetryLock } for the given pyproject/lockfile. ··· 84 117 , python ? pkgs.python3 85 118 , pwd ? projectDir 86 119 , preferWheels ? false 120 + # Example: { my-app = ./src; } 121 + , editablePackageSources ? { } 87 122 , __isBootstrap ? false # Hack: Always add Poetry as a build input unless bootstrapping 88 123 }@attrs: 89 124 let 90 125 poetryPkg = poetry.override { inherit python; }; 91 126 pyProject = readTOML pyproject; 127 + 128 + scripts = pyProject.tool.poetry.scripts or { }; 129 + hasScripts = scripts != { }; 130 + scriptsPackage = self.mkPoetryScriptsPackage { 131 + inherit python scripts; 132 + }; 133 + 134 + hasEditable = editablePackageSources != { }; 135 + editablePackage = self.mkPoetryEditablePackage { 136 + inherit pyProject python editablePackageSources; 137 + }; 138 + 92 139 poetryLock = readTOML poetrylock; 93 140 lockFiles = 94 141 let ··· 180 227 181 228 inputAttrs = mkInputAttrs { inherit py pyProject; attrs = { }; includeBuildSystem = false; }; 182 229 230 + storePackages = builtins.foldl' (acc: v: acc ++ v) [ ] (lib.attrValues inputAttrs); 183 231 in 184 232 { 185 233 python = py; 186 - poetryPackages = builtins.foldl' (acc: v: acc ++ v) [ ] (lib.attrValues inputAttrs); 234 + poetryPackages = storePackages 235 + ++ lib.optional hasScripts scriptsPackage 236 + ++ lib.optional hasEditable editablePackage; 187 237 poetryLock = poetryLock; 188 238 inherit pyProject; 189 239 }; ··· 203 253 , pwd ? projectDir 204 254 , python ? pkgs.python3 205 255 , preferWheels ? false 206 - # Example: { my-app = ./src; } 207 256 , editablePackageSources ? { } 208 257 }: 209 258 let 210 - py = self.mkPoetryPackages ( 211 - { 212 - inherit pyproject poetrylock overrides python pwd preferWheels; 213 - } 214 - ); 215 - 216 - inherit (py) pyProject; 217 - 218 - # Add executables from tool.poetry.scripts 219 - scripts = pyProject.tool.poetry.scripts or { }; 220 - hasScripts = scripts != { }; 221 - scriptsPackage = import ./shell-scripts.nix { 222 - inherit scripts lib; 223 - inherit (py) python; 259 + poetryPython = self.mkPoetryPackages { 260 + inherit pyproject poetrylock overrides python pwd preferWheels editablePackageSources; 224 261 }; 225 262 226 - hasEditable = editablePackageSources != { }; 227 - editablePackage = import ./editable.nix { 228 - inherit pkgs lib poetryLib editablePackageSources; 229 - inherit (py) pyProject python; 230 - }; 263 + inherit (poetryPython) poetryPackages; 231 264 232 265 in 233 - py.python.withPackages ( 234 - _: py.poetryPackages 235 - ++ lib.optional hasEditable editablePackage 236 - ++ lib.optional hasScripts scriptsPackage 237 - ); 266 + poetryPython.python.withPackages (_: poetryPackages); 238 267 239 268 /* Creates a Python application from pyproject.toml and poetry.lock 240 269
+19 -1
pkgs/development/tools/poetry2nix/poetry2nix/lib.nix
··· 1 - { lib, pkgs }: 1 + { lib, pkgs, stdenv }: 2 2 let 3 3 inherit (import ./semver.nix { inherit lib ireplace; }) satisfiesSemver; 4 4 inherit (builtins) genList length; ··· 194 194 inherit src; 195 195 }; 196 196 }; 197 + 198 + # Maps Nixpkgs CPU values to target machines known to be supported for manylinux* wheels. 199 + # (a.k.a. `uname -m` output from CentOS 7) 200 + # 201 + # This is current as of manylinux2014 (PEP-0599), and is a superset of manylinux2010 / manylinux1. 202 + # s390x is not supported in Nixpkgs, so we don't map it. 203 + manyLinuxTargetMachines = { 204 + x86_64 = "x86_64"; 205 + i686 = "i686"; 206 + aarch64 = "aarch64"; 207 + armv7l = "armv7l"; 208 + powerpc64 = "ppc64"; 209 + powerpc64le = "ppc64le"; 210 + }; 211 + 212 + # Machine tag for our target platform (if available) 213 + targetMachine = manyLinuxTargetMachines.${stdenv.targetPlatform.parsed.cpu.name} or null; 197 214 in 198 215 { 199 216 inherit ··· 207 224 cleanPythonSources 208 225 moduleName 209 226 getPythonVersion 227 + targetMachine 210 228 ; 211 229 }
+2 -2
pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix
··· 31 31 inherit (poetryLib) isCompatible getManyLinuxDeps fetchFromPypi moduleName; 32 32 33 33 inherit (import ./pep425.nix { 34 - inherit lib python; 34 + inherit lib poetryLib python; 35 35 inherit (pkgs) stdenv; 36 36 }) selectWheel 37 37 ; ··· 161 161 builtins.fetchGit { 162 162 inherit (source) url; 163 163 rev = source.resolved_reference or source.reference; 164 - ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD"; 164 + ref = sourceSpec.branch or sourceSpec.rev or (if sourceSpec?tag then "refs/tags/${sourceSpec.tag}" else "HEAD"); 165 165 } 166 166 ) 167 167 else if isUrl then
+138 -11
pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix
··· 132 132 } 133 133 ); 134 134 135 + datadog-lambda = super.datadog-lambda.overridePythonAttrs (old: { 136 + postPatch = '' 137 + substituteInPlace setup.py --replace "setuptools==" "setuptools>=" 138 + ''; 139 + buildInputs = old.buildInputs ++ [ self.setuptools ]; 140 + }); 141 + 142 + ddtrace = super.ddtrace.overridePythonAttrs (old: { 143 + buildInputs = old.buildInputs ++ 144 + (pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.IOKit ]) ++ [ self.cython ]; 145 + }); 146 + 135 147 dictdiffer = super.dictdiffer.overridePythonAttrs ( 136 148 old: { 137 149 buildInputs = old.buildInputs ++ [ self.pytest-runner ]; ··· 235 247 old: 236 248 if old.format != "wheel" then rec { 237 249 nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.pkg-config ]; 238 - buildInputs = old.buildInputs ++ [ pkgs.hdf5 self.pkg-config self.cython ]; 250 + buildInputs = old.buildInputs ++ [ pkgs.hdf5 self.pkgconfig self.cython ]; 239 251 configure_flags = "--hdf5=${pkgs.hdf5}"; 240 252 postConfigure = '' 241 253 ${self.python.executable} setup.py configure ${configure_flags} ··· 407 419 export LLVM_CONFIG=${pkgs.llvm}/bin/llvm-config 408 420 ''; 409 421 410 - __impureHostDeps = pkgs.lib.optionals pkgs.stdenv.isDarwin [ "/usr/lib/libm.dylib" ]; 422 + __impureHostDeps = lib.optionals pkgs.stdenv.isDarwin [ "/usr/lib/libm.dylib" ]; 411 423 412 424 passthru = old.passthru // { llvm = pkgs.llvm; }; 413 425 } ··· 549 561 } 550 562 ); 551 563 564 + mysqlclient = super.mysqlclient.overridePythonAttrs ( 565 + old: { 566 + buildInputs = old.buildInputs ++ [ pkgs.libmysqlclient ]; 567 + } 568 + ); 569 + 552 570 netcdf4 = super.netcdf4.overridePythonAttrs ( 553 571 old: { 554 572 buildInputs = old.buildInputs ++ [ ··· 615 633 } 616 634 ); 617 635 636 + osqp = super.osqp.overridePythonAttrs ( 637 + old: { 638 + nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.cmake ]; 639 + dontUseCmakeConfigure = true; 640 + } 641 + ); 642 + 618 643 parsel = super.parsel.overridePythonAttrs ( 619 644 old: rec { 620 645 nativeBuildInputs = old.nativeBuildInputs ++ [ self.pytest-runner ]; ··· 642 667 } 643 668 ); 644 669 670 + # Work around https://github.com/nix-community/poetry2nix/issues/244 671 + # where git deps are not picked up as they should 672 + pip = 673 + if lib.versionAtLeast super.pip.version "20.3" then 674 + super.pip.overridePythonAttrs 675 + (old: 676 + let 677 + pname = "pip"; 678 + version = "20.2.4"; 679 + in 680 + { 681 + name = pname + "-" + version; 682 + inherit version; 683 + src = pkgs.fetchFromGitHub { 684 + owner = "pypa"; 685 + repo = pname; 686 + rev = version; 687 + sha256 = "eMVV4ftgV71HLQsSeaOchYlfaJVgzNrwUynn3SA1/Do="; 688 + name = "${pname}-${version}-source"; 689 + }; 690 + }) else super.pip; 691 + 645 692 poetry-core = super.poetry-core.overridePythonAttrs (old: { 646 693 # "Vendor" dependencies (for build-system support) 647 694 postPatch = '' ··· 972 1019 973 1020 pytest = super.pytest.overridePythonAttrs ( 974 1021 old: { 1022 + # Fixes https://github.com/pytest-dev/pytest/issues/7891 1023 + postPatch = old.postPatch or "" + '' 1024 + sed -i '/\[metadata\]/aversion = ${old.version}' setup.cfg 1025 + ''; 975 1026 doCheck = false; 976 1027 } 977 1028 ); ··· 996 1047 } 997 1048 ); 998 1049 1050 + # pytest-splinter seems to put a .marker file in an empty directory 1051 + # presumably so it's tracked by and can be installed with MANIFEST.in, see 1052 + # https://github.com/pytest-dev/pytest-splinter/commit/a48eeef662f66ff9d3772af618748e73211a186b 1053 + # 1054 + # This directory then gets used as an empty initial profile directory and is 1055 + # zipped up. But if the .marker file is in the Nix store, it has the 1056 + # creation date of 1970, and Zip doesn't work with such old files, so it 1057 + # fails at runtime! 1058 + # 1059 + # We fix this here by just removing the file after the installation 1060 + # 1061 + # The error you get without this is: 1062 + # 1063 + # E ValueError: ZIP does not support timestamps before 1980 1064 + # /nix/store/55b9ip7xkpimaccw9pa0vacy5q94f5xa-python3-3.7.6/lib/python3.7/zipfile.py:357: ValueError 1065 + pytest-splinter = super.pytest-splinter.overrideAttrs (old: { 1066 + postInstall = old.postInstall or "" + '' 1067 + rm $out/${super.python.sitePackages}/pytest_splinter/profiles/firefox/.marker 1068 + ''; 1069 + }); 1070 + 1071 + 999 1072 ffmpeg-python = super.ffmpeg-python.overridePythonAttrs ( 1000 1073 old: { 1001 1074 buildInputs = old.buildInputs ++ [ self.pytest-runner ]; ··· 1168 1241 # is explicitly disabled with USE_CUDA=0. 1169 1242 find $out -name "*.so" -exec ${pkgs.patchelf}/bin/patchelf --remove-needed libcuda.so.1 {} \; 1170 1243 ''; 1171 - buildInputs = old.buildInputs ++ lib.optionals enableCuda [ 1244 + buildInputs = (old.buildInputs or [ ]) 1245 + ++ [ self.typing-extensions ] 1246 + ++ lib.optionals enableCuda [ 1172 1247 pkgs.linuxPackages.nvidia_x11 1173 1248 pkgs.nccl.dev 1174 1249 pkgs.nccl.out 1175 1250 ]; 1176 1251 propagatedBuildInputs = [ 1177 - super.numpy 1178 - super.future 1252 + self.numpy 1253 + self.future 1179 1254 ]; 1180 1255 }) 1181 1256 ) ··· 1257 1332 format = "wheel"; 1258 1333 }; 1259 1334 # If "wheel" is built from source 1260 - sourcePackage = ( 1335 + sourcePackage = (( 1261 1336 pkgs.python3.pkgs.override { 1262 1337 python = self.python; 1263 1338 } 1264 - ).wheel.overridePythonAttrs ( 1265 - old: { 1266 - inherit (super.wheel) pname name version src; 1267 - } 1268 - ); 1339 + ).wheel.override { 1340 + inherit (self) buildPythonPackage bootstrapped-pip setuptools; 1341 + }).overrideAttrs (old: { 1342 + inherit (super.wheel) pname name version src; 1343 + }); 1269 1344 in 1270 1345 if isWheel then wheelPackage else sourcePackage; 1271 1346 ··· 1303 1378 } 1304 1379 ); 1305 1380 1381 + packaging = super.packaging.overridePythonAttrs ( 1382 + old: { 1383 + buildInputs = old.buildInputs ++ 1384 + # From 20.5 until 20.7, packaging used flit for packaging (heh) 1385 + # See https://github.com/pypa/packaging/pull/352 and https://github.com/pypa/packaging/pull/367 1386 + lib.optional (lib.versionAtLeast old.version "20.5" && lib.versionOlder old.version "20.8") [ self.flit-core ]; 1387 + } 1388 + ); 1389 + 1306 1390 supervisor = super.supervisor.overridePythonAttrs ( 1307 1391 old: { 1308 1392 propagatedBuildInputs = old.propagatedBuildInputs ++ [ ··· 1317 1401 propagatedBuildInputs = old.propagatedBuildInputs ++ [ self.toolz ]; 1318 1402 } 1319 1403 ); 1404 + 1405 + # For some reason the toml dependency of tqdm declared here: 1406 + # https://github.com/tqdm/tqdm/blob/67130a23646ae672836b971e1086b6ae4c77d930/pyproject.toml#L2 1407 + # is not translated correctly to a nix dependency. 1408 + tqdm = super.tqdm.overrideAttrs ( 1409 + old: { 1410 + buildInputs = [ super.toml ] ++ old.buildInputs; 1411 + } 1412 + ); 1413 + 1414 + watchdog = super.watchdog.overrideAttrs ( 1415 + old: { 1416 + buildInputs = old.buildInputs or [ ] 1417 + ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreServices; 1418 + } 1419 + ); 1420 + 1421 + # pyee cannot find `vcversioner` and other "setup requirements", so it tries to 1422 + # download them from the internet, which only works when nix sandboxing is disabled. 1423 + # Additionally, since pyee uses vcversioner to specify its version, we need to do this 1424 + # manually specify its version. 1425 + pyee = super.pyee.overrideAttrs ( 1426 + old: { 1427 + postPatch = old.postPatch or "" + '' 1428 + sed -i setup.py \ 1429 + -e '/setup_requires/,/],/d' \ 1430 + -e 's/vcversioner={},/version="${old.version}",/' 1431 + ''; 1432 + } 1433 + ); 1434 + 1435 + # nixpkgs has setuptools_scm 4.1.2 1436 + # but newrelic has a seemingly unnecessary version constraint for <4 1437 + # So we patch that out 1438 + newrelic = super.newrelic.overridePythonAttrs ( 1439 + old: { 1440 + postPatch = old.postPatch or "" + '' 1441 + substituteInPlace setup.py --replace '"setuptools_scm>=3.2,<4"' '"setuptools_scm"' 1442 + ''; 1443 + } 1444 + ); 1445 + 1446 + 1320 1447 }
+12 -7
pkgs/development/tools/poetry2nix/poetry2nix/pep425.nix
··· 1 - { lib, stdenv, python, isLinux ? stdenv.isLinux }: 1 + { lib, stdenv, poetryLib, python, isLinux ? stdenv.isLinux }: 2 2 let 3 3 inherit (lib.strings) hasSuffix hasInfix splitString removeSuffix; 4 + inherit (poetryLib) targetMachine; 4 5 5 6 # The 'cpxy" as determined by `python.version` 6 7 # ··· 72 73 withPlatform = 73 74 if isLinux 74 75 then 75 - ( 76 - x: x.platform == "manylinux1_${stdenv.hostPlatform.linuxArch}" 77 - || x.platform == "manylinux2010_${stdenv.hostPlatform.linuxArch}" 78 - || x.platform == "manylinux2014_${stdenv.hostPlatform.linuxArch}" 79 - || x.platform == "any" 80 - ) 76 + if targetMachine != null 77 + then 78 + ( 79 + x: x.platform == "manylinux1_${targetMachine}" 80 + || x.platform == "manylinux2010_${targetMachine}" 81 + || x.platform == "manylinux2014_${targetMachine}" 82 + || x.platform == "any" 83 + ) 84 + else 85 + (x: x.platform == "any") 81 86 else (x: hasInfix "macosx" x.platform || x.platform == "any"); 82 87 filterWheel = x: 83 88 let
+3 -3
pkgs/development/tools/poetry2nix/poetry2nix/pep508.nix
··· 1 1 { lib, stdenv, poetryLib }: python: 2 2 let 3 - inherit (poetryLib) ireplace; 3 + inherit (poetryLib) ireplace targetMachine; 4 4 5 5 # Like builtins.substring but with stop being offset instead of length 6 6 substr = start: stop: s: builtins.substring start (stop - start) s; ··· 95 95 else if stdenv.isDarwin then "darwin" 96 96 else throw "Unsupported platform" 97 97 ); 98 - platform_machine = stdenv.hostPlatform.linuxArch; 98 + platform_machine = targetMachine; 99 99 platform_python_implementation = 100 100 let 101 101 impl = python.passthru.implementation; ··· 132 132 mVal = ''[a-zA-Z0-9\'"_\. ]+''; 133 133 mOp = "in|[!=<>]+"; 134 134 e = stripStr exprs.value; 135 - m = builtins.map stripStr (builtins.match "^(${mVal}) *(${mOp}) *(${mVal})$" e); 135 + m = builtins.map stripStr (builtins.match ''^(${mVal}) *(${mOp}) *(${mVal})$'' e); 136 136 m0 = processVar (builtins.elemAt m 0); 137 137 m2 = processVar (builtins.elemAt m 2); 138 138 in
+1
pkgs/development/tools/poetry2nix/poetry2nix/pkgs/poetry/update
··· 3 3 4 4 rev=$(curl -s https://api.github.com/repos/python-poetry/poetry/releases/latest | jq -r '.name') 5 5 nix-prefetch-github --rev "$rev" python-poetry poetry > src.json 6 + echo >> src.json 6 7 7 8 src=$(nix-build --no-out-link --expr 'with import <nixpkgs> {}; fetchFromGitHub (lib.importJSON ./src.json)') 8 9 cp $src/pyproject.toml $src/poetry.lock .
+1 -1
pkgs/development/tools/poetry2nix/update
··· 16 16 mkdir build 17 17 cp *.* build/ 18 18 cp -r pkgs hooks bin build/ 19 - rm build/shell.nix build/generate.py build/overlay.nix build/flake.nix 19 + rm build/shell.nix build/generate.py build/overlay.nix build/flake.* 20 20 21 21 cat > build/README.md << EOF 22 22 Dont change these files here, they are maintained at https://github.com/nix-community/poetry2nix