forked from mirrors/nixpkgs
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:
parent
ece829033b
commit
eba1f79418
|
@ -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…
Reference in a new issue