Skip to content

Commit

Permalink
treefmt: Enable shfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Sep 25, 2024
1 parent ecaac48 commit 9fa419c
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 89 deletions.
18 changes: 9 additions & 9 deletions build/hooks/pyproject-bootstrap-build-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
echo "Sourcing pyproject-build-hook"

pyprojectBuildPhase() {
echo "Executing pyprojectBuildPhase"
runHook preBuild
echo "Executing pyprojectBuildPhase"
runHook preBuild

echo "Creating a wheel..."
@build@/bin/pyproject-build --no-isolation --outdir dist/ --wheel $pyprojectBuildFlags
echo "Finished creating a wheel..."
echo "Creating a wheel..."
@build@/bin/pyproject-build --no-isolation --outdir dist/ --wheel $pyprojectBuildFlags
echo "Finished creating a wheel..."

runHook postBuild
echo "Finished executing pyprojectBuildPhase"
runHook postBuild
echo "Finished executing pyprojectBuildPhase"
}

if [ -z "${dontUsePyprojectBuild-}" ] && [ -z "${buildPhase-}" ]; then
echo "Using pyprojectBuildPhase"
buildPhase=pyprojectBuildPhase
echo "Using pyprojectBuildPhase"
buildPhase=pyprojectBuildPhase
fi
16 changes: 8 additions & 8 deletions build/hooks/pyproject-build-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
echo "Sourcing pyproject-build-hook"

pyprojectBuildPhase() {
echo "Executing pyprojectBuildPhase"
runHook preBuild
echo "Executing pyprojectBuildPhase"
runHook preBuild

echo "Creating a wheel..."
env PYTHONPATH="${NIX_PYPROJECT_PYTHONPATH}:${PYTHONPATH}" @build@/bin/pyproject-build --no-isolation --outdir dist/ --wheel $pypaBuildFlags
echo "Creating a wheel..."
env PYTHONPATH="${NIX_PYPROJECT_PYTHONPATH}:${PYTHONPATH}" @build@/bin/pyproject-build --no-isolation --outdir dist/ --wheel $pypaBuildFlags

runHook postBuild
echo "Finished executing pyprojectBuildPhase"
runHook postBuild
echo "Finished executing pyprojectBuildPhase"
}

