summaryrefslogtreecommitdiff
path: root/src/virtualenv/activation/python
diff options
context:
space:
mode:
authorBernát Gábor <bgabor8@bloomberg.net>2020-01-02 16:32:54 +0000
committerBernat Gabor <bgabor8@bloomberg.net>2020-01-10 15:38:36 +0000
commitff6dc73d447a3c6276af64df2eb91e2709e450a3 (patch)
treecf2c4be51c557ce2157cc32279cbd53464df3bf5 /src/virtualenv/activation/python
parent1cb5216252dbb144a3ee3976f9ec92def3dfc6db (diff)
downloadvirtualenv-ff6dc73d447a3c6276af64df2eb91e2709e450a3.tar.gz
unicode support (#1477)
* creator unicode support Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * activator support Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * fix * add space * python3.4 support * Windows fixes * some fixes * fix powershell requires utf-16 * try to fix python2 windows Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * use utf-8 for activation scripts Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * fix * more fix Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * fix Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * windows path py2.7 * fixes for Python 2 and unicode on Windows * do not single out mbcs, but the file system encoder * do not install pathlib python 2 windows Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net> * fix encoding on py35 Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Diffstat (limited to 'src/virtualenv/activation/python')
-rw-r--r--src/virtualenv/activation/python/__init__.py2
-rw-r--r--src/virtualenv/activation/python/activate_this.py16
2 files changed, 15 insertions, 3 deletions
diff --git a/src/virtualenv/activation/python/__init__.py b/src/virtualenv/activation/python/__init__.py
index 1d73e99..36b2b2c 100644
--- a/src/virtualenv/activation/python/__init__.py
+++ b/src/virtualenv/activation/python/__init__.py
@@ -3,7 +3,7 @@ from __future__ import absolute_import, unicode_literals
import json
import os
-from pathlib2 import Path
+from virtualenv.util import Path
from ..via_template import ViaTemplateActivator
diff --git a/src/virtualenv/activation/python/activate_this.py b/src/virtualenv/activation/python/activate_this.py
index fc8d449..3311fe8 100644
--- a/src/virtualenv/activation/python/activate_this.py
+++ b/src/virtualenv/activation/python/activate_this.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
"""Activate virtualenv for current interpreter:
Use exec(open(this_file).read(), {'__file__': this_file}).
@@ -14,14 +15,21 @@ try:
except NameError:
raise AssertionError("You must use exec(open(this_file).read(), {'__file__': this_file}))")
+
+def set_env(key, value, encoding):
+ if sys.version_info[0] == 2:
+ value = value.encode(encoding)
+ os.environ[key] = value
+
+
# prepend bin to PATH (this file is inside the bin directory)
bin_dir = os.path.dirname(os.path.abspath(__file__))
-os.environ["PATH"] = os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
+set_env("PATH", os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep)), sys.getfilesystemencoding())
base = os.path.dirname(bin_dir)
# virtual env is right above bin directory
-os.environ["VIRTUAL_ENV"] = base
+set_env("VIRTUAL_ENV", base, sys.getfilesystemencoding())
# add the virtual environments site-packages to the host python import mechanism
prev = set(sys.path)
@@ -33,7 +41,11 @@ __SITE_PACKAGES__
'''
for site_package in json.loads(site_packages):
+ if sys.version_info[0] == 2:
+ site_package = site_package.encode('utf-8').decode(sys.getfilesystemencoding())
path = os.path.realpath(os.path.join(os.path.dirname(__file__), site_package))
+ if sys.version_info[0] == 2:
+ path = path.encode(sys.getfilesystemencoding())
site.addsitedir(path)
# fmt: on