Skip to content

Commit

Permalink
Lower min version of six to 1.9 (#1606)
Browse files Browse the repository at this point in the history
This change should allow installation of virtualenv on systems
with older six where their LTS support may prevent them from
upgrading it.
  • Loading branch information
ssbarnea committed Feb 13, 2020
1 parent 5fcbab2 commit 52e4213
Show file tree
Hide file tree
Showing 42 changed files with 187 additions and 147 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1606.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lower minimal version of six required to 1.9 - by ``ssbarnea``
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install_requires =
appdirs>=1.4.3,<2
distlib>=0.3.0,<1
filelock>=3.0.0,<4
six>=1.12.0,<2
six>=1.9.0,<2 # keep it >=1.9.0 as it may cause problems on LTS platforms
contextlib2>=0.6.0,<1;python_version<"3.3"
importlib-metadata>=0.12,<2;python_version<"3.8"
importlib-resources>=1.0,<2;python_version<"3.7"
Expand Down
6 changes: 3 additions & 3 deletions src/virtualenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from datetime import datetime

import six
from virtualenv.util.six import ensure_text


def run(args=None, options=None):
Expand All @@ -20,8 +20,8 @@ def run(args=None, options=None):
logging.warning(
"created virtual environment in %.0fms %s with seeder %s",
(datetime.now() - start).total_seconds() * 1000,
six.ensure_text(str(session.creator)),
six.ensure_text(str(session.seeder)),
ensure_text(str(session.creator)),
ensure_text(str(session.seeder)),
)
except ProcessCallFailed as exception:
print("subprocess call failed for {}".format(exception.cmd))
Expand Down
4 changes: 2 additions & 2 deletions src/virtualenv/activation/activator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from abc import ABCMeta, abstractmethod

import six
from six import add_metaclass


@six.add_metaclass(ABCMeta)
@add_metaclass(ABCMeta)
class Activator(object):
"""Generates an activate script for the virtual environment"""

Expand Down
7 changes: 3 additions & 4 deletions src/virtualenv/activation/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import os
from collections import OrderedDict

import six

from virtualenv.info import WIN_CPYTHON_2
from virtualenv.util.path import Path
from virtualenv.util.six import ensure_text

from ..via_template import ViaTemplateActivator

Expand All @@ -20,7 +19,7 @@ def replacements(self, creator, dest_folder):
lib_folders = OrderedDict((os.path.relpath(str(i), str(dest_folder)), None) for i in creator.libs)
replacements.update(
{
"__LIB_FOLDERS__": six.ensure_text(os.pathsep.join(lib_folders.keys())),
"__LIB_FOLDERS__": ensure_text(os.pathsep.join(lib_folders.keys())),
"__DECODE_PATH__": ("yes" if WIN_CPYTHON_2 else ""),
}
)
Expand All @@ -30,5 +29,5 @@ def replacements(self, creator, dest_folder):
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
value = six.ensure_text(repr(value.encode("utf-8"))[1:-1])
value = ensure_text(repr(value.encode("utf-8"))[1:-1])
return value
12 changes: 7 additions & 5 deletions src/virtualenv/activation/via_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import sys
from abc import ABCMeta, abstractmethod

import six
from six import add_metaclass

from virtualenv.util.six import ensure_text

from .activator import Activator

Expand All @@ -14,7 +16,7 @@
from importlib_resources import read_text


@six.add_metaclass(ABCMeta)
@add_metaclass(ABCMeta)
class ViaTemplateActivator(Activator):
@abstractmethod
def templates(self):
Expand All @@ -30,10 +32,10 @@ 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__": six.ensure_text(str(creator.dest)),
"__VIRTUAL_ENV__": ensure_text(str(creator.dest)),
"__VIRTUAL_NAME__": creator.env_name,
"__BIN_NAME__": six.ensure_text(str(creator.bin_dir.relative_to(creator.dest))),
"__PATH_SEP__": six.ensure_text(os.pathsep),
"__BIN_NAME__": ensure_text(str(creator.bin_dir.relative_to(creator.dest))),
"__PATH_SEP__": ensure_text(os.pathsep),
}

def _generate(self, replacements, templates, to_folder, creator):
Expand Down
6 changes: 3 additions & 3 deletions src/virtualenv/config/env_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os

import six
from virtualenv.util.six import ensure_str, ensure_text

from .convert import convert

