From 15b3d9d2773b6ff919b324d756e23f0f8bf9fc3f Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 16 May 2020 00:34:11 -0700 Subject: [PATCH] python3Packages.venvShellHook: add postVenvCreation (#87850) * python3Packages.venvShellHook: add postVenvCreation * python: docs: add postVenvCreation explaination --- doc/languages-frameworks/python.section.md | 12 ++++++++++-- .../interpreters/python/hooks/venv-shell-hook.sh | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 35ea480e6b94..838426afa04f 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -1023,7 +1023,8 @@ are used in `buildPythonPackage`. - `setuptoolsBuildHook` to build a wheel using `setuptools`. - `setuptoolsCheckHook` to run tests with `python setup.py test`. - `venvShellHook` to source a Python 3 `venv` at the `venvDir` location. A - `venv` is created if it does not yet exist. + `venv` is created if it does not yet exist. `postVenvCreation` can be used to + to run commands only after venv is first created. - `wheelUnpackHook` to move a wheel to the correct folder so it can be installed with the `pipInstallHook`. @@ -1291,10 +1292,17 @@ in pkgs.mkShell rec { zlib ]; + # Run this command, only after creating the virtual environment + postVenvCreation = '' + unset SOURCE_DATE_EPOCH + pip install -r requirements.txt + ''; + # Now we can execute any commands within the virtual environment. # This is optional and can be left out to run pip manually. postShellHook = '' - pip install -r requirements.txt + # allow pip to install wheels + unset SOURCE_DATE_EPOCH ''; } diff --git a/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh b/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh index 3185b1f9fae9..1fcc0bbd4b13 100644 --- a/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh +++ b/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh @@ -4,12 +4,14 @@ venvShellHook() { if [ -d "${venvDir}" ]; then echo "Skipping venv creation, '${venvDir}' already exists" + source "${venvDir}/bin/activate" else echo "Creating new venv environment in path: '${venvDir}'" @pythonInterpreter@ -m venv "${venvDir}" - fi - source "${venvDir}/bin/activate" + source "${venvDir}/bin/activate" + runHook postVenvCreation + fi runHook postShellHook echo "Finished executing venvShellHook"