Skip to content

Commit

Permalink
Avoid importing from setuptools._distutils (#16348)
Browse files Browse the repository at this point in the history
Fixes #16318, as requested by setuptools maintainer
  • Loading branch information
hauntsaninja authored Oct 28, 2023
1 parent c76132f commit 2aa2443
Showing 1 changed file with 14 additions and 17 deletions.
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

0 comments on commit 2aa2443

Please sign in to comment.