1# Setup hook to use for pip projects
2# shellcheck shell=bash
3
4echo "Sourcing pip-build-hook"
5
6pipBuildPhase() {
7 echo "Executing pipBuildPhase"
8 runHook preBuild
9
10 mkdir -p dist
11
12 local -a flagsArray=(
13 --verbose
14 --no-index
15 --no-deps
16 --no-clean
17 --no-build-isolation
18 --wheel-dir dist
19 )
20 concatTo flagsArray pipBuildFlags
21
22 echo "Creating a wheel..."
23 echoCmd 'pip build flags' "${flagsArray[@]}"
24 @pythonInterpreter@ -m pip wheel "${flagsArray[@]}" .
25 echo "Finished creating a wheel..."
26
27 runHook postBuild
28 echo "Finished executing pipBuildPhase"
29}
30
31pipShellHook() {
32 echo "Executing pipShellHook"
33 runHook preShellHook
34
35 # Long-term setup.py should be dropped.
36 if [ -e pyproject.toml ]; then
37 tmp_path=$(mktemp -d)
38 export PATH="$tmp_path/bin:$PATH"
39 export PYTHONPATH="$tmp_path/@pythonSitePackages@:$PYTHONPATH"
40 mkdir -p "$tmp_path/@pythonSitePackages@"
41 @pythonInterpreter@ -m pip install -e . --prefix "$tmp_path" \
42 --no-build-isolation >&2
43 fi
44
45 runHook postShellHook
46 echo "Finished executing pipShellHook"
47}
48
49if [ -z "${dontUsePipBuild-}" ] && [ -z "${buildPhase-}" ]; then
50 echo "Using pipBuildPhase"
51 buildPhase=pipBuildPhase
52fi
53
54if [ -z "${shellHook-}" ]; then
55 echo "Using pipShellHook"
56 shellHook=pipShellHook
57fi