Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unicode support #1477

Merged
merged 18 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def generate_draft_news():
env = os.environ.copy()
env["PATH"] += os.pathsep.join([os.path.dirname(sys.executable)] + env["PATH"].split(os.pathsep))
changelog = subprocess.check_output(
["towncrier", "--draft", "--version", "DRAFT"], cwd=str(ROOT_SRC_TREE_DIR), env=env
).decode("utf-8")
["towncrier", "--draft", "--version", "DRAFT"], cwd=str(ROOT_SRC_TREE_DIR), env=env, universal_newlines=True
)
if "No significant changes" in changelog:
content = ""
else:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ zip_safe = True
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
install_requires =
six >= 1.12.0, < 2
pathlib2 >= 2.3.3, < 3
appdirs >= 1.4.3
entrypoints >= 0.3, <1
pathlib2 >= 2.3.3, < 3; python_version < '3.4' and sys.platform != 'win32'
distlib >= 0.3.0, <1; sys.platform == 'win32'
[options.packages.find]
where = src

[options.extras_require]
testing =
pytest >= 4.0.0, <6
coverage >= 5.0.1, <6
coverage >= 4.5.1, <6
pytest-mock >= 1.12.1, <2
xonsh >= 0.9.13, <1; python_version > '3.4'
docs =
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/bash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, unicode_literals

from pathlib2 import Path
from virtualenv.util import Path

