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

Avoid importing from setuptools._distutils #16348

Merged
merged 1 commit into from
Oct 28, 2023
Merged
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
31 changes: 14 additions & 17 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,28 @@
from mypyc.namegen import exported_name
from mypyc.options import CompilerOptions

if sys.version_info < (3, 12):
if TYPE_CHECKING:
try:
# Import setuptools so that it monkey-patch overrides distutils
import setuptools
except ImportError:
pass

if TYPE_CHECKING:
if sys.version_info >= (3, 12):
from setuptools import Extension
else:
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
import setuptools
except ImportError:
pass
from distutils import ccompiler, sysconfig
if sys.version_info >= (3, 12):
# From setuptools' monkeypatch
from distutils import ccompiler, sysconfig # type: ignore[import-not-found]
else:
import setuptools
from setuptools import Extension
from setuptools._distutils import (
ccompiler as _ccompiler, # type: ignore[attr-defined]
sysconfig as _sysconfig, # type: ignore[attr-defined]
)

ccompiler = _ccompiler
sysconfig = _sysconfig
from distutils import ccompiler, sysconfig


def get_extension() -> type[Extension]:
Expand Down