mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 16:51:40 -05:00
Turn pyproject.toml patching into a hook
We should not be setting pre/post phases as it's counter intuitive when working with overrides.
This commit is contained in:
parent
fc6c640a12
commit
0367b93492
6 changed files with 50 additions and 24 deletions
26
default.nix
26
default.nix
|
@ -82,18 +82,22 @@ let
|
|||
);
|
||||
in
|
||||
lockPkgs;
|
||||
|
||||
overlays = builtins.map getFunctorFn (
|
||||
[
|
||||
(
|
||||
self: super: {
|
||||
mkPoetryDep = self.callPackage ./mk-poetry-dep.nix {
|
||||
inherit pkgs lib python poetryLib;
|
||||
};
|
||||
poetry = poetryPkg;
|
||||
# The canonical name is setuptools-scm
|
||||
setuptools-scm = super.setuptools_scm;
|
||||
}
|
||||
self: super: let
|
||||
hooks = self.callPackage ./hooks {};
|
||||
in
|
||||
{
|
||||
mkPoetryDep = self.callPackage ./mk-poetry-dep.nix {
|
||||
inherit pkgs lib python poetryLib;
|
||||
};
|
||||
poetry = poetryPkg;
|
||||
# The canonical name is setuptools-scm
|
||||
setuptools-scm = super.setuptools_scm;
|
||||
|
||||
inherit (hooks) removePathDependenciesHook;
|
||||
}
|
||||
)
|
||||
# Null out any filtered packages, we don't want python.pkgs from nixpkgs
|
||||
(self: super: builtins.listToAttrs (builtins.map (x: { name = x.name; value = null; }) incompatible))
|
||||
|
@ -187,15 +191,13 @@ let
|
|||
|
||||
buildInputs = mkInput "buildInputs" buildSystemPkgs;
|
||||
propagatedBuildInputs = mkInput "propagatedBuildInputs" (getDeps "dependencies") ++ ([ py.pkgs.setuptools ]);
|
||||
nativeBuildInputs = mkInput "nativeBuildInputs" [ pkgs.yj ];
|
||||
nativeBuildInputs = mkInput "nativeBuildInputs" [ pkgs.yj py.pkgs.removePathDependenciesHook ];
|
||||
checkInputs = mkInput "checkInputs" (getDeps "dev-dependencies");
|
||||
|
||||
passthru = {
|
||||
python = py;
|
||||
};
|
||||
|
||||
postPatch = (passedAttrs.postPatch or "") + poetryLib.removeTOMLPathDependencies python;
|
||||
|
||||
meta = meta // {
|
||||
inherit (pyProject.tool.poetry) description homepage;
|
||||
license = getLicenseBySpdxId (pyProject.tool.poetry.license or "unknown");
|
||||
|
|
25
hooks/default.nix
Normal file
25
hooks/default.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{ python
|
||||
, callPackage
|
||||
, makeSetupHook
|
||||
, yj
|
||||
}:
|
||||
|
||||
let
|
||||
pythonInterpreter = python.pythonForBuild.interpreter;
|
||||
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
|
||||
) {};
|
||||
|
||||
}
|
8
hooks/remove-path-dependencies.sh
Normal file
8
hooks/remove-path-dependencies.sh
Normal file
|
@ -0,0 +1,8 @@
|
|||
remove-path-dependencies-hook() {
|
||||
# Tell poetry not to resolve the path dependencies. Any version is fine!
|
||||
@yj@ -tj < pyproject.toml | @pythonInterpreter@ @pyprojectPatchScript@ > pyproject.json
|
||||
@yj@ -jt < pyproject.json > pyproject.toml
|
||||
rm pyproject.json
|
||||
}
|
||||
|
||||
postPatchHooks+=(remove-path-dependencies-hook)
|
9
lib.nix
9
lib.nix
|
@ -93,14 +93,6 @@ let
|
|||
[ pythonPackages.${drvAttr} or (throw "unsupported build system ${buildSystem}") ]
|
||||
);
|
||||
|
||||
removeTOMLPathDependencies = python: ''
|
||||
# Tell poetry not to resolve the path dependencies. Any version is
|
||||
# fine !
|
||||
${pkgs.yj}/bin/yj -tj < pyproject.toml | ${python.interpreter} ${./pyproject-without-path.py} > pyproject.json
|
||||
${pkgs.yj}/bin/yj -jt < pyproject.json > pyproject.toml
|
||||
rm pyproject.json
|
||||
'';
|
||||
|
||||
in
|
||||
{
|
||||
inherit
|
||||
|
@ -109,6 +101,5 @@ in
|
|||
isCompatible
|
||||
readTOML
|
||||
getBuildSystemPkgs
|
||||
removeTOMLPathDependencies
|
||||
;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,9 @@ pythonPackages.callPackage (
|
|||
dontStrip = format == "wheel";
|
||||
|
||||
nativeBuildInputs = (if (!isSource && (getManyLinuxDeps fileInfo.name).str != null) then [ autoPatchelfHook ] else [])
|
||||
++ lib.optional (isLocal) pkgs.yj;
|
||||
++ lib.optional (isLocal) pkgs.yj
|
||||
++ lib.optional (format == "pyproject") pythonPackages.removePathDependenciesHook
|
||||
;
|
||||
|
||||
buildInputs = (
|
||||
baseBuildInputs
|
||||
|
@ -120,8 +122,6 @@ pythonPackages.callPackage (
|
|||
# but dependencies try to access Django
|
||||
builtins.map (n: pythonPackages.${lib.toLower n}) (builtins.attrNames dependencies);
|
||||
|
||||
postPatch = (args.postPatch or "") + lib.optionalString isLocal (poetryLib.removeTOMLPathDependencies python);
|
||||
|
||||
meta = {
|
||||
broken = ! isCompatible python.pythonVersion python-versions;
|
||||
license = [];
|
||||
|
|
Loading…
Add table
Reference in a new issue