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

Support custom VIRTUAL_ENV for layout_python #876

Merged
merged 9 commits into from Jun 15, 2022
7 changes: 7 additions & 0 deletions .github/workflows/go.yml
Expand Up @@ -25,6 +25,13 @@ jobs:
go-version: 1.16
id: go

- name: Set up Python
if: runner.os != 'Windows'
uses: actions/setup-python@v4.0.0
with:
python-version: "3.9"
id: python

- name: Check out code into the Go module directory
uses: actions/checkout@v3.0.2

Expand Down
17 changes: 13 additions & 4 deletions stdlib.sh
Expand Up @@ -789,9 +789,10 @@ layout_php() {

# Usage: layout python <python_exe>
#
# Creates and loads a virtual environment under
# Creates and loads a virtual environment.
# You can specify the path of the virtual environment through VIRTUAL_ENV
# environment variable, otherwise it will be set to
# "$direnv_layout_dir/python-$python_version".
# This forces the installation of any egg into the project's sub-folder.
# For python older then 3.3 this requires virtualenv to be installed.
#
# It's possible to specify the python executable if you want to use different
Expand All @@ -814,7 +815,13 @@ layout_python() {
return 1
fi

VIRTUAL_ENV=$(direnv_layout_dir)/python-$python_version
if [[ -n $VIRTUAL_ENV ]]; then
zimbatm marked this conversation as resolved.
Show resolved Hide resolved
local REPLY
realpath.absolute "$VIRTUAL_ENV"
VIRTUAL_ENV=$REPLY
else
VIRTUAL_ENV=$(direnv_layout_dir)/python-$python_version
fi
case $ve in
"venv")
if [[ ! -d $VIRTUAL_ENV ]]; then
Expand Down Expand Up @@ -946,7 +953,9 @@ layout_pipenv() {
#
# layout pyenv 3.6.7
#
# Uses pyenv and layout_python to create and load a virtual environment under
# Uses pyenv and layout_python to create and load a virtual environment.
# You can specify the path of the virtual environment through VIRTUAL_ENV
# environment variable, otherwise it will be set to
# "$direnv_layout_dir/python-$python_version".
#
layout_pyenv() {
Expand Down
24 changes: 24 additions & 0 deletions test/direnv-test-common.sh
Expand Up @@ -247,6 +247,30 @@ test_start "skip-env"
test -z "${SKIPPED}"
test_stop

if has python; then
test_start "python-layout"
rm -rf .direnv

direnv_eval
test -n "${VIRTUAL_ENV:-}"

if [[ ":$PATH:" != *":${VIRTUAL_ENV}/bin:"* ]]; then
echo "FAILED: VIRTUAL_ENV/bin not added to PATH"
exit 1
fi
test_stop

test_start "python-custom-virtual-env"
direnv_eval
test "${VIRTUAL_ENV:-}" -ef ./foo

if [[ ":$PATH:" != *":${PWD}/foo/bin:"* ]]; then
echo "FAILED: VIRTUAL_ENV/bin not added to PATH"
exit 1
fi
test_stop
fi

test_start "aliases"
direnv deny
# check that allow/deny aliases work
Expand Down
2 changes: 2 additions & 0 deletions test/scenarios/python-custom-virtual-env/.envrc
@@ -0,0 +1,2 @@
export VIRTUAL_ENV=foo
layout python
Empty file.
1 change: 1 addition & 0 deletions test/scenarios/python-layout/.envrc
@@ -0,0 +1 @@
layout python