from ..via_template import ViaTemplateActivator

Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/bash/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ deactivate () {
# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="__VIRTUAL_ENV__"
VIRTUAL_ENV='__VIRTUAL_ENV__'
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/batch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, unicode_literals

from pathlib2 import Path
from virtualenv.util import Path

from ..via_template import ViaTemplateActivator

Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/cshell/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, unicode_literals

from pathlib2 import Path
from virtualenv.util import Path

from ..via_template import ViaTemplateActivator

Expand Down
6 changes: 3 additions & 3 deletions src/virtualenv/activation/cshell/activate.csh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA
# Unset irrelevant variables.
deactivate nondestructive

setenv VIRTUAL_ENV "__VIRTUAL_ENV__"
setenv VIRTUAL_ENV '__VIRTUAL_ENV__'

set _OLD_VIRTUAL_PATH="$PATH:q"
setenv PATH "$VIRTUAL_ENV:q/__BIN_NAME__:$PATH:q"



if ("__VIRTUAL_PROMPT__" != "") then
set env_name = "__VIRTUAL_PROMPT__"
if ('__VIRTUAL_PROMPT__' != "") then
set env_name = '__VIRTUAL_PROMPT__'
else
set env_name = '('"$VIRTUAL_ENV:t:q"') '
endif
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/fish/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, unicode_literals

from pathlib2 import Path
from virtualenv.util import Path

from ..via_template import ViaTemplateActivator

Expand Down
22 changes: 11 additions & 11 deletions src/virtualenv/activation/fish/activate.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ function deactivate -d 'Exit virtualenv mode and return to the normal environmen
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
if test (echo $FISH_VERSION | tr "." "\n")[1] -lt 3
set -gx PATH (_fishify_path $_OLD_VIRTUAL_PATH)
if test (echo $FISH_VERSION | head -c 1) -lt 3
set -gx PATH (_fishify_path "$_OLD_VIRTUAL_PATH")
else
set -gx PATH $_OLD_VIRTUAL_PATH
set -gx PATH "$_OLD_VIRTUAL_PATH"
end
set -e _OLD_VIRTUAL_PATH
end

if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
set -gx PYTHONHOME "$_OLD_VIRTUAL_PYTHONHOME"
set -e _OLD_VIRTUAL_PYTHONHOME
end

Expand Down Expand Up @@ -57,15 +57,15 @@ end
# Unset irrelevant variables.
deactivate nondestructive

set -gx VIRTUAL_ENV "__VIRTUAL_ENV__"
set -gx VIRTUAL_ENV '__VIRTUAL_ENV__'

# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
if test (echo $FISH_VERSION | tr "." "\n")[1] -lt 3
if test (echo $FISH_VERSION | head -c 1) -lt 3
set -gx _OLD_VIRTUAL_PATH (_bashify_path $PATH)
else
set -gx _OLD_VIRTUAL_PATH $PATH
set -gx _OLD_VIRTUAL_PATH "$PATH"
end
set -gx PATH "$VIRTUAL_ENV/__BIN_NAME__" $PATH
set -gx PATH "$VIRTUAL_ENV"'/__BIN_NAME__' $PATH

# Unset `$PYTHONHOME` if set.
if set -q PYTHONHOME
Expand All @@ -87,10 +87,10 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"

# Prompt override provided?
# If not, just prepend the environment name.
if test -n "__VIRTUAL_PROMPT__"
printf '%s%s' "__VIRTUAL_PROMPT__" (set_color normal)
if test -n '__VIRTUAL_PROMPT__'
printf '%s%s' '__VIRTUAL_PROMPT__' (set_color normal)
else
printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV")
printf '%s(%s) ' (set_color normal) (basename '$VIRTUAL_ENV')
end

# Restore the original $status
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/powershell/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, unicode_literals

from pathlib2 import Path
from virtualenv.util import Path

from ..via_template import ViaTemplateActivator

Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import os

from pathlib2 import Path
from virtualenv.util import Path

from ..via_template import ViaTemplateActivator

Expand Down
16 changes: 14 additions & 2 deletions src/virtualenv/activation/python/activate_this.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Activate virtualenv for current interpreter:

Use exec(open(this_file).read(), {'__file__': this_file}).
Expand All @@ -14,14 +15,21 @@
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)
Expand All @@ -33,7 +41,11 @@
'''

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

Expand Down
8 changes: 4 additions & 4 deletions src/virtualenv/activation/via_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def generate(self, creator):
def replacements(self, creator, dest_folder):
return {
"__VIRTUAL_PROMPT__": "" if self.flag_prompt is None else self.flag_prompt,
"__VIRTUAL_ENV__": str(creator.dest_dir),
"__VIRTUAL_NAME__": str(creator.env_name),
"__BIN_NAME__": str(creator.bin_name),
"__VIRTUAL_ENV__": six.ensure_text(str(creator.dest_dir)),
"__VIRTUAL_NAME__": creator.env_name,
"__BIN_NAME__": six.ensure_text(str(creator.bin_name)),
"__PATH_SEP__": os.pathsep,
}

Expand All @@ -35,4 +35,4 @@ def _generate(self, replacements, templates, to_folder):
text = pkgutil.get_data(self.__module__, str(template)).decode("utf-8")
for start, end in replacements.items():
text = text.replace(start, end)
(to_folder / template).write_text(text)
(to_folder / template).write_text(text, encoding="utf-8")
2 changes: 1 addition & 1 deletion src/virtualenv/activation/xonosh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, unicode_literals

from pathlib2 import Path
from virtualenv.util import Path

from ..via_template import ViaTemplateActivator

Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/config/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import logging
import os

from pathlib2 import Path

from virtualenv.info import PY3, get_default_config_dir
from virtualenv.util import Path

from .convert import convert

Expand Down
3 changes: 2 additions & 1 deletion src/virtualenv/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys

from appdirs import user_config_dir, user_data_dir
from pathlib2 import Path

from virtualenv.util import Path

IS_PYPY = hasattr(sys, "pypy_version_info")
PY3 = sys.version_info[0] == 3
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/interpreters/create/cpython/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from os import X_OK, access, chmod

import six
from pathlib2 import Path

from virtualenv.interpreters.create.via_global_ref import ViaGlobalRef
from virtualenv.util import copy, ensure_dir, symlink
from virtualenv.util import Path, copy, ensure_dir, symlink


@six.add_metaclass(abc.ABCMeta)
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/interpreters/create/cpython/cpython2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import abc

import six
from pathlib2 import Path

from virtualenv.util import copy
from virtualenv.util import Path, copy

from .common import CPython, CPythonPosix, CPythonWindows

Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/interpreters/create/cpython/cpython3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import abc

import six
from pathlib2 import Path

from virtualenv.util import copy
from virtualenv.util import Path, copy

from .common import CPython, CPythonPosix, CPythonWindows

Expand Down
Loading