diff --git a/packaging/pep517_backend/_compat.py b/packaging/pep517_backend/_compat.py index 79859e6d..5e2ffe09 100644 --- a/packaging/pep517_backend/_compat.py +++ b/packaging/pep517_backend/_compat.py @@ -20,4 +20,10 @@ def chdir_cm(path: os.PathLike) -> t.Iterator[None]: os.chdir(original_wd) -__all__ = ("chdir_cm",) # noqa: WPS410 +try: + from tomllib import loads as load_toml_from_string +except ImportError: + from tomli import loads as load_toml_from_string # type: ignore[no-redef] + + +__all__ = ("chdir_cm", "load_toml_from_string") # noqa: WPS410 diff --git a/packaging/pep517_backend/_cython_configuration.py b/packaging/pep517_backend/_cython_configuration.py index 040fe4f7..316b85fc 100644 --- a/packaging/pep517_backend/_cython_configuration.py +++ b/packaging/pep517_backend/_cython_configuration.py @@ -9,11 +9,7 @@ from expandvars import expandvars -try: - from tomllib import loads as _load_toml_from_string -except ImportError: - from tomli import loads as _load_toml_from_string # type: ignore[no-redef] - +from ._compat import load_toml_from_string # noqa: WPS436 from ._transformers import ( # noqa: WPS436 get_cli_kwargs_from_config, get_enabled_cli_flags_from_config, @@ -73,7 +69,7 @@ def get_local_cython_config() -> dict: # NAME = "VALUE" """ config_toml_txt = (Path.cwd().resolve() / 'pyproject.toml').read_text() - config_mapping = _load_toml_from_string(config_toml_txt) + config_mapping = load_toml_from_string(config_toml_txt) return config_mapping['tool']['local']['cythonize']