|
20 | 20 | import textwrap
|
21 | 21 | import time
|
22 | 22 | import warnings
|
| 23 | +from functools import cache |
23 | 24 | from io import BytesIO, StringIO
|
24 | 25 | from typing import TYPE_CHECKING, Callable, Optional, Protocol, cast
|
25 | 26 |
|
@@ -270,6 +271,14 @@ def _get_ext_suffix():
|
270 | 271 | return dist_suffix
|
271 | 272 |
|
272 | 273 |
|
| 274 | +@cache |
| 275 | +def add_gcc_dll_directory() -> None: |
| 276 | + if (sys.platform == "win32") & (hasattr(os, "add_dll_directory")): |
| 277 | + gcc_path = shutil.which("gcc") |
| 278 | + if gcc_path is not None: |
| 279 | + os.add_dll_directory(os.path.dirname(gcc_path)) # type: ignore |
| 280 | + |
| 281 | + |
273 | 282 | def dlimport(fullpath, suffix=None):
|
274 | 283 | """
|
275 | 284 | Dynamically load a .so, .pyd, .dll, or .py file.
|
@@ -319,11 +328,7 @@ def dlimport(fullpath, suffix=None):
|
319 | 328 | _logger.debug(f"module_name {module_name}")
|
320 | 329 |
|
321 | 330 | sys.path[0:0] = [workdir] # insert workdir at beginning (temporarily)
|
322 |
| - # Explicitly add gcc dll directory on Python 3.8+ on Windows |
323 |
| - if (sys.platform == "win32") & (hasattr(os, "add_dll_directory")): |
324 |
| - gcc_path = shutil.which("gcc") |
325 |
| - if gcc_path is not None: |
326 |
| - os.add_dll_directory(os.path.dirname(gcc_path)) |
| 331 | + add_gcc_dll_directory() |
327 | 332 | global import_time
|
328 | 333 | try:
|
329 | 334 | importlib.invalidate_caches()
|
|
0 commit comments