Skip to content

Commit

Permalink
Add setup.py to selfcheck.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mr-c committed Feb 5, 2025
1 parent 88d6890 commit 35d58fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 4 additions & 8 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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)

0 comments on commit 35d58fc

Please sign in to comment.