Skip to content

Commit ed5a2a0

Browse files
authored
Drop need for virtualenv (#13136)
Linking #12237
1 parent 37080f5 commit ed5a2a0

File tree

7 files changed

+24
-45
lines changed

7 files changed

+24
-45
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
python-version: '3.7'
2626
- name: Install tox
27-
run: pip install --upgrade 'setuptools!=50' 'virtualenv>=20.6.0' tox==3.24.5
27+
run: pip install --upgrade 'setuptools!=50' tox==3.24.5
2828
- name: Setup tox environment
2929
run: tox -e ${{ env.TOXENV }} --notest
3030
- name: Test

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
./misc/build-debug-python.sh $PYTHONVERSION $PYTHONDIR $VENV
109109
source $VENV/bin/activate
110110
- name: Install tox
111-
run: pip install --upgrade 'setuptools!=50' 'virtualenv>=20.6.0' tox==3.24.5
111+
run: pip install --upgrade 'setuptools!=50' tox==3.24.5
112112
- name: Compiled with mypyc
113113
if: ${{ matrix.test_mypyc }}
114114
run: |
@@ -128,7 +128,7 @@ jobs:
128128
with:
129129
python-version: '3.11-dev'
130130
- name: Install tox
131-
run: pip install --upgrade 'setuptools!=50' 'virtualenv>=20.6.0' tox==3.24.5
131+
run: pip install --upgrade 'setuptools!=50' tox==3.24.5
132132
- name: Setup tox environment
133133
run: tox -e py --notest
134134
- name: Test

mypy/test/testpep561.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
from contextlib import contextmanager
22
import filelock
33
import os
4-
import pytest
54
import re
65
import subprocess
76
from subprocess import PIPE
87
import sys
98
import tempfile
10-
from typing import Tuple, List, Generator
9+
from typing import Tuple, List, Iterator
1110

1211
import mypy.api
1312
from mypy.test.config import package_path, pip_lock, pip_timeout
14-
from mypy.util import try_find_python2_interpreter
1513
from mypy.test.data import DataDrivenTestCase, DataSuite
1614
from mypy.test.config import test_temp_dir
1715
from mypy.test.helpers import assert_string_arrays_equal, perform_file_operations
@@ -32,23 +30,19 @@ def run_case(self, test_case: DataDrivenTestCase) -> None:
3230

3331

3432
@contextmanager
35-
def virtualenv(
36-
python_executable: str = sys.executable
37-
) -> Generator[Tuple[str, str], None, None]:
33+
def virtualenv(python_executable: str = sys.executable) -> Iterator[Tuple[str, str]]:
3834
"""Context manager that creates a virtualenv in a temporary directory
3935
40-
returns the path to the created Python executable"""
41-
# Sadly, we need virtualenv, as the Python 3 venv module does not support creating a venv
42-
# for Python 2, and Python 2 does not have its own venv.
36+
Returns the path to the created Python executable
37+
"""
4338
with tempfile.TemporaryDirectory() as venv_dir:
44-
proc = subprocess.run([sys.executable,
45-
'-m',
46-
'virtualenv',
47-
f'-p{python_executable}',
48-
venv_dir], cwd=os.getcwd(), stdout=PIPE, stderr=PIPE)
39+
proc = subprocess.run(
40+
[python_executable, '-m', 'venv', venv_dir],
41+
cwd=os.getcwd(), stdout=PIPE, stderr=PIPE
42+
)
4943
if proc.returncode != 0:
5044
err = proc.stdout.decode('utf-8') + proc.stderr.decode('utf-8')
51-
raise Exception("Failed to create venv. Do you have virtualenv installed?\n" + err)
45+
raise Exception("Failed to create venv.\n" + err)
5246
if sys.platform == 'win32':
5347
yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python'))
5448
else:
@@ -94,12 +88,7 @@ def install_package(pkg: str,
9488
def test_pep561(testcase: DataDrivenTestCase) -> None:
9589
"""Test running mypy on files that depend on PEP 561 packages."""
9690
assert testcase.old_cwd is not None, "test was not properly set up"
97-
if 'python2' in testcase.name.lower():
98-
python = try_find_python2_interpreter()
99-
if python is None:
100-
pytest.skip()
101-
else:
102-
python = sys.executable
91+
python = sys.executable
10392

10493
assert python is not None, "Should be impossible"
10594
pkgs, pip_args = parse_pkgs(testcase.input[0])

mypyc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ First clone the mypy git repository:
6767

6868
Optionally create a virtualenv (recommended):
6969

70-
$ virtualenv -p python3 <directory>
70+
$ python3 -m venv <directory>
7171
$ source <directory>/bin/activate
7272

7373
Then install the dependencies:

mypyc/test-data/run-imports.test

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ def test_import_as_submodule_within_function() -> None:
3030
# assert 'nob' not in globals()
3131

3232
def test_import_module_without_stub_in_function() -> None:
33-
# 'virtualenv' must not have a stub in typeshed for this test case
34-
import virtualenv # type: ignore
33+
# 'psutil' must not have a stub in typeshed for this test case
34+
import psutil # type: ignore
3535
# TODO: We shouldn't add local imports to globals()
36-
# assert 'virtualenv' not in globals()
37-
assert isinstance(virtualenv.__name__, str)
36+
# assert 'psutil' not in globals()
37+
assert isinstance(psutil.__name__, str)
3838

3939
def test_import_as_module_without_stub_in_function() -> None:
40-
# 'virtualenv' must not have a stub in typeshed for this test case
41-
import virtualenv as vv # type: ignore
42-
assert 'virtualenv' not in globals()
40+
# 'psutil' must not have a stub in typeshed for this test case
41+
import psutil as pp # type: ignore
42+
assert 'psutil' not in globals()
4343
# TODO: We shouldn't add local imports to globals()
44-
# assert 'vv' not in globals()
45-
assert isinstance(vv.__name__, str)
44+
# assert 'pp' not in globals()
45+
assert isinstance(pp.__name__, str)
4646

4747
[file testmodule.py]
4848
def factorial(x: int) -> int:

test-data/unit/pep561.test

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ reveal_type(a)
7272
[out]
7373
testStubPrecedence.py:5: note: Revealed type is "builtins.list[builtins.str]"
7474

75-
[case testTypedPkgStubs_python2]
76-
# pkgs: typedpkg-stubs
77-
from typedpkg.sample import ex
78-
from typedpkg import dne
79-
a = ex([''])
80-
reveal_type(a)
81-
[out]
82-
testTypedPkgStubs_python2.py:3: error: Module "typedpkg" has no attribute "dne"
83-
testTypedPkgStubs_python2.py:5: note: Revealed type is "builtins.list[builtins.str]"
84-
8575
[case testTypedPkgSimpleEgg]
8676
# pkgs: typedpkg; no-pip
8777
from typedpkg.sample import ex

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ pytest-forked>=1.3.0,<2.0.0
1515
pytest-cov>=2.10.0,<3.0.0
1616
py>=1.5.2
1717
typed_ast>=1.5.4,<2; python_version>='3.8'
18-
virtualenv>=20.6.0
1918
setuptools!=50
19+
six
2020
importlib-metadata>=4.6.1,<5.0.0

0 commit comments

Comments
 (0)