|
17 | 17 | from inspect import cleandoc
|
18 | 18 | from itertools import chain
|
19 | 19 | 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 |
21 | 21 |
|
22 | 22 | from .._path import StrPath
|
23 | 23 | from ..errors import RemovedConfigError
|
| 24 | +from ..extension import Extension |
24 | 25 | from ..warnings import SetuptoolsWarning
|
25 | 26 |
|
26 | 27 | if TYPE_CHECKING:
|
|
35 | 36 | _ProjectReadmeValue: TypeAlias = Union[str, Dict[str, str]]
|
36 | 37 | _CorrespFn: TypeAlias = Callable[["Distribution", Any, StrPath], None]
|
37 | 38 | _Correspondence: TypeAlias = Union[str, _CorrespFn]
|
| 39 | +_T = TypeVar("_T") |
38 | 40 |
|
39 | 41 | _logger = logging.getLogger(__name__)
|
40 | 42 |
|
@@ -117,13 +119,14 @@ def json_compatible_key(key: str) -> str:
|
117 | 119 |
|
118 | 120 |
|
119 | 121 | def _set_config(dist: Distribution, field: str, value: Any):
|
| 122 | + val = _PREPROCESS.get(field, _noop)(dist, value) |
120 | 123 | setter = getattr(dist.metadata, f"set_{field}", None)
|
121 | 124 | if setter:
|
122 |
| - setter(value) |
| 125 | + setter(val) |
123 | 126 | elif hasattr(dist.metadata, field) or field in SETUPTOOLS_PATCHES:
|
124 |
| - setattr(dist.metadata, field, value) |
| 127 | + setattr(dist.metadata, field, val) |
125 | 128 | else:
|
126 |
| - setattr(dist, field, value) |
| 129 | + setattr(dist, field, val) |
127 | 130 |
|
128 | 131 |
|
129 | 132 | _CONTENT_TYPES = {
|
@@ -218,6 +221,17 @@ def _optional_dependencies(dist: Distribution, val: dict, _root_dir):
|
218 | 221 | dist.extras_require = {**existing, **val}
|
219 | 222 |
|
220 | 223 |
|
| 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 | + |
221 | 235 | def _unify_entry_points(project_table: dict):
|
222 | 236 | project = project_table
|
223 | 237 | entry_points = project.pop("entry-points", project.pop("entry_points", {}))
|
@@ -376,6 +390,10 @@ def _acessor(obj):
|
376 | 390 | "license_files",
|
377 | 391 | }
|
378 | 392 |
|
| 393 | +_PREPROCESS = { |
| 394 | + "ext_modules": _ext_modules, |
| 395 | +} |
| 396 | + |
379 | 397 | _PREVIOUSLY_DEFINED = {
|
380 | 398 | "name": _attrgetter("metadata.name"),
|
381 | 399 | "version": _attrgetter("metadata.version"),
|
|
0 commit comments