buildPython hooks: format with shfmt

This commit is contained in:
Yueh-Shun Li 2024-09-10 23:15:40 +08:00
parent 7ba9e4244b
commit 57c2e5683d
14 changed files with 52 additions and 53 deletions

View File

@ -1,7 +1,7 @@
# Setup hook to use in case a conda binary package is installed
echo "Sourcing conda install hook"
condaInstallPhase(){
condaInstallPhase() {
echo "Executing condaInstallPhase"
runHook preInstall
@ -10,11 +10,11 @@ condaInstallPhase(){
# or multiple top level directories.
siteDir=@pythonSitePackages@
if [ -e ./site-packages ]; then
mkdir -p $out/$siteDir
cp -r ./site-packages/* $out/$siteDir
mkdir -p $out/$siteDir
cp -r ./site-packages/* $out/$siteDir
else
cp -r . $out
rm $out/env-vars
cp -r . $out
rm $out/env-vars
fi
runHook postInstall

View File

@ -1,7 +1,7 @@
# Setup hook to use in case a conda binary package is fetched
echo "Sourcing conda unpack hook"
condaUnpackPhase(){
condaUnpackPhase() {
echo "Executing condaUnpackPhase"
runHook preUnpack

View File

@ -1,13 +1,13 @@
# Setup hook to use in case an egg is fetched
echo "Sourcing egg setup hook"
eggUnpackPhase(){
eggUnpackPhase() {
echo "Executing eggUnpackPhase"
runHook preUnpack
cp "$src" "$(stripHash "$src")"
# runHook postUnpack # Calls find...?
# runHook postUnpack # Calls find...?
echo "Finished executing eggUnpackPhase"
}

View File

@ -10,13 +10,13 @@ pipBuildPhase() {
mkdir -p dist
echo "Creating a wheel..."
@pythonInterpreter@ -m pip wheel \
--verbose \
--no-index \
--no-deps \
--no-clean \
--no-build-isolation \
--wheel-dir dist \
$pipBuildFlags .
--verbose \
--no-index \
--no-deps \
--no-clean \
--no-build-isolation \
--wheel-dir dist \
$pipBuildFlags .
echo "Finished creating a wheel..."
runHook postBuild
@ -29,12 +29,12 @@ pipShellHook() {
# 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
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

View File

@ -5,14 +5,14 @@ pypaInstallPhase() {
echo "Executing pypaInstallPhase"
runHook preInstall
pushd dist > /dev/null
pushd dist >/dev/null
for wheel in *.whl; do
@pythonInterpreter@ -m installer --prefix "$out" "$wheel"
echo "Successfully installed $wheel"
done
popd > /dev/null
popd >/dev/null
export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH"

View File

@ -18,11 +18,11 @@ function _concatSep {
echo "$result"
}
function _pytestComputeDisabledTestsString () {
function _pytestComputeDisabledTestsString() {
declare -a tests
local tests=($1)
local prefix="not "
prefixed=( "${tests[@]/#/$prefix}" )
prefixed=("${tests[@]/#/$prefix}")
result=$(_concatSep "and" prefixed)
echo "$result"
}
@ -35,7 +35,7 @@ function pytestCheckPhase() {
args=" -m pytest"
if [ -n "$disabledTests" ]; then
disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}")
args+=" -k \""$disabledTestsString"\""
args+=" -k \""$disabledTestsString"\""
fi
if [ -n "${disabledTestPaths-}" ]; then
@ -43,11 +43,11 @@ function pytestCheckPhase() {
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\""
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"

View File

@ -1,7 +1,7 @@
# Setup hook for checking whether Python imports succeed
echo "Sourcing python-imports-check-hook.sh"
pythonImportsCheckPhase () {
pythonImportsCheckPhase() {
echo "Executing pythonImportsCheckPhase"
if [ -n "$pythonImportsCheck" ]; then
@ -12,7 +12,7 @@ pythonImportsCheckPhase () {
pythonImportsCheckOutput=$python
fi
export PYTHONPATH="$pythonImportsCheckOutput/@pythonSitePackages@:$PYTHONPATH"
( cd $pythonImportsCheckOutput && eval "@pythonCheckInterpreter@ -c 'import os; import importlib; list(map(lambda mod: importlib.import_module(mod), os.environ[\"pythonImportsCheck\"].split()))'" )
(cd $pythonImportsCheckOutput && @pythonCheckInterpreter@ -c 'import os; import importlib; list(map(lambda mod: importlib.import_module(mod), os.environ["pythonImportsCheck"].split()))')
fi
}

View File

@ -8,7 +8,7 @@ pythonNamespacesHook() {
echo "Enforcing PEP420 namespace: ${namespace}"
# split namespace into segments. "azure.mgmt" -> "azure mgmt"
IFS='.' read -ra pathSegments <<< $namespace
IFS='.' read -ra pathSegments <<<$namespace
constructedPath=$out/@pythonSitePackages@
# Need to remove the __init__.py at each namespace level
@ -49,4 +49,3 @@ pythonNamespacesHook() {
if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then
postFixupHooks+=(pythonNamespacesHook)
fi

View File

@ -6,7 +6,7 @@ echo "Sourcing python-recompile-bytecode-hook.sh"
# Note this effectively duplicates `python-remove-bin-bytecode`, but long-term
# this hook should be removed again.
pythonRecompileBytecodePhase () {
pythonRecompileBytecodePhase() {
# TODO: consider other outputs than $out
items="$(find "$out" -name "@bytecodeName@")"

View File

@ -89,7 +89,7 @@ pythonRelaxDepsHook() {
_pythonRelaxDeps $metadata_file
_pythonRemoveDeps $metadata_file
if (( "${NIX_DEBUG:-0}" >= 1 )); then
if (("${NIX_DEBUG:-0}" >= 1)); then
echo "pythonRelaxDepsHook: resulting METADATA for '$wheel':"
cat $metadata_file
fi

View File

@ -5,10 +5,10 @@ echo "Sourcing python-remove-bin-bytecode-hook.sh"
# It may happen there are executables with a .py extension for which
# bytecode is generated. This hook removes that bytecode.
pythonRemoveBinBytecodePhase () {
pythonRemoveBinBytecodePhase() {
if [ -d "$out/bin" ]; then
rm -rf "$out/bin/__pycache__" # Python 3
find "$out/bin" -type f -name "*.pyc" -delete # Python 2
rm -rf "$out/bin/__pycache__" # Python 3
find "$out/bin" -type f -name "*.pyc" -delete # Python 2
fi
}

View File

@ -9,15 +9,15 @@ buildSphinxPhase() {
local __sphinxRoot=""
runHook preBuildSphinx
if [[ -n "${sphinxRoot:-}" ]] ; then # explicit root
if ! [[ -f "${sphinxRoot}/conf.py" ]] ; then
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 candidate in doc docs doc/source docs/source ; do
if [[ -f "$candidate/conf.py" ]] ; then
for candidate in doc docs doc/source docs/source; do
if [[ -f "$candidate/conf.py" ]]; then
echo "Sphinx documentation found in $candidate"
__sphinxRoot=$candidate
break
@ -25,7 +25,7 @@ buildSphinxPhase() {
done
fi
if [[ -z "${__sphinxRoot}" ]] ; then
if [[ -z "${__sphinxRoot}" ]]; then
echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable"
exit 1
fi

View File

@ -3,14 +3,14 @@ venvShellHook() {
runHook preShellHook
if [ -d "${venvDir}" ]; then
echo "Skipping venv creation, '${venvDir}' already exists"
source "${venvDir}/bin/activate"
echo "Skipping venv creation, '${venvDir}' already exists"
source "${venvDir}/bin/activate"
else
echo "Creating new venv environment in path: '${venvDir}'"
@pythonInterpreter@ -m venv "${venvDir}"
echo "Creating new venv environment in path: '${venvDir}'"
@pythonInterpreter@ -m venv "${venvDir}"
source "${venvDir}/bin/activate"
runHook postVenvCreation
source "${venvDir}/bin/activate"
runHook postVenvCreation
fi
runHook postShellHook

View File

@ -1,14 +1,14 @@
# Setup hook to use in case a wheel is fetched
echo "Sourcing wheel setup hook"
wheelUnpackPhase(){
wheelUnpackPhase() {
echo "Executing wheelUnpackPhase"
runHook preUnpack
mkdir -p dist
cp "$src" "dist/$(stripHash "$src")"
# runHook postUnpack # Calls find...?
# runHook postUnpack # Calls find...?
echo "Finished executing wheelUnpackPhase"
}