Skip to content

Commit

Permalink
Allow users to use a virtualenv as own python
Browse files Browse the repository at this point in the history
Notice that it will still try to install our own provided
packages so that we have a minimum working environment.
  • Loading branch information
ktf committed Oct 15, 2024
1 parent b304682 commit ded0bf7
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions python-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,43 @@ prepend_path:
# If we need tensorflow-metal to work on Mac during subsequent builds, we
# must use lib/python$pyver, not lib/python here.
PYTHONPATH: "$PYTHON_MODULES_ROOT/lib/python/site-packages"
prefer_system: ".*"
prefer_system_check: |
# if we are in a virtualenv, assume people know what they are doing

Check notice on line 18 in python-modules.sh

View workflow job for this annotation

GitHub Actions / alidistlint

Missing script shebang. Use exactly "#!/bin/bash -e" to match aliBuild environment. You may see spurious errors until you fix the shebang. [ali:bad-shebang]
# and simply use the virtualenv recipe.
if [ ! -z $VIRTUAL_ENV ]; then

Check notice on line 20 in python-modules.sh

View workflow job for this annotation

GitHub Actions / alidistlint

Use -n instead of ! -z. [SC2236]

Check notice on line 20 in python-modules.sh

View workflow job for this annotation

GitHub Actions / alidistlint

Double quote to prevent globbing and word splitting. [SC2086]
echo "alibuild_system_replace: virtualenv"
exit 0
fi
# If not, either they are using the system python or they are using our own python.
# In both cases we can simply create our own virtualenv
exit 1
prefer_system_replacement_specs:
virtualenv:
version: "virtualenv"
recipe: |
# Install pinned basic requirements for python infrastructure

Check notice on line 31 in python-modules.sh

View workflow job for this annotation

GitHub Actions / alidistlint

Missing script shebang. Use exactly "#!/bin/bash -e" to match aliBuild environment. You may see spurious errors until you fix the shebang. [ali:bad-shebang]
echo "$PIP_BASE_REQUIREMENTS" > base-requirements.txt
python3 -m pip install -IU -r base-requirements.txt
# The above updates pip and setuptools, so install the rest of the packages separately.
echo "$PIP_REQUIREMENTS" > requirements.txt
python3 -m pip install -IU -r requirements.txt
# We do not need anything else, because python is going to be in path
# if we are inside a virtualenv so no need to pretend we know where
# the correct python is.

# We generate the modulefile to avoid complains by dependencies
mkdir -p "$INSTALLROOT/etc/modulefiles"
alibuild-generate-module --bin > "$INSTALLROOT/etc/modulefiles/$PKGNAME"
requires:
- "FreeType:(?!osx)"
- libpng
- hdf5
build_requires:
- Python-modules-list
- alibuild-recipe-tools
---
#!/bin/bash -e
unset VIRTUAL_ENV

# Users might want to install more packages in the same environment. A venv
# provides a pip binary that will install packages into the same path.
# This copies the system python binary (or the one from PYTHON_ROOT) into the
Expand Down Expand Up @@ -50,9 +83,6 @@ find "$INSTALLROOT" -mindepth 2 -maxdepth 2 \
find "$INSTALLROOT"/bin -type f -exec sed -r -i.deleteme -e "1s,^#!$INSTALLROOT/bin/,#!/usr/bin/env ," {} \;
rm -f "$INSTALLROOT"/bin/*.deleteme

# Link python -> python$pyver, so we can refer to it in PYTHONPATH without knowing pyver.
ln -nsf "python$pyver" "$INSTALLROOT/lib/python"

# Modulefile
mkdir -p "$INSTALLROOT/etc/modulefiles"
alibuild-generate-module --bin > "$INSTALLROOT/etc/modulefiles/$PKGNAME"
Expand Down

0 comments on commit ded0bf7

Please sign in to comment.