uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead
https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948 this can do it nicely. Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
commit
56de2bcd43
30691 changed files with 3076956 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
# Setup hook to use in case a conda binary package is installed
|
||||
echo "Sourcing conda install hook"
|
||||
|
||||
condaInstallPhase(){
|
||||
echo "Executing condaInstallPhase"
|
||||
runHook preInstall
|
||||
|
||||
# There are two different formats of conda packages.
|
||||
# It either contains only a site-packages directory
|
||||
# or multiple top level directories.
|
||||
siteDir=@pythonSitePackages@
|
||||
if [ -e ./site-packages ]; then
|
||||
mkdir -p $out/$siteDir
|
||||
cp -r ./site-packages/* $out/$siteDir
|
||||
else
|
||||
cp -r . $out
|
||||
rm $out/env-vars
|
||||
fi
|
||||
|
||||
runHook postInstall
|
||||
echo "Finished executing condaInstallPhase"
|
||||
}
|
||||
|
||||
if [ -z "${installPhase-}" ]; then
|
||||
echo "Using condaInstallPhase"
|
||||
installPhase=condaInstallPhase
|
||||
fi
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
# Setup hook to use in case a conda binary package is fetched
|
||||
echo "Sourcing conda unpack hook"
|
||||
|
||||
condaUnpackPhase(){
|
||||
echo "Executing condaUnpackPhase"
|
||||
runHook preUnpack
|
||||
|
||||
# use lbzip2 for parallel decompression (bz2 is slow)
|
||||
lbzip2 -dc -n $NIX_BUILD_CORES $src | tar --exclude='info' -x
|
||||
|
||||
# runHook postUnpack # Calls find...?
|
||||
echo "Finished executing condaUnpackPhase"
|
||||
}
|
||||
|
||||
if [ -z "${unpackPhase-}" ]; then
|
||||
echo "Using condaUnpackPhase"
|
||||
unpackPhase=condaUnpackPhase
|
||||
fi
|
||||
187
pkgs/development/interpreters/python/hooks/default.nix
Normal file
187
pkgs/development/interpreters/python/hooks/default.nix
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
# Hooks for building Python packages.
|
||||
{ python
|
||||
, lib
|
||||
, makeSetupHook
|
||||
, disabledIf
|
||||
, isPy3k
|
||||
, ensureNewerSourcesForZipFilesHook
|
||||
, findutils
|
||||
}:
|
||||
|
||||
let
|
||||
callPackage = python.pythonForBuild.pkgs.callPackage;
|
||||
pythonInterpreter = python.pythonForBuild.interpreter;
|
||||
pythonSitePackages = python.sitePackages;
|
||||
pythonCheckInterpreter = python.interpreter;
|
||||
setuppy = ../run_setup.py;
|
||||
in rec {
|
||||
|
||||
condaInstallHook = callPackage ({ gnutar, lbzip2 }:
|
||||
makeSetupHook {
|
||||
name = "conda-install-hook";
|
||||
deps = [ gnutar lbzip2 ];
|
||||
substitutions = {
|
||||
inherit pythonSitePackages;
|
||||
};
|
||||
} ./conda-install-hook.sh) {};
|
||||
|
||||
condaUnpackHook = callPackage ({}:
|
||||
makeSetupHook {
|
||||
name = "conda-unpack-hook";
|
||||
deps = [];
|
||||
} ./conda-unpack-hook.sh) {};
|
||||
|
||||
eggBuildHook = callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "egg-build-hook.sh";
|
||||
deps = [ ];
|
||||
} ./egg-build-hook.sh) {};
|
||||
|
||||
eggInstallHook = callPackage ({ setuptools }:
|
||||
makeSetupHook {
|
||||
name = "egg-install-hook.sh";
|
||||
deps = [ setuptools ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter pythonSitePackages;
|
||||
};
|
||||
} ./egg-install-hook.sh) {};
|
||||
|
||||
eggUnpackHook = callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "egg-unpack-hook.sh";
|
||||
deps = [ ];
|
||||
} ./egg-unpack-hook.sh) {};
|
||||
|
||||
flitBuildHook = callPackage ({ flit }:
|
||||
makeSetupHook {
|
||||
name = "flit-build-hook";
|
||||
deps = [ flit ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter;
|
||||
};
|
||||
} ./flit-build-hook.sh) {};
|
||||
|
||||
pipBuildHook = callPackage ({ pip, wheel }:
|
||||
makeSetupHook {
|
||||
name = "pip-build-hook.sh";
|
||||
deps = [ pip wheel ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter pythonSitePackages;
|
||||
};
|
||||
} ./pip-build-hook.sh) {};
|
||||
|
||||
pipInstallHook = callPackage ({ pip }:
|
||||
makeSetupHook {
|
||||
name = "pip-install-hook";
|
||||
deps = [ pip ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter pythonSitePackages;
|
||||
};
|
||||
} ./pip-install-hook.sh) {};
|
||||
|
||||
pytestCheckHook = callPackage ({ pytest }:
|
||||
makeSetupHook {
|
||||
name = "pytest-check-hook";
|
||||
deps = [ pytest ];
|
||||
substitutions = {
|
||||
inherit pythonCheckInterpreter;
|
||||
};
|
||||
} ./pytest-check-hook.sh) {};
|
||||
|
||||
pythonCatchConflictsHook = callPackage ({ setuptools }:
|
||||
makeSetupHook {
|
||||
name = "python-catch-conflicts-hook";
|
||||
deps = [ setuptools ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter;
|
||||
catchConflicts=../catch_conflicts/catch_conflicts.py;
|
||||
};
|
||||
} ./python-catch-conflicts-hook.sh) {};
|
||||
|
||||
pythonImportsCheckHook = callPackage ({}:
|
||||
makeSetupHook {
|
||||
name = "python-imports-check-hook.sh";
|
||||
substitutions = {
|
||||
inherit pythonCheckInterpreter;
|
||||
};
|
||||
} ./python-imports-check-hook.sh) {};
|
||||
|
||||
pythonNamespacesHook = callPackage ({}:
|
||||
makeSetupHook {
|
||||
name = "python-namespaces-hook.sh";
|
||||
substitutions = {
|
||||
inherit pythonSitePackages findutils;
|
||||
};
|
||||
} ./python-namespaces-hook.sh) {};
|
||||
|
||||
pythonRecompileBytecodeHook = callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "python-recompile-bytecode-hook";
|
||||
substitutions = {
|
||||
inherit pythonInterpreter pythonSitePackages;
|
||||
compileArgs = lib.concatStringsSep " " (["-q" "-f" "-i -"] ++ lib.optionals isPy3k ["-j $NIX_BUILD_CORES"]);
|
||||
bytecodeName = if isPy3k then "__pycache__" else "*.pyc";
|
||||
};
|
||||
} ./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";
|
||||
} ./python-remove-bin-bytecode-hook.sh) {};
|
||||
|
||||
pythonRemoveTestsDirHook = callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "python-remove-tests-dir-hook";
|
||||
substitutions = {
|
||||
inherit pythonSitePackages;
|
||||
};
|
||||
} ./python-remove-tests-dir-hook.sh) {};
|
||||
|
||||
setuptoolsBuildHook = callPackage ({ setuptools, wheel }:
|
||||
makeSetupHook {
|
||||
name = "setuptools-setup-hook";
|
||||
deps = [ setuptools wheel ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter pythonSitePackages setuppy;
|
||||
};
|
||||
} ./setuptools-build-hook.sh) {};
|
||||
|
||||
setuptoolsCheckHook = callPackage ({ setuptools }:
|
||||
makeSetupHook {
|
||||
name = "setuptools-check-hook";
|
||||
deps = [ setuptools ];
|
||||
substitutions = {
|
||||
inherit pythonCheckInterpreter setuppy;
|
||||
};
|
||||
} ./setuptools-check-hook.sh) {};
|
||||
|
||||
venvShellHook = disabledIf (!isPy3k) (callPackage ({ }:
|
||||
makeSetupHook {
|
||||
name = "venv-shell-hook";
|
||||
deps = [ ensureNewerSourcesForZipFilesHook ];
|
||||
substitutions = {
|
||||
inherit pythonInterpreter;
|
||||
};
|
||||
} ./venv-shell-hook.sh) {});
|
||||
|
||||
wheelUnpackHook = callPackage ({ wheel }:
|
||||
makeSetupHook {
|
||||
name = "wheel-unpack-hook.sh";
|
||||
deps = [ wheel ];
|
||||
} ./wheel-unpack-hook.sh) {};
|
||||
|
||||
sphinxHook = callPackage ({ sphinx }:
|
||||
makeSetupHook {
|
||||
name = "python${python.pythonVersion}-sphinx-hook";
|
||||
deps = [ sphinx ];
|
||||
} ./sphinx-hook.sh) {};
|
||||
}
|
||||
15
pkgs/development/interpreters/python/hooks/egg-build-hook.sh
Normal file
15
pkgs/development/interpreters/python/hooks/egg-build-hook.sh
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Setup hook to use for eggs
|
||||
echo "Sourcing egg-build-hook"
|
||||
|
||||
eggBuildPhase() {
|
||||
echo "Executing eggBuildPhase"
|
||||
runHook preBuild
|
||||
|
||||
runHook postBuild
|
||||
echo "Finished executing eggBuildPhase"
|
||||
}
|
||||
|
||||
if [ -z "${dontUseEggBuild-}" ] && [ -z "${buildPhase-}" ]; then
|
||||
echo "Using eggBuildPhase"
|
||||
buildPhase=eggBuildPhase
|
||||
fi
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Setup hook for eggs
|
||||
echo "Sourcing egg-install-hook"
|
||||
|
||||
eggInstallPhase() {
|
||||
echo "Executing eggInstallPhase"
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p "$out/@pythonSitePackages@"
|
||||
export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH"
|
||||
|
||||
find
|
||||
@pythonInterpreter@ -m easy_install --prefix="$out" *.egg
|
||||
|
||||
runHook postInstall
|
||||
echo "Finished executing eggInstallPhase"
|
||||
}
|
||||
|
||||
if [ -z "${dontUseEggInstall-}" ] && [ -z "${installPhase-}" ]; then
|
||||
echo "Using eggInstallPhase"
|
||||
installPhase=eggInstallPhase
|
||||
fi
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# Setup hook to use in case an egg is fetched
|
||||
echo "Sourcing egg setup hook"
|
||||
|
||||
eggUnpackPhase(){
|
||||
echo "Executing eggUnpackPhase"
|
||||
runHook preUnpack
|
||||
|
||||
cp "$src" "$(stripHash "$src")"
|
||||
|
||||
# runHook postUnpack # Calls find...?
|
||||
echo "Finished executing eggUnpackPhase"
|
||||
}
|
||||
|
||||
if [ -z "${dontUseEggUnpack-}" ] && [ -z "${unpackPhase-}" ]; then
|
||||
echo "Using eggUnpackPhase"
|
||||
unpackPhase=eggUnpackPhase
|
||||
fi
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# Setup hook for flit
|
||||
echo "Sourcing flit-build-hook"
|
||||
|
||||
flitBuildPhase () {
|
||||
echo "Executing flitBuildPhase"
|
||||
runHook preBuild
|
||||
@pythonInterpreter@ -m flit build --format wheel
|
||||
runHook postBuild
|
||||
echo "Finished executing flitBuildPhase"
|
||||
}
|
||||
|
||||
if [ -z "${dontUseFlitBuild-}" ] && [ -z "${buildPhase-}" ]; then
|
||||
echo "Using flitBuildPhase"
|
||||
buildPhase=flitBuildPhase
|
||||
fi
|
||||
43
pkgs/development/interpreters/python/hooks/pip-build-hook.sh
Normal file
43
pkgs/development/interpreters/python/hooks/pip-build-hook.sh
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Setup hook to use for pip projects
|
||||
echo "Sourcing pip-build-hook"
|
||||
|
||||
pipBuildPhase() {
|
||||
echo "Executing pipBuildPhase"
|
||||
runHook preBuild
|
||||
|
||||
mkdir -p dist
|
||||
echo "Creating a wheel..."
|
||||
@pythonInterpreter@ -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .
|
||||
echo "Finished creating a wheel..."
|
||||
|
||||
runHook postBuild
|
||||
echo "Finished executing pipBuildPhase"
|
||||
}
|
||||
|
||||
pipShellHook() {
|
||||
echo "Executing pipShellHook"
|
||||
runHook preShellHook
|
||||
|
||||
# Long-term setup.py should be dropped.
|
||||
if [ -e pyproject.toml ]; then
|
||||
tmp_path=$(mktemp -d)
|
||||
export PATH="$tmp_path/bin:$PATH"
|
||||
export PYTHONPATH="$tmp_path/@pythonSitePackages@:$PYTHONPATH"
|
||||
mkdir -p "$tmp_path/@pythonSitePackages@"
|
||||
@pythonInterpreter@ -m pip install -e . --prefix "$tmp_path" \
|
||||
--no-build-isolation >&2
|
||||
fi
|
||||
|
||||
runHook postShellHook
|
||||
echo "Finished executing pipShellHook"
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePipBuild-}" ] && [ -z "${buildPhase-}" ]; then
|
||||
echo "Using pipBuildPhase"
|
||||
buildPhase=pipBuildPhase
|
||||
fi
|
||||
|
||||
if [ -z "${shellHook-}" ]; then
|
||||
echo "Using pipShellHook"
|
||||
shellHook=pipShellHook
|
||||
fi
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# Setup hook for pip.
|
||||
echo "Sourcing pip-install-hook"
|
||||
|
||||
declare -a pipInstallFlags
|
||||
|
||||
pipInstallPhase() {
|
||||
echo "Executing pipInstallPhase"
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p "$out/@pythonSitePackages@"
|
||||
export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH"
|
||||
|
||||
pushd dist || return 1
|
||||
@pythonInterpreter@ -m pip install ./*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache $pipInstallFlags
|
||||
popd || return 1
|
||||
|
||||
runHook postInstall
|
||||
echo "Finished executing pipInstallPhase"
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePipInstall-}" ] && [ -z "${installPhase-}" ]; then
|
||||
echo "Using pipInstallPhase"
|
||||
installPhase=pipInstallPhase
|
||||
fi
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
# Setup hook for pytest
|
||||
echo "Sourcing pytest-check-hook"
|
||||
|
||||
declare -ar disabledTests
|
||||
declare -a disabledTestPaths
|
||||
|
||||
function _concatSep {
|
||||
local result
|
||||
local sep="$1"
|
||||
local -n arr=$2
|
||||
for index in ${!arr[*]}; do
|
||||
if [ $index -eq 0 ]; then
|
||||
result="${arr[index]}"
|
||||
else
|
||||
result+=" $sep ${arr[index]}"
|
||||
fi
|
||||
done
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
function _pytestComputeDisabledTestsString () {
|
||||
declare -a tests
|
||||
local tests=($1)
|
||||
local prefix="not "
|
||||
prefixed=( "${tests[@]/#/$prefix}" )
|
||||
result=$(_concatSep "and" prefixed)
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
function pytestCheckPhase() {
|
||||
echo "Executing pytestCheckPhase"
|
||||
runHook preCheck
|
||||
|
||||
# Compose arguments
|
||||
args=" -m pytest"
|
||||
if [ -n "$disabledTests" ]; then
|
||||
disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}")
|
||||
args+=" -k \""$disabledTestsString"\""
|
||||
fi
|
||||
|
||||
if [ -n "${disabledTestPaths-}" ]; then
|
||||
eval "disabledTestPaths=($disabledTestPaths)"
|
||||
fi
|
||||
|
||||
for path in ${disabledTestPaths[@]}; do
|
||||
if [ ! -e "$path" ]; then
|
||||
echo "Disabled tests path \"$path\" does not exist. Aborting"
|
||||
exit 1
|
||||
fi
|
||||
args+=" --ignore=\"$path\""
|
||||
done
|
||||
args+=" ${pytestFlagsArray[@]}"
|
||||
eval "@pythonCheckInterpreter@ $args"
|
||||
|
||||
runHook postCheck
|
||||
echo "Finished executing pytestCheckPhase"
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
|
||||
echo "Using pytestCheckPhase"
|
||||
preDistPhases+=" pytestCheckPhase"
|
||||
|
||||
# It's almost always the case that setuptoolsCheckPhase should not be ran
|
||||
# when the pytestCheckHook is being ran
|
||||
if [ -z "${useSetuptoolsCheck-}" ]; then
|
||||
dontUseSetuptoolsCheck=1
|
||||
|
||||
# Remove command if already injected into preDistPhases
|
||||
if [[ "$preDistPhases" =~ "setuptoolsCheckPhase" ]]; then
|
||||
echo "Removing setuptoolsCheckPhase"
|
||||
preDistPhases=${preDistPhases/setuptoolsCheckPhase/}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# Setup hook for detecting conflicts in Python packages
|
||||
echo "Sourcing python-catch-conflicts-hook.sh"
|
||||
|
||||
pythonCatchConflictsPhase() {
|
||||
@pythonInterpreter@ @catchConflicts@
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePythonCatchConflicts-}" ]; then
|
||||
preDistPhases+=" pythonCatchConflictsPhase"
|
||||
fi
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# Setup hook for checking whether Python imports succeed
|
||||
echo "Sourcing python-imports-check-hook.sh"
|
||||
|
||||
pythonImportsCheckPhase () {
|
||||
echo "Executing pythonImportsCheckPhase"
|
||||
|
||||
if [ -n "$pythonImportsCheck" ]; then
|
||||
echo "Check whether the following modules can be imported: $pythonImportsCheck"
|
||||
( cd $out && eval "@pythonCheckInterpreter@ -c 'import os; import importlib; list(map(lambda mod: importlib.import_module(mod), os.environ[\"pythonImportsCheck\"].split()))'" )
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePythonImportsCheck-}" ]; then
|
||||
echo "Using pythonImportsCheckPhase"
|
||||
preDistPhases+=" pythonImportsCheckPhase"
|
||||
fi
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
# Clean up __init__.py's found in namespace directories
|
||||
echo "Sourcing python-namespaces-hook"
|
||||
|
||||
pythonNamespacesHook() {
|
||||
echo "Executing pythonNamespacesHook"
|
||||
|
||||
for namespace in ${pythonNamespaces[@]}; do
|
||||
echo "Enforcing PEP420 namespace: ${namespace}"
|
||||
|
||||
# split namespace into segments. "azure.mgmt" -> "azure mgmt"
|
||||
IFS='.' read -ra pathSegments <<< $namespace
|
||||
constructedPath=$out/@pythonSitePackages@
|
||||
|
||||
# Need to remove the __init__.py at each namespace level
|
||||
# E.g `azure/__init__.py` and `azure/mgmt/__init__.py`
|
||||
# The __pycache__ entry also needs to be removed
|
||||
for pathSegment in ${pathSegments[@]}; do
|
||||
constructedPath=${constructedPath}/${pathSegment}
|
||||
pathToRemove=${constructedPath}/__init__.py
|
||||
pycachePath=${constructedPath}/__pycache__/
|
||||
|
||||
# remove __init__.py
|
||||
if [ -f "$pathToRemove" ]; then
|
||||
rm -v "$pathToRemove"
|
||||
fi
|
||||
|
||||
# remove ${pname}-${version}-${python-interpeter}-nspkg.pth
|
||||
#
|
||||
# Still need to check that parent directory exists in the
|
||||
# event of a "meta-package" package, which will just install
|
||||
# other packages, but not produce anything in site-packages
|
||||
# besides meta information
|
||||
if [ -d "${constructedPath}/../" -a -z ${dontRemovePth-} ]; then
|
||||
# .pth files are located in the parent directory of a module
|
||||
@findutils@/bin/find ${constructedPath}/../ -name '*-nspkg.pth' -exec rm -v "{}" +
|
||||
fi
|
||||
|
||||
# remove __pycache__/ entry, can be interpreter specific. E.g. __init__.cpython-38.pyc
|
||||
# use null characters to perserve potential whitespace in filepath
|
||||
if [ -d "$pycachePath" ]; then
|
||||
@findutils@/bin/find "$pycachePath" -name '__init__*' -exec rm -v "{}" +
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "Finished executing pythonNamespacesHook"
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then
|
||||
postFixupHooks+=(pythonNamespacesHook)
|
||||
fi
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# Setup hook for recompiling bytecode.
|
||||
# https://github.com/NixOS/nixpkgs/issues/81441
|
||||
echo "Sourcing python-recompile-bytecode-hook.sh"
|
||||
|
||||
# Remove all bytecode from the $out output. Then, recompile only site packages folder
|
||||
# Note this effectively duplicates `python-remove-bin-bytecode`, but long-term
|
||||
# this hook should be removed again.
|
||||
|
||||
pythonRecompileBytecodePhase () {
|
||||
# TODO: consider other outputs than $out
|
||||
|
||||
items="$(find "$out" -name "@bytecodeName@")"
|
||||
if [[ -n $items ]]; then
|
||||
for pycache in $items; do
|
||||
rm -rf "$pycache"
|
||||
done
|
||||
fi
|
||||
|
||||
find "$out"/@pythonSitePackages@ -name "*.py" -exec @pythonInterpreter@ -OO -m compileall @compileArgs@ {} +
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePythonRecompileBytecode-}" ]; then
|
||||
postPhases+=" pythonRecompileBytecodePhase"
|
||||
fi
|
||||
|
|
@ -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"
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# Setup hook for removing bytecode from the bin folder
|
||||
echo "Sourcing python-remove-bin-bytecode-hook.sh"
|
||||
|
||||
# The bin folder is added to $PATH and should only contain executables.
|
||||
# It may happen there are executables with a .py extension for which
|
||||
# bytecode is generated. This hook removes that bytecode.
|
||||
|
||||
pythonRemoveBinBytecodePhase () {
|
||||
if [ -d "$out/bin" ]; then
|
||||
rm -rf "$out/bin/__pycache__" # Python 3
|
||||
find "$out/bin" -type f -name "*.pyc" -delete # Python 2
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePythonRemoveBinBytecode-}" ]; then
|
||||
preDistPhases+=" pythonRemoveBinBytecodePhase"
|
||||
fi
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# Clean up top-level tests directory in site-package installation.
|
||||
echo "Sourcing python-remove-tests-dir-hook"
|
||||
|
||||
pythonRemoveTestsDir() {
|
||||
echo "Executing pythonRemoveTestsDir"
|
||||
|
||||
rm -rf $out/@pythonSitePackages@/tests
|
||||
rm -rf $out/@pythonSitePackages@/test
|
||||
|
||||
echo "Finished executing pythonRemoveTestsDir"
|
||||
}
|
||||
|
||||
if [ -z "${dontUsePythonRemoveTestsDir-}" ]; then
|
||||
postFixupHooks+=(pythonRemoveTestsDir)
|
||||
fi
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
# Setup hook for setuptools.
|
||||
echo "Sourcing setuptools-build-hook"
|
||||
|
||||
setuptoolsBuildPhase() {
|
||||
echo "Executing setuptoolsBuildPhase"
|
||||
local args
|
||||
runHook preBuild
|
||||
|
||||
cp -f @setuppy@ nix_run_setup
|
||||
args=""
|
||||
if [ -n "$setupPyGlobalFlags" ]; then
|
||||
args+="$setupPyGlobalFlags"
|
||||
fi
|
||||
if [ -n "$enableParallelBuilding" ]; then
|
||||
setupPyBuildFlags+=" --parallel $NIX_BUILD_CORES"
|
||||
fi
|
||||
if [ -n "$setupPyBuildFlags" ]; then
|
||||
args+=" build_ext $setupPyBuildFlags"
|
||||
fi
|
||||
eval "@pythonInterpreter@ nix_run_setup $args bdist_wheel"
|
||||
|
||||
runHook postBuild
|
||||
echo "Finished executing setuptoolsBuildPhase"
|
||||
}
|
||||
|
||||
setuptoolsShellHook() {
|
||||
echo "Executing setuptoolsShellHook"
|
||||
runHook preShellHook
|
||||
|
||||
if test -e setup.py; then
|
||||
tmp_path=$(mktemp -d)
|
||||
export PATH="$tmp_path/bin:$PATH"
|
||||
export PYTHONPATH="$tmp_path/@pythonSitePackages@:$PYTHONPATH"
|
||||
mkdir -p "$tmp_path/@pythonSitePackages@"
|
||||
eval "@pythonInterpreter@ -m pip install -e . --prefix $tmp_path \
|
||||
--no-build-isolation >&2"
|
||||
|
||||
# Process pth file installed in tmp path. This allows one to
|
||||
# actually import the editable installation. Note site.addsitedir
|
||||
# appends, not prepends, new paths. Hence, it is not possible to override
|
||||
# an existing installation of the package.
|
||||
# https://github.com/pypa/setuptools/issues/2612
|
||||
export NIX_PYTHONPATH="$tmp_path/@pythonSitePackages@:${NIX_PYTHONPATH-}"
|
||||
fi
|
||||
|
||||
runHook postShellHook
|
||||
echo "Finished executing setuptoolsShellHook"
|
||||
}
|
||||
|
||||
if [ -z "${dontUseSetuptoolsBuild-}" ] && [ -z "${buildPhase-}" ]; then
|
||||
echo "Using setuptoolsBuildPhase"
|
||||
buildPhase=setuptoolsBuildPhase
|
||||
fi
|
||||
|
||||
if [ -z "${dontUseSetuptoolsShellHook-}" ] && [ -z "${shellHook-}" ]; then
|
||||
echo "Using setuptoolsShellHook"
|
||||
shellHook=setuptoolsShellHook
|
||||
fi
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
# Setup hook for setuptools.
|
||||
echo "Sourcing setuptools-check-hook"
|
||||
|
||||
setuptoolsCheckPhase() {
|
||||
echo "Executing setuptoolsCheckPhase"
|
||||
runHook preCheck
|
||||
|
||||
cp -f @setuppy@ nix_run_setup
|
||||
@pythonCheckInterpreter@ nix_run_setup test
|
||||
|
||||
runHook postCheck
|
||||
echo "Finished executing setuptoolsCheckPhase"
|
||||
}
|
||||
|
||||
if [ -z "${dontUseSetuptoolsCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
|
||||
echo "Using setuptoolsCheckPhase"
|
||||
preDistPhases+=" setuptoolsCheckPhase"
|
||||
fi
|
||||
57
pkgs/development/interpreters/python/hooks/sphinx-hook.sh
Normal file
57
pkgs/development/interpreters/python/hooks/sphinx-hook.sh
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# This hook automatically finds Sphinx documentation, builds it in html format
|
||||
# and installs it.
|
||||
#
|
||||
# This hook knows about several popular locations in which subdirectory
|
||||
# documentation may be, but in very unusual cases $sphinxRoot directory can be
|
||||
# set explicitly.
|
||||
#
|
||||
# Name of the directory relative to ${doc:-$out}/share/doc is normally also
|
||||
# deduced automatically, but can be overridden with $sphinxOutdir variable.
|
||||
#
|
||||
# Sphinx build system can depend on arbitrary amount of python modules, client
|
||||
# code is responsible for ensuring that all dependencies are present.
|
||||
|
||||
buildSphinxPhase() {
|
||||
local __sphinxRoot="" o
|
||||
|
||||
runHook preBuildSphinx
|
||||
if [[ -n "${sphinxRoot:-}" ]] ; then # explicit root
|
||||
if ! [[ -f "${sphinxRoot}/conf.py" ]] ; then
|
||||
echo 2>&1 "$sphinxRoot/conf.py: no such file"
|
||||
exit 1
|
||||
fi
|
||||
__sphinxRoot=$sphinxRoot
|
||||
else
|
||||
for o in doc docs doc/source docs/source ; do
|
||||
if [[ -f "$o/conf.py" ]] ; then
|
||||
echo "Sphinx documentation found in $o"
|
||||
__sphinxRoot=$o
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -z "${__sphinxRoot}" ]] ; then
|
||||
echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable"
|
||||
exit 1
|
||||
fi
|
||||
sphinx-build -M html "${__sphinxRoot}" ".sphinx/html" -v
|
||||
|
||||
runHook postBuildSphinx
|
||||
}
|
||||
|
||||
installSphinxPhase() {
|
||||
local docdir=""
|
||||
runHook preInstallSphinx
|
||||
|
||||
docdir="${doc:-$out}/share/doc/${sphinxOutdir:-$name}"
|
||||
mkdir -p "$docdir"
|
||||
|
||||
cp -r .sphinx/html/html "$docdir/"
|
||||
rm -fr "${docdir}/html/_sources" "${docdir}/html/.buildinfo"
|
||||
|
||||
runHook postInstallSphinx
|
||||
}
|
||||
|
||||
preBuildPhases+=" buildSphinxPhase"
|
||||
postPhases+=" installSphinxPhase"
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
venvShellHook() {
|
||||
echo "Executing venvHook"
|
||||
runHook preShellHook
|
||||
|
||||
if [ -d "${venvDir}" ]; then
|
||||
echo "Skipping venv creation, '${venvDir}' already exists"
|
||||
source "${venvDir}/bin/activate"
|
||||
else
|
||||
echo "Creating new venv environment in path: '${venvDir}'"
|
||||
@pythonInterpreter@ -m venv "${venvDir}"
|
||||
|
||||
source "${venvDir}/bin/activate"
|
||||
runHook postVenvCreation
|
||||
fi
|
||||
|
||||
runHook postShellHook
|
||||
echo "Finished executing venvShellHook"
|
||||
}
|
||||
|
||||
if [ -z "${dontUseVenvShellHook:-}" ] && [ -z "${shellHook-}" ]; then
|
||||
echo "Using venvShellHook"
|
||||
if [ -z "${venvDir-}" ]; then
|
||||
echo "Error: \`venvDir\` should be set when using \`venvShellHook\`."
|
||||
exit 1
|
||||
else
|
||||
shellHook=venvShellHook
|
||||
fi
|
||||
fi
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue