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.
wip/yesman
Frederik Rietdijk 4 years ago committed by Frederik Rietdijk
parent ece829033b
commit eba1f79418
  1. 1
      doc/languages-frameworks/python.section.md
  2. 12
      pkgs/development/interpreters/python/hooks/default.nix
  3. 26
      pkgs/development/interpreters/python/hooks/venv-shell-hook.sh
  4. 2
      pkgs/top-level/python-packages.nix

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

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

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

Loading…
Cancel
Save