Skip to content

Commit 297bbf8

Browse files
committed
cleanup venv handling
1 parent 0182be2 commit 297bbf8

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

05_paraview/venv.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
"""Activate venv for current interpreter:
3+
4+
Use `import venv` along with a `--venv path/to/venv/base`
5+
6+
This can be used when you must use an existing Python interpreter, not the venv bin/python.
7+
"""
18
import os
29
import site
310
import sys
411

512
if "--venv" in sys.argv:
6-
# Code taken from virutal-env::bin/active_this.py
13+
# Code inspired by virutal-env::bin/active_this.py
714
venv_path = sys.argv[sys.argv.index("--venv") + 1]
815
bin_dir = os.path.abspath(os.path.join(venv_path, "bin"))
916
base = bin_dir[: -len("bin") - 1]
1017
os.environ["PATH"] = os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
1118
os.environ["VIRTUAL_ENV"] = base
1219
prev_length = len(sys.path)
1320
python_libs = os.path.join(base, f"lib/python{sys.version_info.major}.{sys.version_info.minor}/site-packages")
14-
path = os.path.realpath(os.path.join(bin_dir, python_libs))
1521
site.addsitedir(python_libs.decode("utf-8") if "" else python_libs)
1622
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
1723
sys.real_prefix = sys.prefix

presentation.pdf

17.9 MB
Binary file not shown.

0 commit comments

Comments
 (0)