pip: remove restriction

This commit is contained in:
Phillip Cloud 2021-11-07 09:50:59 -05:00
parent 5739058f26
commit 2fed7bc910
No known key found for this signature in database
GPG key ID: D908212070FD785E
9 changed files with 104 additions and 67 deletions

View file

@ -211,7 +211,7 @@ lib.makeScope pkgs.newScope (self: {
__toPluginAble = toPluginAble self;
inherit (hooks) pipBuildHook removePathDependenciesHook poetry2nixFixupHook wheelUnpackHook;
inherit (hooks) pipBuildHook removePathDependenciesHook removeGitDependenciesHook poetry2nixFixupHook wheelUnpackHook;
} // lib.optionalAttrs (! super ? setuptools-scm) {
# The canonical name is setuptools-scm
setuptools-scm = super.setuptools_scm;
@ -313,7 +313,10 @@ lib.makeScope pkgs.newScope (self: {
app = py.pkgs.buildPythonPackage (
passedAttrs // inputAttrs // {
nativeBuildInputs = inputAttrs.nativeBuildInputs ++ [ py.pkgs.removePathDependenciesHook ];
nativeBuildInputs = inputAttrs.nativeBuildInputs ++ [
py.pkgs.removePathDependenciesHook
py.pkgs.removeGitDependenciesHook
];
} // {
pname = moduleName pyProject.tool.poetry.name;
version = pyProject.tool.poetry.version;

View file

@ -21,9 +21,28 @@ in
substitutions = {
inherit pythonInterpreter;
yj = "${buildPackages.yj}/bin/yj";
pyprojectPatchScript = "${./pyproject-without-path.py}";
pyprojectPatchScript = "${./pyproject-without-special-deps.py}";
fields = [ "path" ];
kind = "path";
};
} ./remove-path-dependencies.sh
} ./remove-special-dependencies.sh
)
{ };
removeGitDependenciesHook = callPackage
({}:
makeSetupHook
{
name = "remove-git-dependencies.sh";
deps = [ ];
substitutions = {
inherit pythonInterpreter;
yj = "${buildPackages.yj}/bin/yj";
pyprojectPatchScript = "${./pyproject-without-special-deps.py}";
fields = [ "git" "branch" "rev" "tag" ];
kind = "git";
};
} ./remove-special-dependencies.sh
)
{ };

View file

@ -1,25 +0,0 @@
#!/usr/bin/env python
# Patch out path dependencies from a pyproject.json file
import json
import sys
data = json.load(sys.stdin)
def get_deep(o, path):
for p in path.split('.'):
o = o.get(p, {})
return o
for dep in get_deep(data, 'tool.poetry.dependencies').values():
if isinstance(dep, dict):
try:
del dep['path'];
except KeyError:
pass
else:
dep['version'] = '*'
json.dump(data, sys.stdout, indent=4)

View file

@ -0,0 +1,52 @@
#!/usr/bin/env python
# Patch out path dependencies from a pyproject.json file
import argparse
import json
import sys
def main(input, output, fields_to_remove):
data = json.load(input)
try:
deps = data["tool"]["poetry"]["dependencies"]
except KeyError:
pass
else:
for dep_name, dep in deps.items():
if isinstance(dep, dict):
removed = 0
for field in fields_to_remove:
removed += dep.pop(field, None) is not None
if removed:
dep["version"] = "*"
json.dump(data, output, separators=(",", ":"))
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument(
"-i",
"--input",
type=argparse.FileType("r"),
default=sys.stdin,
help="Location from which to read input JSON",
)
p.add_argument(
"-o",
"--output",
type=argparse.FileType("w"),
default=sys.stdout,
help="Location to write output JSON",
)
p.add_argument(
"-f",
"--fields-to-remove",
nargs="+",
help="The fields to remove from the TOML",
)
args = p.parse_args()
main(args.input, args.output, args.fields_to_remove)

View file

@ -1,12 +0,0 @@
remove-path-dependencies-hook() {
if ! test -f pyproject.toml; then
return
fi
# 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)

View file

@ -0,0 +1,20 @@
remove-@kind@-dependencies-hook() {
if ! test -f pyproject.toml; then
return
fi
echo "Removing @kind@ dependencies"
# Tell poetry not to resolve special dependencies. Any version is fine!
@yj@ -tj < pyproject.toml | \
@pythonInterpreter@ \
@pyprojectPatchScript@ \
--fields-to-remove @fields@ > pyproject.json
@yj@ -jt < pyproject.json > pyproject.toml
rm pyproject.json
echo "Finished removing @kind@ dependencies"
}
postPatchHooks+=(remove-@kind@-dependencies-hook)

View file

@ -119,8 +119,10 @@ pythonPackages.callPackage
pythonPackages.poetry2nixFixupHook
]
++ lib.optional (!isSource && (getManyLinuxDeps fileInfo.name).str != null) autoPatchelfHook
++ lib.optional (format == "pyproject") pythonPackages.removePathDependenciesHook
;
++ lib.optionals (format == "pyproject") [
pythonPackages.removePathDependenciesHook
pythonPackages.removeGitDependenciesHook
];
buildInputs = (
baseBuildInputs

View file

@ -974,28 +974,6 @@ self: super:
}
);
# Work around https://github.com/nix-community/poetry2nix/issues/244
# where git deps are not picked up as they should
pip =
if lib.versionAtLeast super.pip.version "20.3" then
super.pip.overridePythonAttrs
(old:
let
pname = "pip";
version = "20.2.4";
in
{
name = pname + "-" + version;
inherit version;
src = pkgs.fetchFromGitHub {
owner = "pypa";
repo = pname;
rev = version;
sha256 = "eMVV4ftgV71HLQsSeaOchYlfaJVgzNrwUynn3SA1/Do=";
name = "${pname}-${version}-source";
};
}) else super.pip;
platformdirs = super.platformdirs.overridePythonAttrs (old: {
postPatch = ''
substituteInPlace setup.py --replace 'setup()' 'setup(version="${old.version}")'

View file

@ -24,8 +24,8 @@ builtins.removeAttrs
composable-defaults = callTest ./composable-defaults { };
override = callTest ./override-support { };
override-default = callTest ./override-default-support { };
top-packages-1 = callTest ./common-pkgs-1 { };
top-packages-2 = callTest ./common-pkgs-2 { };
common-pkgs-1 = callTest ./common-pkgs-1 { };
common-pkgs-2 = callTest ./common-pkgs-2 { };
pep425 = pkgs.callPackage ./pep425 { inherit pep425;inherit pep425OSX;inherit pep425Python37; };
env = callTest ./env { };
pytest-randomly = callTest ./pytest-randomly { };