Skip to content

Commit

Permalink
buildPython hooks: format with shfmt (#347191)
Browse files Browse the repository at this point in the history
  • Loading branch information
natsukium authored Oct 9, 2024
2 parents 054a692 + 57c2e56 commit 8cae045
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 53 deletions.
10 changes: 5 additions & 5 deletions pkgs/development/interpreters/python/hooks/conda-install-hook.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/interpreters/python/hooks/egg-unpack-hook.sh
Original file line number Diff line number Diff line change
@@ -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"
}

Expand Down
26 changes: 13 additions & 13 deletions pkgs/development/interpreters/python/hooks/pip-build-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
16 changes: 8 additions & 8 deletions pkgs/development/interpreters/python/hooks/pytest-check-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -35,19 +35,19 @@ function pytestCheckPhase() {
args=" -m pytest"
if [ -n "$disabledTests" ]; then
disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}")
args+=" -k \""$disabledTestsString"\""
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\""
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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,4 +49,3 @@ pythonNamespacesHook() {
if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then
postFixupHooks+=(pythonNamespacesHook)
fi

Original file line number Diff line number Diff line change
Expand Up @@ -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@")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions pkgs/development/interpreters/python/hooks/sphinx-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ 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
fi
done
fi

if [[ -z "${__sphinxRoot}" ]] ; then
if [[ -z "${__sphinxRoot}" ]]; then
echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable"
exit 1
fi
Expand Down
12 changes: 6 additions & 6 deletions pkgs/development/interpreters/python/hooks/venv-shell-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}

Expand Down

0 comments on commit 8cae045

Please sign in to comment.