File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ """
18import os
29import site
310import sys
411
512if "--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
You can’t perform that action at this time.
0 commit comments