mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-10-01 17:40:20 +02:00
Merge pull request #170813 from thiagokokada/wheel-deps-versions-hook-init
wheelDepsVersionsHook: init
This commit is contained in:
commit
32500cc1c1
|
@ -49,21 +49,9 @@ buildPythonApplication rec {
|
|||
hash = "sha256-o5dVJDbdKgo6hMMU9mKzoouSgVWl7xSAp+Aq61VcfeU=";
|
||||
};
|
||||
|
||||
# Relax some dependencies
|
||||
postPatch = ''
|
||||
substituteInPlace requirements.txt \
|
||||
--replace 'WTForms ==' 'WTForms >=' \
|
||||
--replace 'attrs == 20.2.0' 'attrs' \
|
||||
--replace 'elasticsearch ==' 'elasticsearch >=' \
|
||||
--replace 'python_dotenv ==' 'python_dotenv >=' \
|
||||
--replace 'python_frontmatter == 0.5.0' 'python_frontmatter' \
|
||||
--replace 'requests ==' 'requests >=' \
|
||||
--replace 'validators ==' 'validators >=' \
|
||||
--replace 'flask-login == ' 'flask-login >= ' \
|
||||
--replace 'tinydb ==' 'tinydb >=' \
|
||||
--replace 'Flask_WTF == 0.14.3' 'Flask_WTF' \
|
||||
--replace 'Flask ==' 'Flask >='
|
||||
'';
|
||||
nativeBuildInputs = [ pythonRelaxDepsHook ];
|
||||
|
||||
pythonRelaxDeps = true;
|
||||
|
||||
propagatedBuildInputs = [
|
||||
appdirs
|
||||
|
|
|
@ -15,16 +15,15 @@ python3.pkgs.buildPythonApplication rec {
|
|||
hash = "sha256-xo5EWtP2aN8YzP8ro3bnxZwUGUp0PHD0g8hk+Y+gExE=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [ python3.pkgs.pythonRelaxDepsHook ];
|
||||
|
||||
propagatedBuildInputs = with python3.pkgs; [
|
||||
sh
|
||||
pygit2
|
||||
clint
|
||||
];
|
||||
|
||||
postPatch = ''
|
||||
substituteInPlace setup.py \
|
||||
--replace "pygit2==0.28.2" "pygit2>=0.28.2"
|
||||
'';
|
||||
pythonRelaxDeps = [ "pygit2" ];
|
||||
|
||||
doCheck = false;
|
||||
|
||||
|
|
|
@ -124,6 +124,15 @@ in rec {
|
|||
};
|
||||
} ./python-recompile-bytecode-hook.sh ) {};
|
||||
|
||||
pythonRelaxDepsHook = callPackage ({ wheel }:
|
||||
makeSetupHook {
|
||||
name = "python-relax-deps-hook";
|
||||
deps = [ wheel ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter;
|
||||
};
|
||||
} ./python-relax-deps-hook.sh) {};
|
||||
|
||||
pythonRemoveBinBytecodeHook = callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "python-remove-bin-bytecode-hook";
|
||||
|
@ -161,8 +170,8 @@ in rec {
|
|||
deps = [ ensureNewerSourcesForZipFilesHook ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter;
|
||||
};
|
||||
} ./venv-shell-hook.sh) {});
|
||||
};
|
||||
} ./venv-shell-hook.sh) {});
|
||||
|
||||
wheelUnpackHook = callPackage ({ wheel }:
|
||||
makeSetupHook {
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
# Setup hook that modifies Python dependencies versions.
|
||||
#
|
||||
# Example usage in a derivation:
|
||||
#
|
||||
# { …, pythonPackages, … }:
|
||||
#
|
||||
# pythonPackages.buildPythonPackage {
|
||||
# …
|
||||
# nativeBuildInputs = [ pythonPackages.pythonRelaxDepsHook ];
|
||||
#
|
||||
# # This will relax the dependency restrictions
|
||||
# # e.g.: abc>1,<=2 -> abc
|
||||
# pythonRelaxDeps = [ "abc" ];
|
||||
# # This will relax all dependencies restrictions instead
|
||||
# # pythonRelaxDeps = true;
|
||||
# # This will remove the dependency
|
||||
# # e.g.: cde>1,<=2 -> <nothing>
|
||||
# pythonRemoveDeps = [ "cde" ];
|
||||
# # This will remove all dependencies from the project
|
||||
# # pythonRemoveDeps = true;
|
||||
# …
|
||||
# }
|
||||
|
||||
_pythonRelaxDeps() {
|
||||
local -r metadata_file="$1"
|
||||
|
||||
if [[ -z "${pythonRelaxDeps:-}" ]] || [[ "$pythonRelaxDeps" == 0 ]]; then
|
||||
return
|
||||
elif [[ "$pythonRelaxDeps" == 1 ]]; then
|
||||
sed -i "$metadata_file" -r \
|
||||
-e 's/(Requires-Dist: \S*) \(.*\)/\1/'
|
||||
else
|
||||
for dep in $pythonRelaxDeps; do
|
||||
sed -i "$metadata_file" -r \
|
||||
-e "s/(Requires-Dist: $dep) \(.*\)/\1/"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
_pythonRemoveDeps() {
|
||||
local -r metadata_file="$1"
|
||||
|
||||
if [[ -z "${pythonRemoveDeps:-}" ]] || [[ "$pythonRemoveDeps" == 0 ]]; then
|
||||
return
|
||||
elif [[ "$pythonRemoveDeps" == 1 ]]; then
|
||||
sed -i "$metadata_file" \
|
||||
-e '/Requires-Dist:.*/d'
|
||||
else
|
||||
for dep in $pythonRemoveDeps; do
|
||||
sed -i "$metadata_file" \
|
||||
-e "/Requires-Dist: $dep/d"
|
||||
done
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
pythonRelaxDepsHook() {
|
||||
pushd dist
|
||||
|
||||
local -r package="$pname-$version"
|
||||
local -r unpack_dir="unpacked"
|
||||
local -r metadata_file="$unpack_dir/$package/$package.dist-info/METADATA"
|
||||
local -r wheel=$(echo "$package"*".whl")
|
||||
|
||||
@pythonInterpreter@ -m wheel unpack --dest "$unpack_dir" "$wheel"
|
||||
rm -rf "$wheel"
|
||||
|
||||
_pythonRelaxDeps "$metadata_file"
|
||||
_pythonRemoveDeps "$metadata_file"
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "pythonRelaxDepsHook: resulting METADATA:"
|
||||
cat "$unpack_dir/$package/$package.dist-info/METADATA"
|
||||
fi
|
||||
|
||||
@pythonInterpreter@ -m wheel pack "$unpack_dir/$package"
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
postBuild+=" pythonRelaxDepsHook"
|
|
@ -1,6 +1,7 @@
|
|||
{ lib
|
||||
, buildPythonPackage
|
||||
, fetchPypi
|
||||
, pythonRelaxDepsHook
|
||||
, pbr
|
||||
, python-mimeparse
|
||||
, extras
|
||||
|
@ -20,15 +21,13 @@ buildPythonPackage rec {
|
|||
|
||||
propagatedBuildInputs = [ pbr python-mimeparse extras ];
|
||||
buildInputs = [ traceback2 ];
|
||||
nativeBuildInputs = [ pythonRelaxDepsHook ];
|
||||
|
||||
# testscenarios has a circular dependency on testtools
|
||||
doCheck = false;
|
||||
checkInputs = [ testscenarios ];
|
||||
|
||||
# testtools 2.0.0 and up has a circular run-time dependency on futures
|
||||
postPatch = ''
|
||||
substituteInPlace requirements.txt --replace "fixtures>=1.3.0" ""
|
||||
'';
|
||||
pythonRemoveDeps = [ "fixtures" ];
|
||||
|
||||
meta = {
|
||||
description = "A set of extensions to the Python standard library's unit testing framework";
|
||||
|
|
|
@ -119,6 +119,7 @@ in {
|
|||
pythonImportsCheckHook
|
||||
pythonNamespacesHook
|
||||
pythonRecompileBytecodeHook
|
||||
pythonRelaxDepsHook
|
||||
pythonRemoveBinBytecodeHook
|
||||
pythonRemoveTestsDirHook
|
||||
setuptoolsBuildHook
|
||||
|
|
Loading…
Reference in a new issue