Skip to content

Commit

Permalink
Merge pull request #16663 from mppf/fix-venv
Browse files Browse the repository at this point in the history
Replace symbolic link python3 in venv with wrapper

Follow-up to PRs #16644 and #16560.

This PR is intended to solve problems where this warning is reported in some nightly testing configurations:
```
[Warning: could not import filelock]
```

The venv normally includes in some-venv/bin/python3 a symbolic link to
the real python3 interpreter used.

This has the drawback that when distributing the venv, the relevant
python executable might be in a different place.

So, this commit adds a bash script that runs python while telling it to
think it is being launched from that location (that is what the exec -a
here does). The wrapper uses whichever python3 is available in the
system. This allows the python3 being run to change (e.g. if the venv is
used on a system with a different path to the python3).

This approach replaces the approach from PR #3571.

Reviewed by @ronawho - thanks!

- [x] checked basic module build on an XC
- [x] full local testing
  • Loading branch information
mppf committed Nov 4, 2020
2 parents 3f39199 + 454ceaf commit 5b68005
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 117 deletions.
2 changes: 0 additions & 2 deletions Makefile.devel
Expand Up @@ -18,8 +18,6 @@

export CHPL_MAKE_PYTHON := $(shell $(CHPL_MAKE_HOME)/util/config/find-python.sh)

PYTHON_VERSION_DIR = py$(shell $(CHPL_MAKE_PYTHON) $(CHPL_MAKE_HOME)/util/chplenv/chpl_python_version.py)

develall:
@$(MAKE) always-build-man
@$(MAKE) always-build-chplspell-venv
Expand Down
4 changes: 3 additions & 1 deletion third-party/chpl-venv/Makefile
Expand Up @@ -77,6 +77,8 @@ $(CHPL_VENV_VIRTUALENV_DIR):
export VIRTUAL_ENV=$(CHPL_VENV_VIRTUALENV_DIR) && \
$(PIP) install \
--upgrade $(CHPL_PIP_INSTALL_PARAMS) $(LOCAL_PIP_FLAGS) wheel && \
rm $(CHPL_VENV_VIRTUALENV_BIN)/python3
cp python3-wrapper $(CHPL_VENV_VIRTUALENV_BIN)/python3
touch $(CHPL_VENV_VIRTUALENV_DIR)

# Phony convenience target for creating virtualenv.
Expand Down Expand Up @@ -153,7 +155,7 @@ rm-chplspell-reqs: FORCE
# Python installation (ie, the Python used was not installed under "/usr/...").
# Only applicable when building a Cray Chapel module under certain conditions.
use-system-python: FORCE
@$(PYTHON) ./venv-use-sys-python.py $(CHPL_VENV_INSTALL_DIR)
@echo ignoring use-system-python

FORCE:

Expand Down
13 changes: 13 additions & 0 deletions third-party/chpl-venv/python3-wrapper
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Remove the directory containing this script from the path
# (here we just replace chpl-venv with missing since we know
# chpl-venv is always part of the PATH component to this script)

# This is to avoid an infinite loop running this script over and over.
export PATH=${PATH//chpl-venv/missing}

# Now run the real python3 interpreter but tell it that it
# is being launched at the current path, so it can
# correctly find dependencies in the venv
exec -a "$0" python3 "$@"
114 changes: 0 additions & 114 deletions third-party/chpl-venv/venv-use-sys-python.py

This file was deleted.

0 comments on commit 5b68005

Please sign in to comment.