Expand All @@ -14,12 +14,12 @@ def get_env_var(key, as_type):
:param as_type: the type we would like to convert it to
:return:
"""
environ_key = six.ensure_str("VIRTUALENV_{}".format(key.upper()))
environ_key = ensure_str("VIRTUALENV_{}".format(key.upper()))
if os.environ.get(environ_key):
value = os.environ[environ_key]
# noinspection PyBroadException
try:
source = "env var {}".format(six.ensure_text(environ_key))
source = "env var {}".format(ensure_text(environ_key))
as_type = convert(value, as_type, source)
return as_type, source
except Exception: # note the converter already logs a warning when failures happen
Expand Down
5 changes: 2 additions & 3 deletions src/virtualenv/config/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import logging
import os

import six

from virtualenv.dirs import default_config_dir
from virtualenv.info import PY3
from virtualenv.util import ConfigParser
from virtualenv.util.path import Path
from virtualenv.util.six import ensure_str

from .convert import convert


class IniConfig(object):
VIRTUALENV_CONFIG_FILE_ENV_VAR = six.ensure_str("VIRTUALENV_CONFIG_FILE")
VIRTUALENV_CONFIG_FILE_ENV_VAR = ensure_str("VIRTUALENV_CONFIG_FILE")
STATE = {None: "failed to parse", True: "active", False: "missing"}

section = "virtualenv"
Expand Down
12 changes: 6 additions & 6 deletions src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from collections import OrderedDict
from stat import S_IWUSR

import six
from six import add_metaclass

from virtualenv.discovery.cached_py_info import LogCmd
from virtualenv.info import WIN_CPYTHON_2
from virtualenv.pyenv_cfg import PyEnvCfg
from virtualenv.util.path import Path
from virtualenv.util.six import ensure_str, ensure_text
from virtualenv.util.subprocess import run_cmd
from virtualenv.util.zipapp import ensure_file_on_disk
from virtualenv.version import __version__
Expand All @@ -43,14 +43,14 @@ def __init__(self, options, interpreter):
self.pyenv_cfg = PyEnvCfg.from_folder(self.dest)

def __repr__(self):
return six.ensure_str(self.__unicode__())
return ensure_str(self.__unicode__())

def __unicode__(self):
return "{}({})".format(self.__class__.__name__, ", ".join("{}={}".format(k, v) for k, v in self._args()))

def _args(self):
return [
("dest", six.ensure_text(str(self.dest))),
("dest", ensure_text(str(self.dest))),
("clear", self.clear),
]

Expand Down Expand Up @@ -103,7 +103,7 @@ def non_write_able(dest, value):
encoding = sys.getfilesystemencoding()
refused = OrderedDict()
kwargs = {"errors": "ignore"} if encoding != "mbcs" else {}
for char in six.ensure_text(raw_value):
for char in ensure_text(raw_value):
try:
trip = char.encode(encoding, **kwargs).decode(encoding)
if trip == char:
Expand Down Expand Up @@ -135,7 +135,7 @@ def non_write_able(dest, value):
value = dest
while dest:
if dest.exists():
if os.access(six.ensure_text(str(dest)), os.W_OK):
if os.access(ensure_text(str(dest)), os.W_OK):
break
else:
non_write_able(dest, value)
Expand Down Expand Up @@ -188,7 +188,7 @@ def get_env_debug_info(env_exe, debug_script):
with ensure_file_on_disk(debug_script) as debug_script:
cmd = [str(env_exe), str(debug_script)]
if WIN_CPYTHON_2:
cmd = [six.ensure_text(i) for i in cmd]
cmd = [ensure_text(i) for i in cmd]
logging.debug(str("debug via %r"), LogCmd(cmd))
code, out, err = run_cmd(cmd)

Expand Down
3 changes: 2 additions & 1 deletion src/virtualenv/create/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from abc import ABCMeta
from collections import OrderedDict

from six import add_metaclass, ensure_text
from six import add_metaclass

from virtualenv.info import IS_WIN
from virtualenv.util.path import Path
from virtualenv.util.six import ensure_text


@add_metaclass(ABCMeta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import logging

import six
from six import add_metaclass

from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.util.path import Path
Expand All @@ -12,7 +12,7 @@
from .common import CPython, CPythonPosix, CPythonWindows


@six.add_metaclass(abc.ABCMeta)
@add_metaclass(abc.ABCMeta)
class CPython2(CPython, Python2):
"""Create a CPython version 2 virtual environment"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import abc

import six
from six import add_metaclass

from virtualenv.create.describe import Python3Supports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
Expand All @@ -11,7 +11,7 @@
from .common import CPython, CPythonPosix, CPythonWindows


@six.add_metaclass(abc.ABCMeta)
@add_metaclass(abc.ABCMeta)
class CPython3(CPython, Python3Supports):
""""""

