Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkgs/development/tools/poetry2nix/poetry2nix/cli.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ pkgs ? import <nixpkgs> { }
, lib ? pkgs.lib
, version
}:
let
inherit (pkgs) python3;
pname = "poetry2nix-cli";
in
pkgs.stdenv.mkDerivation {
pname = "poetry2nix";
inherit version;
inherit pname;
version = "0";

buildInputs = [
(python3.withPackages (ps: [ ps.toml ]))
Expand All @@ -23,16 +23,18 @@ pkgs.stdenv.mkDerivation {

buildPhase = ''
runHook preBuild
# this is the ./bin/poetry2nix
patchShebangs poetry2nix
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
mv poetry2nix $out/bin
# need to remap this to be consistent with `pkgs.lib.getBin` "standard"
mv poetry2nix $out/bin/${pname}

wrapProgram $out/bin/poetry2nix --prefix PATH ":" ${lib.makeBinPath [
wrapProgram $out/bin/${pname} --prefix PATH ":" ${lib.makeBinPath [
pkgs.nix-prefetch-git
]}

Expand Down
9 changes: 1 addition & 8 deletions pkgs/development/tools/poetry2nix/poetry2nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
, poetryLib ? import ./lib.nix { inherit lib pkgs; stdenv = pkgs.stdenv; }
}:
let
# Poetry2nix version
version = "1.42.1";

inherit (poetryLib) isCompatible readTOML normalizePackageName normalizePackageSet;

# Map SPDX identifiers to license names
Expand All @@ -17,7 +14,7 @@ let
toPluginAble = (import ./plugins.nix { inherit pkgs lib; }).toPluginAble;

# List of known build systems that are passed through from nixpkgs unmodified
knownBuildSystems = builtins.fromJSON (builtins.readFile ./known-build-systems.json);
knownBuildSystems = lib.importJSON ./known-build-systems.json;
nixpkgsBuildSystems = lib.subtractLists [ "poetry" "poetry-core" ] knownBuildSystems;

mkInputAttrs =
Expand Down Expand Up @@ -93,9 +90,6 @@ let

in
lib.makeScope pkgs.newScope (self: {

inherit version;

/* Returns a package of editable sources whose changes will be available without needing to restart the
nix-shell.
In editablePackageSources you can pass a mapping from package name to source directory to have
Expand Down Expand Up @@ -469,7 +463,6 @@ lib.makeScope pkgs.newScope (self: {
/* Poetry2nix CLI used to supplement SHA-256 hashes for git dependencies */
cli = import ./cli.nix {
inherit pkgs lib;
inherit (self) version;
};

# inherit mkPoetryEnv mkPoetryApplication mkPoetryPackages;
Expand Down
168 changes: 93 additions & 75 deletions pkgs/development/tools/poetry2nix/poetry2nix/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
, pip
, pkgs
, lib
,
}:
let
inherit (python.pythonForBuild.pkgs) callPackage;
pythonInterpreter = python.pythonForBuild.interpreter;
pythonSitePackages = python.sitePackages;

nonOverlayedPython = pkgs.python3.pythonForBuild.withPackages (ps: [ ps.tomlkit ]);
makeRemoveSpecialDependenciesHook = { fields, kind }:
makeRemoveSpecialDependenciesHook =
{ fields
, kind
,
}:
nonOverlayedPython.pkgs.callPackage
(
_:
Expand All @@ -29,14 +34,14 @@ let
inherit fields;
inherit kind;
};
} ./remove-special-dependencies.sh
}
./remove-special-dependencies.sh
)
{ };
makeSetupHookArgs = deps:
if lib.elem "propagatedBuildInputs" (builtins.attrNames (builtins.functionArgs makeSetupHook)) then
{ propagatedBuildInputs = deps; }
else
{ inherit deps; };
if lib.elem "propagatedBuildInputs" (builtins.attrNames (builtins.functionArgs makeSetupHook))
then { propagatedBuildInputs = deps; }
else { inherit deps; };
in
{
removePathDependenciesHook = makeRemoveSpecialDependenciesHook {
Expand All @@ -49,84 +54,97 @@ in
kind = "git";
};

pipBuildHook =
callPackage
(
{ pip
, wheel
,
}:
makeSetupHook
({
name = "pip-build-hook.sh";
substitutions = {
inherit pythonInterpreter pythonSitePackages;
};
}
// (makeSetupHookArgs [ pip wheel ]))
./pip-build-hook.sh
)
{ };

pipBuildHook = callPackage
(
{ pip, wheel }:
makeSetupHook
({
name = "pip-build-hook.sh";
substitutions = {
inherit pythonInterpreter pythonSitePackages;
};
} // (makeSetupHookArgs [ pip wheel ])) ./pip-build-hook.sh
)
{ };

poetry2nixFixupHook = callPackage
(
_:
makeSetupHook
{
name = "fixup-hook.sh";
substitutions = {
inherit pythonSitePackages;
filenames = builtins.concatStringsSep " " [
"pyproject.toml"
"README.md"
"LICENSE"
];
};
} ./fixup-hook.sh
)
{ };
poetry2nixFixupHook =
callPackage
(
_:
makeSetupHook
{
name = "fixup-hook.sh";
substitutions = {
inherit pythonSitePackages;
filenames = builtins.concatStringsSep " " [
"pyproject.toml"
"README.md"
"LICENSE"
"CHANGELOG.md"
"CHANGES.md"
];
};
}
./fixup-hook.sh
)
{ };

# As of 2023-03 a newer version of packaging introduced a new behaviour where python-requires
# cannot contain version wildcards. This behaviour is complaint with PEP440
#
# The wildcards are a no-op anyway so we can work around this issue by just dropping the precision down to the last known number.
poetry2nixPythonRequiresPatchHook = callPackage
(
_:
let
# Python pre 3.9 does not contain the ast.unparse method.
# We can extract this from Python 3.8 for any
unparser = stdenv.mkDerivation {
name = "${python.name}-astunparse";
inherit (python) src;
dontConfigure = true;
dontBuild = true;

installPhase = ''
mkdir -p $out/poetry2nix_astunparse
cp ./Tools/parser/unparse.py $out/poetry2nix_astunparse/__init__.py
'';
};

pythonPath =
[ ]
++ lib.optional (lib.versionOlder python.version "3.9") unparser;
poetry2nixPythonRequiresPatchHook =
callPackage
(
_:
let
# Python pre 3.9 does not contain the ast.unparse method.
# We can extract this from Python 3.8 for any
unparser = stdenv.mkDerivation {
name = "${python.name}-astunparse";
inherit (python) src;
dontConfigure = true;
dontBuild = true;

in
makeSetupHook
{
name = "require-python-patch-hook.sh";
substitutions = {
inherit pythonInterpreter pythonPath;
patchScript = ./python-requires-patch-hook.py;
installPhase = ''
mkdir -p $out/poetry2nix_astunparse
cp ./Tools/parser/unparse.py $out/poetry2nix_astunparse/__init__.py
'';
};
} ./python-requires-patch-hook.sh
)
{ };

pythonPath =
[ ]
++ lib.optional (lib.versionOlder python.version "3.9") unparser;
in
makeSetupHook
{
name = "require-python-patch-hook.sh";
substitutions = {
inherit pythonInterpreter pythonPath;
patchScript = ./python-requires-patch-hook.py;
};
}
./python-requires-patch-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";
} ./wheel-unpack-hook.sh
)
{ };
wheelUnpackHook =
callPackage
(
_:
makeSetupHook
{
name = "wheel-unpack-hook.sh";
}
./wheel-unpack-hook.sh
)
{ };
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"flit",
"flit-core",
"pbr",
"flitBuildHook",
"cython",
"hatchling",
"hatch-vcs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ pythonPackages.callPackage
rev = source.resolved_reference or source.reference;
ref = sourceSpec.branch or (if sourceSpec ? tag then "refs/tags/${sourceSpec.tag}" else "HEAD");
} // (
lib.optionalAttrs ((sourceSpec ? rev) && (lib.versionAtLeast builtins.nixVersion "2.4")) {
allRefs = true;
}) // (
lib.optionalAttrs
(((sourceSpec ? rev) || (sourceSpec ? branch) || (source ? resolved_reference) || (source ? reference))
&& (lib.versionAtLeast builtins.nixVersion "2.4"))
{
allRefs = true;
}) // (
lib.optionalAttrs (lib.versionAtLeast builtins.nixVersion "2.4") {
submodules = true;
})
Expand Down
Loading