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:
Frederik Rietdijk 2020-01-13 21:45:24 +01:00 committed by Frederik Rietdijk
parent ece829033b
commit eba1f79418
4 changed files with 40 additions and 1 deletions

View File

@ -833,6 +833,7 @@ used in `buildPythonPackage`.
- `pythonRemoveBinBytecode` to remove bytecode from the `/bin` folder.
- `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.
- `wheelUnpackHook` to move a wheel to the correct folder so it can be installed with the `pipInstallHook`.
### Development mode

View File

@ -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";

View File

@ -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

View File

@ -108,7 +108,7 @@ in {
inherit buildSetupcfg;
inherit (callPackage ../development/interpreters/python/hooks { })
eggUnpackHook eggBuildHook eggInstallHook flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook wheelUnpackHook;
eggUnpackHook eggBuildHook eggInstallHook flitBuildHook pipBuildHook pipInstallHook pytestCheckHook pythonCatchConflictsHook pythonImportsCheckHook pythonRemoveBinBytecodeHook setuptoolsBuildHook setuptoolsCheckHook venvShellHook wheelUnpackHook;
# helpers