1{
2 lib,
3 buildPythonPackage,
4 fetchPypi,
5 pbr,
6 pip,
7 pkgs,
8 stevedore,
9 virtualenv,
10 virtualenv-clone,
11 python,
12 setuptools,
13 setuptools-scm,
14}:
15
16buildPythonPackage rec {
17 pname = "virtualenvwrapper";
18 version = "6.1.1";
19 pyproject = true;
20
21 src = fetchPypi {
22 inherit pname version;
23 hash = "sha256-ES5+o0qaPOkKrqVBgvDTr+9NGpE+63XpiiY7SXjNc8Y=";
24 };
25
26 # pip depend on $HOME setting
27 preConfigure = "export HOME=$TMPDIR";
28
29 build-system = [
30 setuptools
31 setuptools-scm
32 ];
33
34 buildInputs = [
35 pbr
36 pip
37 pkgs.which
38 ];
39 propagatedBuildInputs = [
40 stevedore
41 virtualenv
42 virtualenv-clone
43 ];
44
45 postPatch = ''
46 for file in "virtualenvwrapper.sh" "virtualenvwrapper_lazy.sh"; do
47 substituteInPlace "$file" --replace "which" "${pkgs.which}/bin/which"
48
49 # We can't set PYTHONPATH in a normal way (like exporting in a wrapper
50 # script) because the user has to evaluate the script and we don't want
51 # modify the global PYTHONPATH which would affect the user's
52 # environment.
53 # Furthermore it isn't possible to just use VIRTUALENVWRAPPER_PYTHON
54 # for this workaround, because this variable is well quoted inside the
55 # shell script.
56 # (the trailing " -" is required to only replace things like these one:
57 # "$VIRTUALENVWRAPPER_PYTHON" -c "import os,[...] and not in
58 # if-statements or anything like that.
59 # ...and yes, this "patch" is hacky :)
60 substituteInPlace "$file" --replace '"$VIRTUALENVWRAPPER_PYTHON" -' 'env PYTHONPATH="$VIRTUALENVWRAPPER_PYTHONPATH" "$VIRTUALENVWRAPPER_PYTHON" -'
61 done
62 '';
63
64 postInstall = ''
65 # This might look like a dirty hack but we can't use the makeWrapper function because
66 # the wrapped file were then called via "exec". The virtualenvwrapper shell scripts
67 # aren't normal executables. Instead, the user has to evaluate them.
68
69 for file in "virtualenvwrapper.sh" "virtualenvwrapper_lazy.sh"; do
70 local wrapper="$out/bin/$file"
71 local wrapped="$out/bin/.$file-wrapped"
72 mv "$wrapper" "$wrapped"
73
74 # WARNING: Don't indent the lines below because that would break EOF
75 cat > "$wrapper" << EOF
76 export PATH="${python}/bin:\$PATH"
77 export VIRTUALENVWRAPPER_PYTHONPATH="$PYTHONPATH:$(toPythonPath $out)"
78 source "$wrapped"
79 EOF
80
81 chmod -x "$wrapped"
82 chmod +x "$wrapper"
83 done
84 '';
85
86 meta = with lib; {
87 description = "Enhancements to virtualenv";
88 homepage = "https://github.com/python-virtualenvwrapper/virtualenvwrapper";
89 license = licenses.mit;
90 };
91}