pythonPackages.venvShellHook: init

This is a hook that loads a virtualenv from the specified `venvDir`
location. If the virtualenv does not exist, it is created.

authored by

Frederik Rietdijk and committed by
Frederik Rietdijk
eba1f794 ece82903

+40 -1
+1
doc/languages-frameworks/python.section.md
··· 833 833 - `pythonRemoveBinBytecode` to remove bytecode from the `/bin` folder. 834 834 - `setuptoolsBuildHook` to build a wheel using `setuptools`. 835 835 - `setuptoolsCheckHook` to run tests with `python setup.py test`. 836 + - `venvShellHook` to source a Python 3 `venv` at the `venvDir` location. A `venv` is created if it does not yet exist. 836 837 - `wheelUnpackHook` to move a wheel to the correct folder so it can be installed with the `pipInstallHook`. 837 838 838 839 ### Development mode
+12
pkgs/development/interpreters/python/hooks/default.nix
··· 2 2 { python 3 3 , callPackage 4 4 , makeSetupHook 5 + , disabledIf 6 + , isPy3k 7 + , ensureNewerSourcesForZipFilesHook 5 8 }: 6 9 7 10 let ··· 108 111 inherit pythonCheckInterpreter setuppy; 109 112 }; 110 113 } ./setuptools-check-hook.sh) {}; 114 + 115 + venvShellHook = disabledIf (!isPy3k) (callPackage ({ }: 116 + makeSetupHook { 117 + name = "venv-shell-hook"; 118 + deps = [ ensureNewerSourcesForZipFilesHook ]; 119 + substitutions = { 120 + inherit pythonInterpreter; 121 + }; 122 + } ./venv-shell-hook.sh) {}); 111 123 112 124 wheelUnpackHook = callPackage ({ wheel }: 113 125 makeSetupHook {
+26
pkgs/development/interpreters/python/hooks/venv-shell-hook.sh
··· 1 + venvShellHook() { 2 + echo "Executing venvHook" 3 + runHook preShellHook 4 + 5 + if [ -d "${venvDir}" ]; then 6 + echo "Skipping venv creation, '${venvDir}' already exists" 7 + else 8 + echo "Creating new venv environment in path: '${venvDir}'" 9 + @pythonInterpreter@ -m venv "${venvDir}" 10 + fi 11 + 12 + source "${venvDir}/bin/activate" 13 + 14 + runHook postShellHook 15 + echo "Finished executing venvShellHook" 16 + } 17 + 18 + if [ -z "${dontUseVenvShellHook:-}" ] && [ -z "${shellHook-}" ]; then 19 + echo "Using venvShellHook" 20 + if [ -z "${venvDir-}" ]; then 21 + echo "Error: \`venvDir\` should be set when using \`venvShellHook\`." 22 + exit 1 23 + else 24 + shellHook=venvShellHook 25 + fi 26 + fi
+1 -1
pkgs/top-level/python-packages.nix
··· 108 108 inherit buildSetupcfg; 109 109 110 110 inherit (callPackage ../development/interpreters/python/hooks { }) 111 - eggUnpackHook eggBuildHook eggInstallHook flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook wheelUnpackHook; 111 + eggUnpackHook eggBuildHook eggInstallHook flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook venvShellHook wheelUnpackHook; 112 112 113 113 # helpers 114 114