init
This commit is contained in:
commit
38355d2442
9083 changed files with 1225834 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
from virtualenv.util.path import Path
|
||||
from virtualenv.util.six import ensure_text
|
||||
|
||||
from ..via_template import ViaTemplateActivator
|
||||
|
||||
|
||||
class PythonActivator(ViaTemplateActivator):
|
||||
def templates(self):
|
||||
yield Path("activate_this.py")
|
||||
|
||||
def replacements(self, creator, dest_folder):
|
||||
replacements = super(PythonActivator, self).replacements(creator, dest_folder)
|
||||
lib_folders = OrderedDict((os.path.relpath(str(i), str(dest_folder)), None) for i in creator.libs)
|
||||
win_py2 = creator.interpreter.platform == "win32" and creator.interpreter.version_info.major == 2
|
||||
replacements.update(
|
||||
{
|
||||
"__LIB_FOLDERS__": ensure_text(os.pathsep.join(lib_folders.keys())),
|
||||
"__DECODE_PATH__": ("yes" if win_py2 else ""),
|
||||
},
|
||||
)
|
||||
return replacements
|
||||
|
||||
@staticmethod
|
||||
def _repr_unicode(creator, value):
|
||||
py2 = creator.interpreter.version_info.major == 2
|
||||
if py2: # on Python 2 we need to encode this into explicit utf-8, py3 supports unicode literals
|
||||
start = 2 if sys.version_info[0] == 3 else 1
|
||||
value = ensure_text(repr(value.encode("utf-8"))[start:-1])
|
||||
return value
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Activate virtualenv for current interpreter:
|
||||
|
||||
Use exec(open(this_file).read(), {'__file__': this_file}).
|
||||
|
||||
This can be used when you must use an existing Python interpreter, not the virtualenv bin/python.
|
||||
"""
|
||||
import os
|
||||
import site
|
||||
import sys
|
||||
|
||||
try:
|
||||
abs_file = os.path.abspath(__file__)
|
||||
except NameError:
|
||||
raise AssertionError("You must use exec(open(this_file).read(), {'__file__': this_file}))")
|
||||
|
||||
bin_dir = os.path.dirname(abs_file)
|
||||
base = bin_dir[: -len("__BIN_NAME__") - 1] # strip away the bin part from the __file__, plus the path separator
|
||||
|
||||
# prepend bin to PATH (this file is inside the bin directory)
|
||||
os.environ["PATH"] = os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
|
||||
os.environ["VIRTUAL_ENV"] = base # virtual env is right above bin directory
|
||||
|
||||
# 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.decode("utf-8") if "__DECODE_PATH__" else path)
|
||||
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
|
||||
|
||||
sys.real_prefix = sys.prefix
|
||||
sys.prefix = base
|
||||
Loading…
Add table
Add a link
Reference in a new issue