make the "makewheel.py" script independent from the activate_this.py script

The "activate_this.py" script only seems to be included in virtualenv,
but not venv. Now we implement its effect directly.
This commit is contained in:
Axel Kohlmeyer
2022-06-17 00:10:06 -04:00
parent dd3aab0c66
commit 21b3020a97

View File

@ -1,14 +1,26 @@
#!/usr/bin/env python
import sys,os
import sys,os,site
# find python script to activate the virtual environment and source it
base = os.path.abspath('buildwheel')
if sys.platform == 'win32':
virtenv=os.path.join('buildwheel','Scripts','activate_this.py')
bin_dir=os.path.join(base,'Scripts')
else:
virtenv=os.path.join('buildwheel','bin','activate_this.py')
bin_dir=os.path.join(base,'bin')
exec(open(virtenv).read(), {'__file__': virtenv})
# prepend bin to PATH, set venv path
os.environ["PATH"] = os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
os.environ["VIRTUAL_ENV"] = base
# add the virtual environments libraries to the host python import mechanism
prev_length = len(sys.path)
for lib in "__LIB_FOLDERS__".split(os.pathsep):
path = os.path.realpath(os.path.join(bin_dir, lib))
site.addsitedir(path)
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
sys.real_prefix = sys.prefix
sys.prefix = base
# update pip and install all requirements to build the wheel
os.system('python -m pip install --upgrade pip')