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.
This commit is contained in:
committed by
Frederik Rietdijk
parent
ece829033b
commit
eba1f79418
@@ -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";
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user