Skip to content

Commit

Permalink
POC: Lower min version of six
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 94fdcab
Show file tree
Hide file tree
Showing 51 changed files with 100 additions and 79 deletions.
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
2 changes: 1 addition & 1 deletion 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 import _six as six


def run(args=None, options=None):
Expand Down
48 changes: 48 additions & 0 deletions src/virtualenv/_six.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Backward compatibility layer with older version of six.
This is used to avoid virtualenv requring a version of six newer than what
the system may have.
"""
from six import PY2, PY3, add_metaclass, binary_type, exec_, string_types, text_type # noqa

try:
from six import ensure_text
except ImportError:

def ensure_text(s, encoding="utf-8", errors="strict"):
"""Coerce *s* to six.text_type.
For Python 2:
- `unicode` -> `unicode`
- `str` -> `unicode`
For Python 3:
- `str` -> `str`
- `bytes` -> decoded to `str`
"""
if isinstance(s, binary_type):
return s.decode(encoding, errors)
elif isinstance(s, text_type):
return s
else:
raise TypeError("not expecting type '%s'" % type(s))


try:
from six import ensure_str
except ImportError:

def ensure_str(s, encoding="utf-8", errors="strict"):
"""Coerce *s* to `str`.
For Python 2:
- `unicode` -> encoded to `str`
- `str` -> `str`
For Python 3:
- `str` -> `str`
- `bytes` -> decoded to `str`
"""
if not isinstance(s, (text_type, binary_type)):
raise TypeError("not expecting type '%s'" % type(s))
if PY2 and isinstance(s, text_type):
s = s.encode(encoding, errors)
elif PY3 and isinstance(s, binary_type):
s = s.decode(encoding, errors)
return s
2 changes: 1 addition & 1 deletion src/virtualenv/activation/activator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from abc import ABCMeta, abstractmethod

import six
import virtualenv._six as six


@six.add_metaclass(ABCMeta)
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/activation/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import os
from collections import OrderedDict

import six

import virtualenv._six as six
from virtualenv.info import WIN_CPYTHON_2
from virtualenv.util.path import Path

Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/activation/via_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from abc import ABCMeta, abstractmethod

import six
import virtualenv._six as six

from .activator import Activator

Expand Down
2 changes: 1 addition & 1 deletion 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
import virtualenv._six as six

from .convert import convert

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,8 +3,7 @@
import logging
import os

import six

import virtualenv._six as six
from virtualenv.dirs import default_config_dir
from virtualenv.info import PY3
from virtualenv.util import ConfigParser
Expand Down
6 changes: 2 additions & 4 deletions src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from collections import OrderedDict
from stat import S_IWUSR

import six
from six import add_metaclass

import virtualenv._six as six
from virtualenv.discovery.cached_py_info import LogCmd
from virtualenv.info import WIN_CPYTHON_2
from virtualenv.pyenv_cfg import PyEnvCfg
Expand All @@ -26,7 +24,7 @@
DEBUG_SCRIPT = HERE / "debug.py"


@add_metaclass(ABCMeta)
@six.add_metaclass(ABCMeta)
class Creator(object):
"""A class that given a python Interpreter creates a virtual environment"""

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

from six import add_metaclass, ensure_text

from virtualenv._six import add_metaclass, ensure_text
from virtualenv.info import IS_WIN
from virtualenv.util.path import Path

Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/create/via_global_ref/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from abc import ABCMeta

from six import add_metaclass
from virtualenv._six import add_metaclass

from ..creator import Creator

Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/create/via_global_ref/builtin/builtin_way.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from abc import ABCMeta

from six import add_metaclass

from virtualenv._six import add_metaclass
from virtualenv.create.creator import Creator
from virtualenv.create.describe import Describe

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from abc import ABCMeta
from collections import OrderedDict

from six import add_metaclass

from virtualenv._six import add_metaclass
from virtualenv.create.describe import PosixSupports, WindowsSupports
from virtualenv.util.path import Path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import abc
import logging

import six

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

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

import abc

import six

import virtualenv._six as six
from virtualenv.create.describe import Python3Supports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.util.path import Path
Expand Down
3 changes: 1 addition & 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,8 +2,7 @@

import abc

import six

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

Expand Down
3 changes: 1 addition & 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,8 +3,7 @@
import abc
import logging

import six

import virtualenv._six as six
from virtualenv.create.describe import PosixSupports, WindowsSupports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.util.path import Path
Expand Down
3 changes: 1 addition & 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,8 +2,7 @@

import abc

import six

import virtualenv._six as six
from virtualenv.create.describe import PosixSupports, Python3Supports, WindowsSupports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.util.path import Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import json
import os

import six

import virtualenv._six as six
from virtualenv.create.describe import Python2Supports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.info import IS_ZIPAPP
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/create/via_global_ref/builtin/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from collections import OrderedDict
from stat import S_IXGRP, S_IXOTH, S_IXUSR

from six import add_metaclass, ensure_text

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from abc import ABCMeta
from collections import namedtuple

from six import add_metaclass

from virtualenv._six import add_metaclass
from virtualenv.create.via_global_ref.builtin.ref import ExePathRefToDest
from virtualenv.info import fs_supports_symlink
from virtualenv.util.path import ensure_dir
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import os
import sys

import six

import virtualenv._six as six
from virtualenv.info import IS_WIN

from .discover import Discover
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/discovery/cached_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from collections import OrderedDict
from hashlib import sha256

from six import ensure_text

from virtualenv._six import ensure_text
from virtualenv.dirs import default_data_dir
from virtualenv.discovery.py_info import PythonInfo
from virtualenv.info import PY2, PY3
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/discovery/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from abc import ABCMeta, abstractmethod

import six
import virtualenv._six as six


@six.add_metaclass(ABCMeta)
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/discovery/py_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import sys
from collections import OrderedDict

import six

import virtualenv._six as six
from virtualenv.info import fs_is_case_sensitive

PATTERN = re.compile(r"^(?P<impl>[a-zA-Z]+)?(?P<version>[0-9.]+)?(?:-(?P<arch>32|64))?$")
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/discovery/windows/pep514.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
from logging import basicConfig, getLogger

import six
import virtualenv._six as six

if six.PY3:
import winreg
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/pyenv_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from collections import OrderedDict

import six
import virtualenv._six as six


class PyEnvCfg(object):
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import sys

import six
import virtualenv._six as six

LEVELS = {
0: logging.CRITICAL,
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/seed/embed/base_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from abc import ABCMeta

import six

import virtualenv._six as six
from virtualenv.util.path import Path

from ..seeder import Seeder
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/seed/embed/wheels/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from shutil import copy2
from zipfile import ZipFile

import six

import virtualenv._six as six
from virtualenv.info import IS_ZIPAPP
from virtualenv.util.path import Path
from virtualenv.util.subprocess import Popen, subprocess
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/seed/seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from abc import ABCMeta, abstractmethod

import six
import virtualenv._six as six


@six.add_metaclass(ABCMeta)
Expand Down
5 changes: 2 additions & 3 deletions src/virtualenv/seed/via_app_data/pip_install/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from abc import ABCMeta, abstractmethod
from tempfile import mkdtemp

import six
from six import PY3

import virtualenv._six as six
from virtualenv._six import PY3
from virtualenv.util import ConfigParser
from virtualenv.util.path import Path

Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/seed/via_app_data/pip_install/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import os

import six

import virtualenv._six as six
from virtualenv.util.path import Path, copy

from .base import PipInstall
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/seed/via_app_data/pip_install/symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import subprocess
from stat import S_IREAD, S_IRGRP, S_IROTH, S_IWUSR

import six

import virtualenv._six as six
from virtualenv.util.subprocess import Popen

from .base import PipInstall
Expand Down
3 changes: 1 addition & 2 deletions src/virtualenv/seed/via_app_data/via_app_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from contextlib import contextmanager
from threading import Lock, Thread

import six

import virtualenv._six as six
from virtualenv.dirs import default_data_dir
from virtualenv.info import fs_supports_symlink
from virtualenv.seed.embed.base_embed import BaseEmbed
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import logging

import six
import virtualenv._six as six


class Session(object):
Expand Down
Loading

0 comments on commit 94fdcab

Please sign in to comment.