Expand Down
4 changes: 2 additions & 2 deletions src/virtualenv/create/via_global_ref/builtin/pypy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import abc

import six
from six import add_metaclass

from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.util.path import Path

from ..via_global_self_do import ViaGlobalRefVirtualenvBuiltin


@six.add_metaclass(abc.ABCMeta)
@add_metaclass(abc.ABCMeta)
class PyPy(ViaGlobalRefVirtualenvBuiltin):
@classmethod
def can_describe(cls, interpreter):
Expand Down
4 changes: 2 additions & 2 deletions src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import logging

import six
from six import add_metaclass

from virtualenv.create.describe import PosixSupports, WindowsSupports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
Expand All @@ -13,7 +13,7 @@
from .common import PyPy


@six.add_metaclass(abc.ABCMeta)
@add_metaclass(abc.ABCMeta)
class PyPy2(PyPy, Python2):
""""""

Expand Down
4 changes: 2 additions & 2 deletions src/virtualenv/create/via_global_ref/builtin/pypy/pypy3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import abc

import six
from six import add_metaclass

from virtualenv.create.describe import PosixSupports, Python3Supports, WindowsSupports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
Expand All @@ -11,7 +11,7 @@
from .common import PyPy


@six.add_metaclass(abc.ABCMeta)
@add_metaclass(abc.ABCMeta)
class PyPy3(PyPy, Python3Supports):
@classmethod
def exe_stem(cls):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
import json
import os

import six
from six import add_metaclass

from virtualenv.create.describe import Python2Supports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.info import IS_ZIPAPP
from virtualenv.util.path import Path
from virtualenv.util.six import ensure_text
from virtualenv.util.zipapp import read as read_from_zipapp

from ..via_global_self_do import ViaGlobalRefVirtualenvBuiltin

HERE = Path(os.path.abspath(__file__)).parent


@six.add_metaclass(abc.ABCMeta)
@add_metaclass(abc.ABCMeta)
class Python2(ViaGlobalRefVirtualenvBuiltin, Python2Supports):
def create(self):
"""Perform operations needed to make the created environment work on Python 2"""
Expand All @@ -30,9 +31,7 @@ def create(self):
custom_site_text = read_from_zipapp(custom_site)
else:
custom_site_text = custom_site.read_text()
expected = json.dumps(
[os.path.relpath(six.ensure_text(str(i)), six.ensure_text(str(site_py))) for i in self.libs]
)
expected = json.dumps([os.path.relpath(ensure_text(str(i)), ensure_text(str(site_py))) for i in self.libs])
site_py.write_text(custom_site_text.replace("___EXPECTED_SITE_PACKAGES___", expected))

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion src/virtualenv/create/via_global_ref/builtin/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from collections import OrderedDict
from stat import S_IXGRP, S_IXOTH, S_IXUSR

from six import add_metaclass, ensure_text
from six import add_metaclass

from virtualenv.info import PY3, fs_is_case_sensitive, fs_supports_symlink
from virtualenv.util.path import copy, link, make_exe, symlink
from virtualenv.util.six import ensure_text


@add_metaclass(ABCMeta)
Expand Down
9 changes: 4 additions & 5 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import os
import sys

import six

from virtualenv.info import IS_WIN
from virtualenv.util.six import ensure_str, ensure_text

from .discover import Discover
from .py_info import PythonInfo
Expand All @@ -33,7 +32,7 @@ def run(self):
return get_interpreter(self.python_spec)

def __repr__(self):
return six.ensure_str(self.__unicode__())
return ensure_str(self.__unicode__())

def __unicode__(self):
return "{} discover of python_spec={!r}".format(self.__class__.__name__, self.python_spec)
Expand Down Expand Up @@ -73,7 +72,7 @@ def propose_interpreters(spec):
# find on path, the path order matters (as the candidates are less easy to control by end user)
tested_exes = set()
for pos, path in enumerate(paths):
path = six.ensure_text(path)
path = ensure_text(path)
logging.debug(LazyPathDump(pos, path))
for candidate, match in possible_specs(spec):
found = check_path(candidate, path)
Expand Down Expand Up @@ -106,7 +105,7 @@ def __init__(self, pos, path):
self.path = path

def __repr__(self):
return six.ensure_str(self.__unicode__())
return ensure_str(self.__unicode__())

def __unicode__(self):
content = "discover PATH[{}]={}".format(self.pos, self.path)
Expand Down
Loading

0 comments on commit 52e4213

Please sign in to comment.