if [ -z "${dontUsePyprojectBuild-}" ] && [ -z "${buildPhase-}" ]; then
echo "Using pyprojectBuildPhase"
buildPhase=pyprojectBuildPhase
echo "Using pyprojectBuildPhase"
buildPhase=pyprojectBuildPhase
fi
26 changes: 13 additions & 13 deletions build/hooks/pyproject-bytecode-hook.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
pyprojectBytecodePhase () {
if [ -d "$out/bin" ]; then
rm -rf "$out/bin/__pycache__" # Python 3
find "$out/bin" -type f -name "*.pyc" -delete # Python 2
fi
pyprojectBytecodePhase() {
if [ -d "$out/bin" ]; then
rm -rf "$out/bin/__pycache__" # Python 3
find "$out/bin" -type f -name "*.pyc" -delete # Python 2
fi

items="$(find "$out" -name "@bytecodeName@")"
if [[ -n $items ]]; then
for pycache in $items; do
rm -rf "$pycache"
done
fi
items="$(find "$out" -name "@bytecodeName@")"
if [[ -n $items ]]; then
for pycache in $items; do
rm -rf "$pycache"
done
fi

@pythonInterpreter@ -OO -m compileall @compileArgs@ "$out"/@pythonSitePackages@
@pythonInterpreter@ -OO -m compileall @compileArgs@ "$out"/@pythonSitePackages@
}

if [ -z "${dontUsePyprojectBytecode-}" ]; then
postPhases+=" pyprojectBytecodePhase"
postPhases+=" pyprojectBytecodePhase"
fi
24 changes: 12 additions & 12 deletions build/hooks/pyproject-configure-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
echo "Sourcing pyproject-configure-hook"

pyprojectConfigurePhase() {
echo "Executing pyprojectConfigurePhase"
runHook preConfigure
echo "Executing pyprojectConfigurePhase"
runHook preConfigure

# Undo any Python dependency propagation leaking into build, and set it to our interpreters PYTHONPATH
#
# In case of cross compilation this variable will contain two entries:
# One for the native Python and one for the cross built, so the native can load sysconfig
# information from the cross compiled Python.
export PYTHONPATH=@pythonPath@
# Undo any Python dependency propagation leaking into build, and set it to our interpreters PYTHONPATH
#
# In case of cross compilation this variable will contain two entries:
# One for the native Python and one for the cross built, so the native can load sysconfig
# information from the cross compiled Python.
export PYTHONPATH=@pythonPath@

runHook postConfigure
echo "Finished executing pyprojectConfigurePhase"
runHook postConfigure
echo "Finished executing pyprojectConfigurePhase"
}

if [ -z "${dontUsePyprojectConfigure-}" ] && [ -z "${configurePhase-}" ]; then
echo "Using pyprojectConfiguredPhase"
configurePhase=pyprojectConfigurePhase
echo "Using pyprojectConfiguredPhase"
configurePhase=pyprojectConfigurePhase
fi
26 changes: 13 additions & 13 deletions build/hooks/pyproject-install-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
echo "Sourcing pyproject-install-hook"

pyprojectInstallPhase() {
echo "Executing pyprojectInstallPhase"
runHook preInstall
echo "Executing pyprojectInstallPhase"
runHook preInstall

pushd dist > /dev/null
pushd dist >/dev/null

for wheel in ./*.whl; do
@uv@/bin/uv pip --offline --no-cache install --no-deps --link-mode=copy --system --prefix "$out" $uvPipInstallFlags "$wheel"
echo "Successfully installed $wheel"
done
for wheel in ./*.whl; do
@uv@/bin/uv pip --offline --no-cache install --no-deps --link-mode=copy --system --prefix "$out" $uvPipInstallFlags "$wheel"
echo "Successfully installed $wheel"
done

rm -f "$out/.lock"
rm -f "$out/.lock"

popd > /dev/null
popd >/dev/null

runHook postInstall
echo "Finished executing pyprojectInstallPhase"
runHook postInstall
echo "Finished executing pyprojectInstallPhase"
}

if [ -z "${dontUsePyprojectInstall-}" ] && [ -z "${installPhase-}" ]; then
echo "Using pyprojectInstallPhase"
installPhase=pyprojectInstallPhase
echo "Using pyprojectInstallPhase"
installPhase=pyprojectInstallPhase
fi
14 changes: 7 additions & 7 deletions build/hooks/pyproject-make-venv-hook.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
echo "Sourcing pyproject-make-venv-hook"

pyprojectMakeVenv() {
echo "Executing pyprojectMakeVenv"
runHook preInstall
echo "Executing pyprojectMakeVenv"
runHook preInstall

@pythonInterpreter@ @makeVenvScript@ --python @python@ "$out" --env "NIX_PYPROJECT_DEPS"
@pythonInterpreter@ @makeVenvScript@ --python @python@ "$out" --env "NIX_PYPROJECT_DEPS"

runHook postInstall
echo "Finished executing pyprojectMakeVenv"
runHook postInstall
echo "Finished executing pyprojectMakeVenv"
}

if [ -z "${dontUsePyprojectMakeVenv-}" ] && [ -z "${installPhase-}" ]; then
echo "Using pyprojectMakeVenv"
installPhase=pyprojectMakeVenv
echo "Using pyprojectMakeVenv"
installPhase=pyprojectMakeVenv
fi
8 changes: 4 additions & 4 deletions build/hooks/pyproject-output-setup-hook.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pyprojectOutputSetupHook () {
mkdir -p $out/nix-support
cat >> $out/nix-support/setup-hook << EOF
pyprojectOutputSetupHook() {
mkdir -p $out/nix-support
cat >>$out/nix-support/setup-hook <<EOF
# Add Python dependency to search path for discovery by build
addToSearchPath NIX_PYPROJECT_DEPS "$out"
addToSearchPath NIX_PYPROJECT_PYTHONPATH "$out/@pythonSitePackages@"
EOF
}

if [ -z "${dontUsePyprojectOutputSetupHook-}" ]; then
postPhases+=" pyprojectOutputSetupHook"
postPhases+=" pyprojectOutputSetupHook"
fi
26 changes: 13 additions & 13 deletions build/hooks/pyproject-pypa-install-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
echo "Sourcing pyproject-pypa-install-hook"

pyprojectPypaInstallPhase() {
echo "Executing pyprojectPypaInstallPhase"
runHook preInstall
echo "Executing pyprojectPypaInstallPhase"
runHook preInstall

pushd dist > /dev/null
pushd dist >/dev/null

for wheel in *.whl; do
env PYTHONPATH=$PYTHONPATH:@installer@/@pythonSitePackages@ @pythonInterpreter@ -m installer --prefix "$out" "$wheel"
echo "Successfully installed $wheel"
done
for wheel in *.whl; do
env PYTHONPATH=$PYTHONPATH:@installer@/@pythonSitePackages@ @pythonInterpreter@ -m installer --prefix "$out" "$wheel"
echo "Successfully installed $wheel"
done

rm -f "$out/.lock"
rm -f "$out/.lock"

popd > /dev/null
popd >/dev/null

runHook postInstall
echo "Finished executing pyprojectPypaInstallPhase"
runHook postInstall
echo "Finished executing pyprojectPypaInstallPhase"
}

if [ -z "${dontUsePyprojectInstall-}" ] && [ -z "${installPhase-}" ]; then
echo "Using pyprojectPypaInstallPhase"
installPhase=pyprojectPypaInstallPhase
echo "Using pyprojectPypaInstallPhase"
installPhase=pyprojectPypaInstallPhase
fi
20 changes: 10 additions & 10 deletions build/hooks/pyproject-wheel-dist-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
echo "Sourcing pyproject-wheel-dist-hook"

pyprojectWheelDist() {
echo "Executing pyprojectWheelDist"
runHook preBuild
echo "Executing pyprojectWheelDist"
runHook preBuild

echo "Creating dist..."
mkdir -p dist
ln -s "$src" "dist/$(stripHash "$src")"
echo "Creating dist..."
mkdir -p dist
ln -s "$src" "dist/$(stripHash "$src")"

runHook postBuild
echo "Finished executing pyprojectWheelDist"
runHook postBuild
echo "Finished executing pyprojectWheelDist"
}

if [ -z "${dontUsePyprojectWheelDist-}" ] && [ -z "${buildPhase-}" ]; then
echo "Using pyprojectWheelDist"
buildPhase=pyprojectWheelDist
dontUnpack=1
echo "Using pyprojectWheelDist"
buildPhase=pyprojectWheelDist
dontUnpack=1
fi
3 changes: 3 additions & 0 deletions dev/treefmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ _: {
programs.ruff-format.enable = true;
programs.ruff-check.enable = true;
programs.mypy.enable = true;

# Shell
programs.shfmt.enable = true;
}

0 comments on commit 9fa419c

Please sign in to comment.