diff options
Diffstat (limited to 'pkgs/development/interpreters/python/hooks')
-rw-r--r-- | pkgs/development/interpreters/python/hooks/default.nix | 12 | ||||
-rw-r--r-- | pkgs/development/interpreters/python/hooks/venv-shell-hook.sh | 26 |
2 files changed, 38 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index f05b3b1eec63..159637ae9d5f 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -2,6 +2,9 @@ { python , callPackage , makeSetupHook +, disabledIf +, isPy3k +, ensureNewerSourcesForZipFilesHook }: let @@ -109,6 +112,15 @@ in rec { }; } ./setuptools-check-hook.sh) {}; + venvShellHook = disabledIf (!isPy3k) (callPackage ({ }: + makeSetupHook { + name = "venv-shell-hook"; + deps = [ ensureNewerSourcesForZipFilesHook ]; + substitutions = { + inherit pythonInterpreter; + }; + } ./venv-shell-hook.sh) {}); + wheelUnpackHook = callPackage ({ wheel }: makeSetupHook { name = "wheel-unpack-hook.sh"; diff --git a/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh b/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh new file mode 100644 index 000000000000..3185b1f9fae9 --- /dev/null +++ b/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh @@ -0,0 +1,26 @@ +venvShellHook() { + echo "Executing venvHook" + runHook preShellHook + + if [ -d "${venvDir}" ]; then + echo "Skipping venv creation, '${venvDir}' already exists" + else + echo "Creating new venv environment in path: '${venvDir}'" + @pythonInterpreter@ -m venv "${venvDir}" + fi + + source "${venvDir}/bin/activate" + + runHook postShellHook + echo "Finished executing venvShellHook" +} + +if [ -z "${dontUseVenvShellHook:-}" ] && [ -z "${shellHook-}" ]; then + echo "Using venvShellHook" + if [ -z "${venvDir-}" ]; then + echo "Error: \`venvDir\` should be set when using \`venvShellHook\`." + exit 1 + else + shellHook=venvShellHook + fi +fi |