Skip to content

Commit 04af502

Browse files
authored
Drop Python 2 support (#2548)
1 parent cdd7eb1 commit 04af502

File tree

150 files changed

+415
-1017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+415
-1017
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- pypy-3.8
2828
- pypy-3.7
2929
os:
30-
- ubuntu-20.04
30+
- ubuntu-22.04
3131
- macos-12
3232
- windows-2022
3333
include:
@@ -60,10 +60,6 @@ jobs:
6060
fetch-depth: 0
6161
- name: Use local virtualenv for tox
6262
run: python -m pip install .
63-
- name: Install Python 2 for cross test
64-
uses: actions/setup-python@v4
65-
with:
66-
python-version: "2.7"
6763
- name: Setup brew python for test ${{ matrix.py }}
6864
if: startsWith(matrix.py,'brew@')
6965
run: |

.pre-commit-config.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ repos:
2121
hooks:
2222
- id: pyupgrade
2323
args: ["--py37-plus"]
24-
exclude: "^(src/virtualenv/create/via_global_ref/_virtualenv.py|src/virtualenv/create/via_global_ref/builtin/python2/site.py|src/virtualenv/discovery/py_info.py|tasks/__main__zipapp.py)$"
25-
- repo: https://github.com/asottile/pyupgrade
26-
rev: v2.38.4
27-
hooks:
28-
- id: pyupgrade
29-
files: "^(src/virtualenv/create/via_global_ref/_virtualenv.py|src/virtualenv/create/via_global_ref/builtin/python2/site.py|src/virtualenv/discovery/py_info.py|tasks/__main__zipapp.py)$"
3024
- repo: https://github.com/PyCQA/isort
3125
rev: 5.12.0
3226
hooks:

docs/changelog/2496.docs.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/changelog/2548.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Drop support for creating Python <3.6 (including 2) interpreters. Removed pip of ``20.3.4``, ``21.3.1``; wheel of
2+
``0.37.1``; setuptools of ``59.6.0``, ``44.1.1``, ``50.3.2``- by :user:`gaborbernat`.

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import subprocess
24
import sys
35
from datetime import date, datetime

docs/render_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from argparse import SUPPRESS
24
from collections import namedtuple
35
from contextlib import contextmanager

pyproject.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ dynamic = [
3737
]
3838
dependencies = [
3939
"distlib<1,>=0.3.6",
40-
"filelock<4,>=3.4.1",
41-
'importlib-metadata>=4.8.3; python_version < "3.8"',
42-
"platformdirs<4,>=2.4",
40+
"filelock<4,>=3.11",
41+
'importlib-metadata>=6.4.1; python_version < "3.8"',
42+
"platformdirs<4,>=3.2",
4343
]
4444
optional-dependencies.docs = [
4545
"furo>=2023.3.27",
@@ -76,15 +76,9 @@ nushell = "virtualenv.activation.nushell:NushellActivator"
7676
powershell = "virtualenv.activation.powershell:PowerShellActivator"
7777
python = "virtualenv.activation.python:PythonActivator"
7878
[project.entry-points."virtualenv.create"]
79-
cpython2-mac-arm-framework = "virtualenv.create.via_global_ref.builtin.cpython.mac_os:CPython2macOsArmFramework"
80-
cpython2-mac-framework = "virtualenv.create.via_global_ref.builtin.cpython.mac_os:CPython2macOsFramework"
81-
cpython2-posix = "virtualenv.create.via_global_ref.builtin.cpython.cpython2:CPython2Posix"
82-
cpython2-win = "virtualenv.create.via_global_ref.builtin.cpython.cpython2:CPython2Windows"
8379
cpython3-mac-framework = "virtualenv.create.via_global_ref.builtin.cpython.mac_os:CPython3macOsFramework"
8480
cpython3-posix = "virtualenv.create.via_global_ref.builtin.cpython.cpython3:CPython3Posix"
8581
cpython3-win = "virtualenv.create.via_global_ref.builtin.cpython.cpython3:CPython3Windows"
86-
pypy2-posix = "virtualenv.create.via_global_ref.builtin.pypy.pypy2:PyPy2Posix"
87-
pypy2-win = "virtualenv.create.via_global_ref.builtin.pypy.pypy2:Pypy2Windows"
8882
pypy3-posix = "virtualenv.create.via_global_ref.builtin.pypy.pypy3:PyPy3Posix"
8983
pypy3-win = "virtualenv.create.via_global_ref.builtin.pypy.pypy3:Pypy3Windows"
9084
venv = "virtualenv.create.via_global_ref.venv:Venv"
@@ -105,6 +99,7 @@ line-length = 120
10599
[tool.isort]
106100
profile = "black"
107101
known_first_party = ["virtualenv"]
102+
add_imports = ["from __future__ import annotations"]
108103

109104
[tool.flake8]
110105
max-complexity = 22

src/virtualenv/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .run import cli_run, session_via_cli
24
from .version import __version__
35

src/virtualenv/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import os
35
import sys

src/virtualenv/activation/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .bash import BashActivator
24
from .batch import BatchActivator
35
from .cshell import CShellActivator

src/virtualenv/activation/activator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
from abc import ABCMeta, abstractmethod
35

src/virtualenv/activation/bash/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from pathlib import Path
24

35
from ..via_template import ViaTemplateActivator

src/virtualenv/activation/batch/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24

35
from ..via_template import ViaTemplateActivator

src/virtualenv/activation/cshell/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from ..via_template import ViaTemplateActivator
24

35

src/virtualenv/activation/fish/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from ..via_template import ViaTemplateActivator
24

35

src/virtualenv/activation/nushell/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from ..via_template import ViaTemplateActivator
24

35

src/virtualenv/activation/powershell/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from ..via_template import ViaTemplateActivator
24

35

src/virtualenv/activation/python/__init__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
import os
2-
import sys
34
from collections import OrderedDict
45

56
from ..via_template import ViaTemplateActivator
@@ -12,23 +13,14 @@ def templates(self):
1213
def replacements(self, creator, dest_folder):
1314
replacements = super().replacements(creator, dest_folder)
1415
lib_folders = OrderedDict((os.path.relpath(str(i), str(dest_folder)), None) for i in creator.libs)
15-
win_py2 = creator.interpreter.platform == "win32" and creator.interpreter.version_info.major == 2
1616
replacements.update(
1717
{
1818
"__LIB_FOLDERS__": os.pathsep.join(lib_folders.keys()),
19-
"__DECODE_PATH__": ("yes" if win_py2 else ""),
19+
"__DECODE_PATH__": "",
2020
},
2121
)
2222
return replacements
2323

24-
@staticmethod
25-
def _repr_unicode(creator, value):
26-
py2 = creator.interpreter.version_info.major == 2
27-
if py2: # on Python 2 we need to encode this into explicit utf-8, py3 supports unicode literals
28-
start = 2 if sys.version_info[0] == 3 else 1
29-
value = repr(value.encode("utf-8"))[start:-1]
30-
return value
31-
3224

3325
__all__ = [
3426
"PythonActivator",

src/virtualenv/activation/python/activate_this.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
This can be used when you must use an existing Python interpreter, not the virtualenv bin/python.
66
"""
7+
from __future__ import annotations
8+
79
import os
810
import site
911
import sys

src/virtualenv/activation/via_template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import sys
35
from abc import ABCMeta, abstractmethod

src/virtualenv/app_data/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Application data stored by virtualenv.
33
"""
44

5+
from __future__ import annotations
6+
57
import logging
68
import os
79

src/virtualenv/app_data/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Application data stored by virtualenv.
33
"""
44

5+
from __future__ import annotations
6+
57
from abc import ABCMeta, abstractmethod
68
from contextlib import contextmanager
79

src/virtualenv/app_data/na.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from contextlib import contextmanager
24

35
from .base import AppData, ContentStore

src/virtualenv/app_data/read_only.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os.path
24

35
from virtualenv.util.lock import NoOpFileLock

src/virtualenv/app_data/via_disk_folder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
└── _virtualenv.py
2323
"""
2424

25+
from __future__ import annotations
26+
2527
import json
2628
import logging
2729
from abc import ABCMeta

src/virtualenv/app_data/via_tempdir.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
from tempfile import mkdtemp
35

src/virtualenv/config/cli/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
from argparse import SUPPRESS, ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace
35
from collections import OrderedDict

src/virtualenv/config/convert.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import os
35

src/virtualenv/config/env_var.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .convert import convert
24

35

src/virtualenv/config/ini.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import os
35
from configparser import ConfigParser

src/virtualenv/create/creator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import json
24
import logging
35
import os

src/virtualenv/create/debug.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Inspect a target Python interpreter virtual environment wise"""
2-
import sys # built-in
2+
from __future__ import annotations
33

4-
PYPY2_WIN = hasattr(sys, "pypy_version_info") and sys.platform != "win32" and sys.version_info[0] == 2
4+
import sys # built-in
55

66

77
def encode_path(value):
@@ -12,7 +12,7 @@ def encode_path(value):
1212
value = repr(value)
1313
else:
1414
value = repr(type(value))
15-
if isinstance(value, bytes) and not PYPY2_WIN:
15+
if isinstance(value, bytes):
1616
value = value.decode(sys.getfilesystemencoding())
1717
return value
1818

src/virtualenv/create/describe.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from abc import ABCMeta
24
from collections import OrderedDict
35
from pathlib import Path
@@ -58,7 +60,7 @@ def _config_vars(self):
5860

5961
def _calc_config_vars(self, to):
6062
sys_vars = self.interpreter.sysconfig_vars
61-
return {k: (to if v.startswith(self.interpreter.prefix) else v) for k, v in sys_vars.items()}
63+
return {k: (to if v is not None and v.startswith(self.interpreter.prefix) else v) for k, v in sys_vars.items()}
6264

6365
@classmethod
6466
def can_describe(cls, interpreter): # noqa: U100
@@ -82,12 +84,6 @@ def script(self, name):
8284
return self.script_dir / f"{name}{self.suffix}"
8385

8486

85-
class Python2Supports(Describe, metaclass=ABCMeta):
86-
@classmethod
87-
def can_describe(cls, interpreter):
88-
return interpreter.version_info.major == 2 and super().can_describe(interpreter)
89-
90-
9187
class Python3Supports(Describe, metaclass=ABCMeta):
9288
@classmethod
9389
def can_describe(cls, interpreter):
@@ -108,7 +104,6 @@ def can_describe(cls, interpreter):
108104

109105
__all__ = [
110106
"Describe",
111-
"Python2Supports",
112107
"Python3Supports",
113108
"PosixSupports",
114109
"WindowsSupports",

src/virtualenv/create/pyenv_cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
from collections import OrderedDict
35

0 commit comments

Comments
 (0)