diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/default.nix b/pkgs/development/tools/poetry2nix/poetry2nix/default.nix index 5fb646fae884..cca876ca1e6b 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/default.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/default.nix @@ -24,7 +24,7 @@ in lib.makeScope pkgs.newScope (self: { # Poetry2nix version - version = "1.11.0"; + version = "1.12.0"; /* Returns an attrset { python, poetryPackages, pyProject, poetryLock } for the given pyproject/lockfile. @@ -114,7 +114,7 @@ lib.makeScope pkgs.newScope (self: { __toPluginAble = toPluginAble self; - inherit (hooks) pipBuildHook removePathDependenciesHook poetry2nixFixupHook; + inherit (hooks) pipBuildHook removePathDependenciesHook poetry2nixFixupHook wheelUnpackHook; } ) # Null out any filtered packages, we don't want python.pkgs from nixpkgs @@ -159,13 +159,28 @@ lib.makeScope pkgs.newScope (self: { } ); + inherit (py) pyProject; + + # Add executables from tool.poetry.scripts + scripts = pyProject.tool.poetry.scripts or { }; + hasScripts = scripts != { }; + scriptsPackage = import ./shell-scripts.nix { + inherit scripts lib; + inherit (py) python; + }; + + hasEditable = editablePackageSources != { }; editablePackage = import ./editable.nix { inherit pkgs lib poetryLib editablePackageSources; inherit (py) pyProject python; }; in - py.python.withPackages (_: py.poetryPackages ++ lib.optional (editablePackageSources != { }) editablePackage); + py.python.withPackages ( + _: py.poetryPackages + ++ lib.optional hasEditable editablePackage + ++ lib.optional hasScripts scriptsPackage + ); /* Creates a Python application from pyproject.toml and poetry.lock diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix b/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix index 001a3d09c6b9..e248a5e22359 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix @@ -49,4 +49,16 @@ in } ./fixup-hook.sh ) { }; + # When the "wheel" package itself is a wheel the nixpkgs hook (which pulls in "wheel") leads to infinite recursion + # It doesn't _really_ depend on wheel though, it just copies the wheel. + wheelUnpackHook = callPackage + ({}: + makeSetupHook + { + name = "wheel-unpack-hook.sh"; + deps = [ ]; + } ./wheel-unpack-hook.sh + ) { }; + + } diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/hooks/wheel-unpack-hook.sh b/pkgs/development/tools/poetry2nix/poetry2nix/hooks/wheel-unpack-hook.sh new file mode 100644 index 000000000000..fca808a933ba --- /dev/null +++ b/pkgs/development/tools/poetry2nix/poetry2nix/hooks/wheel-unpack-hook.sh @@ -0,0 +1,18 @@ +# Setup hook to use in case a wheel is fetched +echo "Sourcing wheel setup hook" + +wheelUnpackPhase(){ + echo "Executing wheelUnpackPhase" + runHook preUnpack + + mkdir -p dist + cp "$src" "dist/$(stripHash "$src")" + +# runHook postUnpack # Calls find...? + echo "Finished executing wheelUnpackPhase" +} + +if [ -z "${dontUseWheelUnpack-}" ] && [ -z "${unpackPhase-}" ]; then + echo "Using wheelUnpackPhase" + unpackPhase=wheelUnpackPhase +fi diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix b/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix index 6b784fd8fc5b..2791d7dfcb40 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/mk-poetry-dep.nix @@ -47,10 +47,16 @@ pythonPackages.callPackage isGit = isSource && source.type == "git"; isLocal = isSource && source.type == "directory"; localDepPath = toPath source.url; - pyProject = poetryLib.readTOML (localDepPath + "/pyproject.toml"); - buildSystemPkgs = poetryLib.getBuildSystemPkgs { - inherit pythonPackages pyProject; - }; + + buildSystemPkgs = + let + pyProjectPath = localDepPath + "/pyproject.toml"; + pyProject = poetryLib.readTOML pyProjectPath; + in + if builtins.pathExists pyProjectPath then poetryLib.getBuildSystemPkgs { + inherit pythonPackages pyProject; + } else [ ]; + fileInfo = let isBdist = f: lib.strings.hasSuffix "whl" f.file; diff --git a/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix b/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix index 202261ecdb91..d722ec71b9af 100644 --- a/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix +++ b/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix @@ -12,6 +12,40 @@ self: super: } ); + ansible = super.ansible.overridePythonAttrs ( + old: { + + prePatch = pkgs.python.pkgs.ansible.prePatch or ""; + + postInstall = pkgs.python.pkgs.ansible.postInstall or ""; + + # Inputs copied from nixpkgs as ansible doesn't specify it's dependencies + # in a correct manner. + propagatedBuildInputs = old.propagatedBuildInputs ++ [ + self.pycrypto + self.paramiko + self.jinja2 + self.pyyaml + self.httplib2 + self.six + self.netaddr + self.dnspython + self.jmespath + self.dopy + self.ncclient + ]; + } + ); + + ansible-lint = super.ansible-lint.overridePythonAttrs ( + old: { + buildInputs = old.buildInputs ++ [ self.setuptools-scm-git-archive ]; + preBuild = '' + export HOME=$(mktemp -d) + ''; + } + ); + astroid = super.astroid.overridePythonAttrs ( old: rec { buildInputs = old.buildInputs ++ [ self.pytest-runner ]; @@ -135,6 +169,15 @@ self: super: } ); + h3 = super.h3.overridePythonAttrs ( + old: { + preBuild = (old.preBuild or "") + '' + substituteInPlace h3/h3.py \ + --replace "'{}/{}'.format(_dirname, libh3_path)" '"${pkgs.h3}/lib/libh3${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}"' + ''; + } + ); + h5py = super.h5py.overridePythonAttrs ( old: if old.format != "wheel" then rec { @@ -324,6 +367,13 @@ self: super: pkgs.pkgconfig ]; + postPatch = '' + cat > setup.cfg <> $out/bin/${bin} + #!${python.interpreter} + import sys + import re + + # Insert "" to add CWD to import path + sys.path.insert(0, "") + + from ${module} import ${fn} + + if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', "", sys.argv[0]) + sys.exit(${fn}()) + EOF + chmod +x $out/bin/${bin} + ''; +in +python.pkgs.buildPythonPackage { + name = "poetry2nix-env-scripts"; + dontUnpack = true; + dontUseSetuptoolsBuild = true; + dontConfigure = true; + dontUseSetuptoolsCheck = true; + + installPhase = '' + mkdir -p $out/bin + ${lib.concatStringsSep "\n" (lib.mapAttrsToList mkScript scripts)} + ''; +}