From a07194384f1f572357c0bc2157ef5de10299868e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 15 Jul 2022 15:34:25 -0700 Subject: [PATCH 1/3] Drop need for virtualenv Linking #12237 --- .github/workflows/docs.yml | 2 +- .github/workflows/test.yml | 4 ++-- mypy/test/testpep561.py | 28 +++++++++------------------- mypyc/README.md | 2 +- mypyc/test-data/run-imports.test | 18 +++++++++--------- test-data/unit/pep561.test | 10 ---------- test-requirements.txt | 1 - 7 files changed, 22 insertions(+), 43 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c4f36d609e744..7ba18c6cc9e24 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -24,7 +24,7 @@ jobs: with: python-version: '3.7' - name: Install tox - run: pip install --upgrade 'setuptools!=50' 'virtualenv>=20.6.0' tox==3.24.5 + run: pip install --upgrade 'setuptools!=50' tox==3.24.5 - name: Setup tox environment run: tox -e ${{ env.TOXENV }} --notest - name: Test diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 71223846bc38f..f0be18d8d39a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -108,7 +108,7 @@ jobs: ./misc/build-debug-python.sh $PYTHONVERSION $PYTHONDIR $VENV source $VENV/bin/activate - name: Install tox - run: pip install --upgrade 'setuptools!=50' 'virtualenv>=20.6.0' tox==3.24.5 + run: pip install --upgrade 'setuptools!=50' tox==3.24.5 - name: Compiled with mypyc if: ${{ matrix.test_mypyc }} run: | @@ -128,7 +128,7 @@ jobs: with: python-version: '3.11-dev' - name: Install tox - run: pip install --upgrade 'setuptools!=50' 'virtualenv>=20.6.0' tox==3.24.5 + run: pip install --upgrade 'setuptools!=50' tox==3.24.5 - name: Setup tox environment run: tox -e py --notest - name: Test diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index e5c79762d2c2a..73b6e75242a1b 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -11,7 +11,6 @@ import mypy.api from mypy.test.config import package_path, pip_lock, pip_timeout -from mypy.util import try_find_python2_interpreter from mypy.test.data import DataDrivenTestCase, DataSuite from mypy.test.config import test_temp_dir from mypy.test.helpers import assert_string_arrays_equal, perform_file_operations @@ -32,23 +31,19 @@ def run_case(self, test_case: DataDrivenTestCase) -> None: @contextmanager -def virtualenv( - python_executable: str = sys.executable - ) -> Generator[Tuple[str, str], None, None]: +def virtualenv(python_executable: str = sys.executable) -> Iterator[Tuple[str, str]]: """Context manager that creates a virtualenv in a temporary directory - returns the path to the created Python executable""" - # Sadly, we need virtualenv, as the Python 3 venv module does not support creating a venv - # for Python 2, and Python 2 does not have its own venv. + Returns the path to the created Python executable + """ with tempfile.TemporaryDirectory() as venv_dir: - proc = subprocess.run([sys.executable, - '-m', - 'virtualenv', - f'-p{python_executable}', - venv_dir], cwd=os.getcwd(), stdout=PIPE, stderr=PIPE) + proc = subprocess.run( + [python_executable, '-m', 'venv', venv_dir], + cwd=os.getcwd(), stdout=PIPE, stderr=PIPE + ) if proc.returncode != 0: err = proc.stdout.decode('utf-8') + proc.stderr.decode('utf-8') - raise Exception("Failed to create venv. Do you have virtualenv installed?\n" + err) + raise Exception("Failed to create venv.\n" + err) if sys.platform == 'win32': yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python')) else: @@ -94,12 +89,7 @@ def install_package(pkg: str, def test_pep561(testcase: DataDrivenTestCase) -> None: """Test running mypy on files that depend on PEP 561 packages.""" assert testcase.old_cwd is not None, "test was not properly set up" - if 'python2' in testcase.name.lower(): - python = try_find_python2_interpreter() - if python is None: - pytest.skip() - else: - python = sys.executable + python = sys.executable assert python is not None, "Should be impossible" pkgs, pip_args = parse_pkgs(testcase.input[0]) diff --git a/mypyc/README.md b/mypyc/README.md index 83f59c6dc317f..cb6cf5bf225c6 100644 --- a/mypyc/README.md +++ b/mypyc/README.md @@ -67,7 +67,7 @@ First clone the mypy git repository: Optionally create a virtualenv (recommended): - $ virtualenv -p python3 + $ python3 -m venv $ source /bin/activate Then install the dependencies: diff --git a/mypyc/test-data/run-imports.test b/mypyc/test-data/run-imports.test index 0957d1b2b87f5..c6d5bdb3d8649 100644 --- a/mypyc/test-data/run-imports.test +++ b/mypyc/test-data/run-imports.test @@ -30,19 +30,19 @@ def test_import_as_submodule_within_function() -> None: # assert 'nob' not in globals() def test_import_module_without_stub_in_function() -> None: - # 'virtualenv' must not have a stub in typeshed for this test case - import virtualenv # type: ignore + # 'psutil' must not have a stub in typeshed for this test case + import psutil # type: ignore # TODO: We shouldn't add local imports to globals() - # assert 'virtualenv' not in globals() - assert isinstance(virtualenv.__name__, str) + # assert 'psutil' not in globals() + assert isinstance(psutil.__name__, str) def test_import_as_module_without_stub_in_function() -> None: - # 'virtualenv' must not have a stub in typeshed for this test case - import virtualenv as vv # type: ignore - assert 'virtualenv' not in globals() + # 'psutil' must not have a stub in typeshed for this test case + import psutil as pp # type: ignore + assert 'psutil' not in globals() # TODO: We shouldn't add local imports to globals() - # assert 'vv' not in globals() - assert isinstance(vv.__name__, str) + # assert 'pp' not in globals() + assert isinstance(pp.__name__, str) [file testmodule.py] def factorial(x: int) -> int: diff --git a/test-data/unit/pep561.test b/test-data/unit/pep561.test index 5fd7b5dce6c6b..bee2c8f692d4f 100644 --- a/test-data/unit/pep561.test +++ b/test-data/unit/pep561.test @@ -72,16 +72,6 @@ reveal_type(a) [out] testStubPrecedence.py:5: note: Revealed type is "builtins.list[builtins.str]" -[case testTypedPkgStubs_python2] -# pkgs: typedpkg-stubs -from typedpkg.sample import ex -from typedpkg import dne -a = ex(['']) -reveal_type(a) -[out] -testTypedPkgStubs_python2.py:3: error: Module "typedpkg" has no attribute "dne" -testTypedPkgStubs_python2.py:5: note: Revealed type is "builtins.list[builtins.str]" - [case testTypedPkgSimpleEgg] # pkgs: typedpkg; no-pip from typedpkg.sample import ex diff --git a/test-requirements.txt b/test-requirements.txt index c50705dff7399..8ced6db9f75b5 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -15,6 +15,5 @@ pytest-forked>=1.3.0,<2.0.0 pytest-cov>=2.10.0,<3.0.0 py>=1.5.2 typed_ast>=1.5.4,<2; python_version>='3.8' -virtualenv>=20.6.0 setuptools!=50 importlib-metadata>=4.6.1,<5.0.0 From 952867729eb2322762e8e591ee9f9585c2cbee4a Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 15 Jul 2022 15:39:39 -0700 Subject: [PATCH 2/3] fix --- mypy/test/testpep561.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index 73b6e75242a1b..0f327658c8e0b 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -1,13 +1,12 @@ from contextlib import contextmanager import filelock import os -import pytest import re import subprocess from subprocess import PIPE import sys import tempfile -from typing import Tuple, List, Generator +from typing import Tuple, List, Iterator import mypy.api from mypy.test.config import package_path, pip_lock, pip_timeout From be5b2b6dc63a246fd9721c30b641e5e218bee7cf Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 15 Jul 2022 16:02:26 -0700 Subject: [PATCH 3/3] depend explicitly on six --- test-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test-requirements.txt b/test-requirements.txt index 8ced6db9f75b5..3aefdd258c0fc 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -16,4 +16,5 @@ pytest-cov>=2.10.0,<3.0.0 py>=1.5.2 typed_ast>=1.5.4,<2; python_version>='3.8' setuptools!=50 +six importlib-metadata>=4.6.1,<5.0.0