Making sure that python and pip are the ones we expect

This commit is contained in:
Yannick Jadoul
2020-02-20 00:16:03 +01:00
parent 4f47ab8052
commit 42a231f830
3 changed files with 24 additions and 8 deletions
+16 -8
View File
@@ -63,17 +63,25 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
mkdir /output
cd /project
{environment_exports}
for PYBIN in {pybin_paths}; do (
# Temporary hack/workaround, putting loop body in subshell; fixed in PR #256
export PATH="$PYBIN:$PATH"
{environment_exports}
# check the active python and pip are in PYBIN
# if `test` returns false, the script will exit due to errexit
test "$(which pip)" = "$PYBIN/pip"
test "$(which python)" = "$PYBIN/python"
for PYBIN in {pybin_paths}; do
if [ ! -z {before_build} ]; then
PATH="$PYBIN:$PATH" sh -c {before_build}
sh -c {before_build}
fi
# Build the wheel
rm -rf /tmp/built_wheel
mkdir /tmp/built_wheel
PATH="$PYBIN:$PATH" "$PYBIN/pip" wheel . -w /tmp/built_wheel --no-deps {build_verbosity_flag}
pip wheel . -w /tmp/built_wheel --no-deps {build_verbosity_flag}
built_wheel=(/tmp/built_wheel/*.whl)
# repair the wheel
@@ -92,9 +100,9 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
if [ ! -z {test_command} ]; then
# Set up a virtual environment to install and test from, to make sure
# there are no dependencies that were pulled in at build time.
"$PYBIN/pip" install virtualenv
pip install virtualenv
venv_dir=`mktemp -d`/venv
"$PYBIN/python" -m virtualenv "$venv_dir"
python -m virtualenv "$venv_dir"
# run the tests in a subshell to keep that `activate`
# script from polluting the env
@@ -123,7 +131,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
)
# exit if tests failed (needed for older bash versions)
if [ $? -ne 0 ]; then
exit 1;
exit 1;
fi
# clean up
@@ -133,7 +141,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
# we're all done here; move it to output
mv "${{repaired_wheels[@]}}" /output
for repaired_wheel in "${{repaired_wheels[@]}}"; do chown {uid}:{gid} "/output/$(basename "$repaired_wheel")"; done
done
) done
'''.format(
pybin_paths=' '.join(c.path + '/bin' for c in platform_configs),
test_requires=' '.join(test_requires),