From e212be4c9e851166d4273451f3c9474814bd7e3c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 26 Oct 2022 10:06:30 +0200 Subject: [PATCH 1/6] Fix compatibility with pytest 7.2 (#106) With pytest 7.2, the remaining parts of the "py.path" library got vendored, to get rid of the dependency: https://github.com/pytest-dev/pytest/pull/10396 However, this breaks due to pytest_mypy_plugins importing private API: File ".../pytest_mypy_plugins/collect.py", line 13, in from py._path.local import LocalPath ModuleNotFoundError: No module named 'py._path'; 'py' is not a package Use py.path.local instead (the public name of the same type), which is part of the shim included in pytest. --- CHANGELOG.md | 6 ++++++ pytest_mypy_plugins/collect.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4b01a5..be0fd68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Version history +## Version 1.10.1 + +### Bugfixes + +- Fixes compatibility with pytest 7.2, broken due to a private import from + `py._path`. ## Version 1.10.0 diff --git a/pytest_mypy_plugins/collect.py b/pytest_mypy_plugins/collect.py index a8ad8a0..637049d 100644 --- a/pytest_mypy_plugins/collect.py +++ b/pytest_mypy_plugins/collect.py @@ -6,11 +6,11 @@ from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Mapping, Optional, Set import pkg_resources +import py.path import pytest import yaml from _pytest.config.argparsing import Parser from _pytest.nodes import Node -from py._path.local import LocalPath from pytest_mypy_plugins import utils @@ -151,7 +151,7 @@ def pytest_collect_file(file_path: pathlib.Path, parent: Node) -> Optional[YamlT else: - def pytest_collect_file(path: LocalPath, parent: Node) -> Optional[YamlTestFile]: # type: ignore[misc] + def pytest_collect_file(path: py.path.local, parent: Node) -> Optional[YamlTestFile]: # type: ignore[misc] if path.ext in {".yaml", ".yml"} and path.basename.startswith(("test-", "test_")): return YamlTestFile.from_parent(parent, fspath=path) return None From 2a4fcd46b5ae448672c3f44cb83a4e735f0f0a5a Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 26 Oct 2022 12:44:10 +0300 Subject: [PATCH 2/6] Version 1.10.1 release (#107) * Version 1.10.1 release * Add 7.2 to the test * Fix types --- .github/workflows/test.yml | 3 ++- CHANGELOG.md | 3 +++ pytest_mypy_plugins/collect.py | 14 ++++++++++++-- setup.py | 4 +--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1bbdfcf..1368b72 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,8 @@ jobs: strategy: matrix: python-version: ["3.7", "3.8", "3.9", "3.10"] - pytest-version: ["~=6.2", "~=7.1"] + # TODO: remove `7.1` in the next release + pytest-version: ["~=6.2", "~=7.1", "~=7.2"] steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index be0fd68..87cdcd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,15 @@ # Version history + ## Version 1.10.1 ### Bugfixes +- Removes unused depenencies for `python < 3.7` - Fixes compatibility with pytest 7.2, broken due to a private import from `py._path`. + ## Version 1.10.0 ### Features diff --git a/pytest_mypy_plugins/collect.py b/pytest_mypy_plugins/collect.py index 637049d..ea1c653 100644 --- a/pytest_mypy_plugins/collect.py +++ b/pytest_mypy_plugins/collect.py @@ -3,7 +3,17 @@ import platform import sys import tempfile -from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Mapping, Optional, Set +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Hashable, + Iterator, + List, + Mapping, + Optional, + Set, +) import pkg_resources import py.path @@ -63,7 +73,7 @@ def parse_parametrized(params: List[Mapping[str, Any]]) -> List[Mapping[str, Any class SafeLineLoader(yaml.SafeLoader): - def construct_mapping(self, node: yaml.Node, deep: bool = False) -> None: + def construct_mapping(self, node: yaml.MappingNode, deep: bool = False) -> Dict[Hashable, Any]: mapping = super().construct_mapping(node, deep=deep) # Add 1 so line numbering starts at 1 starting_line = node.start_mark.line + 1 diff --git a/setup.py b/setup.py index 706d140..0d59571 100644 --- a/setup.py +++ b/setup.py @@ -10,12 +10,11 @@ "pyyaml", "chevron", "regex", - "dataclasses ; python_version<'3.7'", ] setup( name="pytest-mypy-plugins", - version="1.10.0", + version="1.10.1", description="pytest plugin for writing tests for mypy plugins", long_description=readme, long_description_content_type="text/markdown", @@ -36,7 +35,6 @@ classifiers=[ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", From 2459905e935f55846a5936ccbccbe4ae711ab5a0 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Thu, 4 May 2023 09:59:44 +0100 Subject: [PATCH 3/6] Fix build (#113) * Fix tests broken by mypy message changes. * Fix type changes needed for newer mypy version, plus formatting. --- pytest_mypy_plugins/collect.py | 2 +- pytest_mypy_plugins/item.py | 5 ++--- pytest_mypy_plugins/tests/test-parametrized.yml | 2 +- pytest_mypy_plugins/tests/test-paths-from-env.yml | 2 +- pytest_mypy_plugins/tests/test-simple-cases.yml | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pytest_mypy_plugins/collect.py b/pytest_mypy_plugins/collect.py index ea1c653..265db91 100644 --- a/pytest_mypy_plugins/collect.py +++ b/pytest_mypy_plugins/collect.py @@ -77,7 +77,7 @@ def construct_mapping(self, node: yaml.MappingNode, deep: bool = False) -> Dict[ mapping = super().construct_mapping(node, deep=deep) # Add 1 so line numbering starts at 1 starting_line = node.start_mark.line + 1 - for (title_node, contents_node) in node.value: + for title_node, contents_node in node.value: if title_node.value == "main": starting_line = title_node.start_mark.line + 1 mapping["__line__"] = starting_line diff --git a/pytest_mypy_plugins/item.py b/pytest_mypy_plugins/item.py index 1ffd091..dafd0ac 100644 --- a/pytest_mypy_plugins/item.py +++ b/pytest_mypy_plugins/item.py @@ -87,7 +87,7 @@ class ReturnCodes: FATAL_ERROR = 2 -def run_mypy_typechecking(cmd_options: List[str]) -> int: +def run_mypy_typechecking(cmd_options: List[str]) -> Optional[Union[str, int]]: fscache = FileSystemCache() sources, options = process_options(cmd_options, fscache=fscache) @@ -215,7 +215,7 @@ def typecheck_in_new_subprocess( def typecheck_in_same_process( self, execution_path: Path, mypy_cmd_options: List[Any] - ) -> Tuple[int, Tuple[str, str]]: + ) -> Tuple[Optional[Union[str, int]], Tuple[str, str]]: with utils.temp_environ(), utils.temp_path(), utils.temp_sys_modules(): # add custom environment variables for key, val in self.environment_variables.items(): @@ -241,7 +241,6 @@ def runtest(self) -> None: temp_dir = tempfile.TemporaryDirectory(prefix="pytest-mypy-", dir=self.root_directory) except (FileNotFoundError, PermissionError, NotADirectoryError) as e: - raise TypecheckAssertionError( error_message=f"Testing base directory {self.root_directory} must exist and be writable" ) from e diff --git a/pytest_mypy_plugins/tests/test-parametrized.yml b/pytest_mypy_plugins/tests/test-parametrized.yml index 4df19e2..d69729a 100644 --- a/pytest_mypy_plugins/tests/test-parametrized.yml +++ b/pytest_mypy_plugins/tests/test-parametrized.yml @@ -44,4 +44,4 @@ ... out: | main:2: note: Revealed type is "{{ rt }}" - main:4: error: Unsupported operand types for / ("str" and "int") + main:4: error: Unsupported operand types for / ("str" and "int") [operator] diff --git a/pytest_mypy_plugins/tests/test-paths-from-env.yml b/pytest_mypy_plugins/tests/test-paths-from-env.yml index 62ef522..3990813 100644 --- a/pytest_mypy_plugins/tests/test-paths-from-env.yml +++ b/pytest_mypy_plugins/tests/test-paths-from-env.yml @@ -3,7 +3,7 @@ import extra_module extra_module.extra_fn() - extra_module.missing() # E: Module has no attribute "missing" + extra_module.missing() # E: Module has no attribute "missing" [attr-defined] env: - MYPYPATH=../extras files: diff --git a/pytest_mypy_plugins/tests/test-simple-cases.yml b/pytest_mypy_plugins/tests/test-simple-cases.yml index e324f46..deb220e 100644 --- a/pytest_mypy_plugins/tests/test-simple-cases.yml +++ b/pytest_mypy_plugins/tests/test-simple-cases.yml @@ -57,7 +57,7 @@ - case: error_case main: | a = 1 - a.lower() # E: "int" has no attribute "lower" + a.lower() # E: "int" has no attribute "lower" [attr-defined] - case: custom_mypy_config_strict_optional_true_set @@ -87,7 +87,7 @@ skip: sys.version_info < (0, 0) main: | a = 1 - a.lower() # E: "int" has no attribute "lower" + a.lower() # E: "int" has no attribute "lower" [attr-defined] - case: fail_if_message_does_not_match expect_fail: yes From 27f6eddd545e5671103675c6cf1f4ee2e81b1cf2 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Thu, 4 May 2023 10:53:26 +0100 Subject: [PATCH 4/6] Replace pkg_resources with packaging for Python 3.12 compatibility. (#112) * Replace pkg_resources with packaging for Python 3.12 compatibility. * Add Python 3.11 to CI testing. * Formatting fix. --- .github/workflows/test.yml | 2 +- pytest_mypy_plugins/collect.py | 4 ++-- setup.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1368b72..5a1c30c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] # TODO: remove `7.1` in the next release pytest-version: ["~=6.2", "~=7.1", "~=7.2"] diff --git a/pytest_mypy_plugins/collect.py b/pytest_mypy_plugins/collect.py index 265db91..99a76ef 100644 --- a/pytest_mypy_plugins/collect.py +++ b/pytest_mypy_plugins/collect.py @@ -15,12 +15,12 @@ Set, ) -import pkg_resources import py.path import pytest import yaml from _pytest.config.argparsing import Parser from _pytest.nodes import Node +from packaging.version import Version from pytest_mypy_plugins import utils @@ -152,7 +152,7 @@ def _eval_skip(self, skip_if: str) -> bool: return eval(skip_if, {"sys": sys, "os": os, "pytest": pytest, "platform": platform}) -if pkg_resources.parse_version(pytest.__version__) >= pkg_resources.parse_version("7.0.0rc1"): +if Version(pytest.__version__) >= Version("7.0.0rc1"): def pytest_collect_file(file_path: pathlib.Path, parent: Node) -> Optional[YamlTestFile]: if file_path.suffix in {".yaml", ".yml"} and file_path.name.startswith(("test-", "test_")): diff --git a/setup.py b/setup.py index 0d59571..36b7d02 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ "pyyaml", "chevron", "regex", + "packaging", ] setup( From 50b11964e8b0ca25d72b7c6c0a415376e8751cbe Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 4 May 2023 13:04:30 +0300 Subject: [PATCH 5/6] Version 1.11.0 release --- CHANGELOG.md | 8 ++++++++ setup.py | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87cdcd4..d213f81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Version history +## Version 1.11.0 + +### Features + +- Adds `python3.11` support and promise about `python3.12` support +- Removes `pkg_resources` to use `packaging` instead + + ## Version 1.10.1 ### Bugfixes diff --git a/setup.py b/setup.py index 36b7d02..746d006 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ readme = f.read() dependencies = [ - "pytest>=6.0.0", + "pytest>=6.2.0", "mypy>=0.970", "decorator", "pyyaml", @@ -15,7 +15,7 @@ setup( name="pytest-mypy-plugins", - version="1.10.1", + version="1.11.0", description="pytest plugin for writing tests for mypy plugins", long_description=readme, long_description_content_type="text/markdown", @@ -40,6 +40,7 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Typing :: Typed", ], ) From ad3ee7f791cac24e1c7c3883d26f712d4120692b Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 5 May 2023 12:57:19 +0300 Subject: [PATCH 6/6] Version 1.11.1 release (#115) --- CHANGELOG.md | 7 +++++++ MANIFEST.in | 1 + setup.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 MANIFEST.in diff --git a/CHANGELOG.md b/CHANGELOG.md index d213f81..2cf40ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Version history +## Version 1.11.1 + +### Bugfixes + +- Adds `tests/` subfolder to `sdist` package + + ## Version 1.11.0 ### Features diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..d3ceaab --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +graft pytest_mypy_plugins/tests diff --git a/setup.py b/setup.py index 746d006..80c84f3 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name="pytest-mypy-plugins", - version="1.11.0", + version="1.11.1", description="pytest plugin for writing tests for mypy plugins", long_description=readme, long_description_content_type="text/markdown",