From 35d58fcb2b23a3f14263e06b5cbb29119cc3c954 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Wed, 5 Feb 2025 09:50:35 +0100 Subject: [PATCH 1/3] Add setup.py to selfcheck. Enhance the setup.py types. mypy's setup.py is used as inspiration for other setuptools using Python projects that want to produce mypyc compiled binary wheels. Therefore it should also be typechecked and held to a higher standard. --- runtests.py | 12 ++++-------- setup.py | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/runtests.py b/runtests.py index 9863e84915004..eee632ed48f8c 100755 --- a/runtests.py +++ b/runtests.py @@ -56,14 +56,10 @@ # Self type check "self": [ executable, - "-m", - "mypy", - "--config-file", - "mypy_self_check.ini", - "-p", - "mypy", - "-p", - "mypyc", + "-c", + "from mypy.main import main as mypy; " + "mypy(args=['--config-file', 'mypy_self_check.ini', '-p', 'mypy', '-p', 'mypyc']); " + "mypy(args=['--config-file', 'mypy_self_check.ini', 'setup.py'])" ], # Lint "lint": ["pre-commit", "run", "--all-files"], diff --git a/setup.py b/setup.py index e995068b4c5d1..12cc1aad4d724 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def is_list_of_setuptools_extension(items: list[Any]) -> TypeGuard[list[Extensio return all(isinstance(item, Extension) for item in items) -def find_package_data(base, globs, root="mypy"): +def find_package_data(base: str, globs: list[str], root: str = "mypy") -> list[str]: """Find all interesting data files, for setup(package_data=) Arguments: @@ -52,13 +52,13 @@ def find_package_data(base, globs, root="mypy"): class CustomPythonBuild(build_py): - def pin_version(self): + def pin_version(self) -> None: path = os.path.join(self.build_lib, "mypy") self.mkpath(path) with open(os.path.join(path, "version.py"), "w") as stream: stream.write(f'__version__ = "{version}"\n') - def run(self): + def run(self) -> None: self.execute(self.pin_version, ()) build_py.run(self) @@ -153,10 +153,10 @@ def run(self): # our Appveyor builds run out of memory sometimes. multi_file=sys.platform == "win32" or force_multifile, ) - assert is_list_of_setuptools_extension(ext_modules), "Expected mypycify to use setuptools" else: ext_modules = [] +assert is_list_of_setuptools_extension(ext_modules), "Expected mypycify to use setuptools" setup(version=version, ext_modules=ext_modules, cmdclass=cmdclass) From 72e1ff81760a6e50a2acba2d2a262ad409afdc25 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Feb 2025 08:57:10 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- runtests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtests.py b/runtests.py index eee632ed48f8c..511cd472975da 100755 --- a/runtests.py +++ b/runtests.py @@ -59,7 +59,7 @@ "-c", "from mypy.main import main as mypy; " "mypy(args=['--config-file', 'mypy_self_check.ini', '-p', 'mypy', '-p', 'mypyc']); " - "mypy(args=['--config-file', 'mypy_self_check.ini', 'setup.py'])" + "mypy(args=['--config-file', 'mypy_self_check.ini', 'setup.py'])", ], # Lint "lint": ["pre-commit", "run", "--all-files"], From a201e66a2e0da6426eac0cbea39795659d7abd0e Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Thu, 6 Feb 2025 12:42:35 +0100 Subject: [PATCH 3/3] split out the packaging test from the general self type check as per https://github.com/python/mypy/pull/18609#discussion_r1943890977 --- runtests.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/runtests.py b/runtests.py index 511cd472975da..75389c6c56bb0 100755 --- a/runtests.py +++ b/runtests.py @@ -56,10 +56,23 @@ # Self type check "self": [ executable, - "-c", - "from mypy.main import main as mypy; " - "mypy(args=['--config-file', 'mypy_self_check.ini', '-p', 'mypy', '-p', 'mypyc']); " - "mypy(args=['--config-file', 'mypy_self_check.ini', 'setup.py'])", + "-m", + "mypy", + "--config-file", + "mypy_self_check.ini", + "-p", + "mypy", + "-p", + "mypyc", + ], + # Type check setup.py as well + "self-packaging": [ + executable, + "-m", + "mypy", + "--config-file", + "mypy_self_check.ini", + "setup.py", ], # Lint "lint": ["pre-commit", "run", "--all-files"],