Skip to content

Commit 3b1051a

Browse files
committed
Implement ext-modules from pyproject.toml
1 parent b1b9f0f commit 3b1051a

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

setuptools/config/_apply_pyprojecttoml.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
from inspect import cleandoc
1818
from itertools import chain
1919
from types import MappingProxyType
20-
from typing import TYPE_CHECKING, Any, Callable, Dict, Mapping, Union
20+
from typing import TYPE_CHECKING, Any, Callable, Dict, Mapping, TypeVar, Union
2121

2222
from .._path import StrPath
2323
from ..errors import RemovedConfigError
24+
from ..extension import Extension
2425
from ..warnings import SetuptoolsWarning
2526

2627
if TYPE_CHECKING:
@@ -35,6 +36,7 @@
3536
_ProjectReadmeValue: TypeAlias = Union[str, Dict[str, str]]
3637
_CorrespFn: TypeAlias = Callable[["Distribution", Any, StrPath], None]
3738
_Correspondence: TypeAlias = Union[str, _CorrespFn]
39+
_T = TypeVar("_T")
3840

3941
_logger = logging.getLogger(__name__)
4042

@@ -117,13 +119,14 @@ def json_compatible_key(key: str) -> str:
117119

118120

119121
def _set_config(dist: Distribution, field: str, value: Any):
122+
val = _PREPROCESS.get(field, _noop)(dist, value)
120123
setter = getattr(dist.metadata, f"set_{field}", None)
121124
if setter:
122-
setter(value)
125+
setter(val)
123126
elif hasattr(dist.metadata, field) or field in SETUPTOOLS_PATCHES:
124-
setattr(dist.metadata, field, value)
127+
setattr(dist.metadata, field, val)
125128
else:
126-
setattr(dist, field, value)
129+
setattr(dist, field, val)
127130

128131

129132
_CONTENT_TYPES = {
@@ -218,6 +221,17 @@ def _optional_dependencies(dist: Distribution, val: dict, _root_dir):
218221
dist.extras_require = {**existing, **val}
219222

220223

224+
def _ext_modules(dist: Distribution, val: list[dict]) -> list[Extension]:
225+
existing = dist.ext_modules or []
226+
args = ({k.replace("-", "_"): v for k, v in x.items()} for x in val)
227+
new = [Extension(**kw) for kw in args]
228+
return [*existing, *new]
229+
230+
231+
def _noop(_dist: Distribution, val: _T) -> _T:
232+
return val
233+
234+
221235
def _unify_entry_points(project_table: dict):
222236
project = project_table
223237
entry_points = project.pop("entry-points", project.pop("entry_points", {}))
@@ -376,6 +390,10 @@ def _acessor(obj):
376390
"license_files",
377391
}
378392

393+
_PREPROCESS = {
394+
"ext_modules": _ext_modules,
395+
}
396+
379397
_PREVIOUSLY_DEFINED = {
380398
"name": _attrgetter("metadata.name"),
381399
"version": _attrgetter("metadata.version"),

0 commit comments

Comments
 (0)