Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support next types-setuptools update #14781

Merged
merged 4 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import re
import sys
import time
from typing import TYPE_CHECKING, Any, Dict, Iterable, NoReturn, cast
from typing import TYPE_CHECKING, Any, Dict, Iterable, NoReturn, Union, cast

from mypy.build import BuildSource
from mypy.errors import CompileError
Expand All @@ -41,7 +41,13 @@
from mypyc.options import CompilerOptions

if TYPE_CHECKING:
from distutils.core import Extension
from distutils.core import Extension as _distutils_Extension
from typing_extensions import TypeAlias

from setuptools import Extension as _setuptools_Extension

Extension: TypeAlias = Union[_setuptools_Extension, _distutils_Extension]


try:
# Import setuptools so that it monkey-patch overrides distutils
Expand Down
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import os.path
import sys
from typing import TYPE_CHECKING, Any

if sys.version_info < (3, 7, 0):
sys.stderr.write("ERROR: You need Python 3.7 or later to use mypy.\n")
Expand All @@ -17,11 +18,14 @@
# This requires setuptools when building; setuptools is not needed
# when installing from a wheel file (though it is still needed for
# alternative forms of installing, as suggested by README.md).
from setuptools import find_packages, setup
from setuptools import Extension, find_packages, setup
from setuptools.command.build_py import build_py

from mypy.version import __version__ as version

if TYPE_CHECKING:
from typing_extensions import TypeGuard

description = "Optional static typing for Python"
long_description = """
Mypy -- Optional Static Typing for Python
Expand All @@ -36,6 +40,10 @@
""".lstrip()


def is_list_of_setuptools_extension(items: list[Any]) -> TypeGuard[list[Extension]]:
return all(isinstance(item, Extension) for item in items)


def find_package_data(base, globs, root="mypy"):
"""Find all interesting data files, for setup(package_data=)

Expand Down Expand Up @@ -166,6 +174,8 @@ 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 = []

Expand Down