Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to use a virtualenv as own python #5661

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
# 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]

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 [ -n "$VIRTUAL_ENV" ]; then
echo "alibuild_system_replace: virtualenv"
adriansev marked this conversation as resolved.
Show resolved Hide resolved
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]

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"/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
41 changes: 41 additions & 0 deletions xjalienfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,47 @@
- alibuild-recipe-tools
prepend_path:
PYTHONPATH: ${XJALIENFS_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 17 in xjalienfs.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]

Check notice on line 17 in xjalienfs.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 19 in xjalienfs.sh

View workflow job for this annotation

GitHub Actions / alidistlint

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

Check notice on line 19 in xjalienfs.sh

View workflow job for this annotation

GitHub Actions / alidistlint

Double quote to prevent globbing and word splitting. [SC2086]

Check notice on line 19 in xjalienfs.sh

View workflow job for this annotation

GitHub Actions / alidistlint

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

Check notice on line 19 in xjalienfs.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:
recipe: |
#!/bin/bash -e

# Use pip's --target to install under $INSTALLROOT without weird hacks. This
# works inside and outside a virtualenv, but unset VIRTUAL_ENV to make sure we
# only depend on stuff we installed using our Python and Python-modules.

# on macos try to install gnureadline and just skip if fails (alienpy can work without it)
# macos python readline implementation is build on libedit which does not work
[[ "$ARCHITECTURE" == osx_* ]] && { \
python3 -m pip install --force-reinstall \
gnureadline || : ; }

env ALIBUILD=1 \
python3 -m pip install --force-reinstall \
"file://$SOURCEDIR/../$PKG_VERSION"
# 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:
- XRootD
- AliEn-Runtime
build_requires:
- alibuild-recipe-tools
---
#!/bin/bash -e

Expand Down
Loading