|
10 | 10 | import sys |
11 | 11 | import typing as t |
12 | 12 | from fnmatch import fnmatchcase |
13 | | -from importlib.util import find_spec |
14 | 13 | from pathlib import Path |
15 | 14 |
|
16 | 15 | import setuptools |
17 | 16 | from setuptools.command.egg_info import egg_info |
18 | 17 |
|
| 18 | +from plux.build import config |
| 19 | + |
19 | 20 | try: |
20 | 21 | from setuptools.command.editable_wheel import editable_wheel |
21 | 22 | except ImportError: |
@@ -61,7 +62,7 @@ def finalize_options(self) -> None: |
61 | 62 | # we merge the configuration from the CLI arguments with the configuration read from the `pyproject.toml` |
62 | 63 | # [tool.plux] section |
63 | 64 | project_config = read_plux_configuration(self.distribution) |
64 | | - file_exclude = project_config.get("exclude") |
| 65 | + file_exclude = project_config.exclude |
65 | 66 | if file_exclude: |
66 | 67 | self.exclude = set(self.exclude) | set(file_exclude) |
67 | 68 | self.exclude = [_path_to_module(item) for item in self.exclude] |
@@ -198,43 +199,28 @@ def load_plux_entrypoints(cmd, file_name, file_path): |
198 | 199 | write_entries(cmd, ep_file, ep_path) |
199 | 200 |
|
200 | 201 |
|
201 | | -def get_plux_json_path(distribution): |
| 202 | +def get_plux_json_path(distribution: setuptools.Distribution) -> str: |
202 | 203 | dirs = distribution.package_dir |
203 | 204 | egg_base = (dirs or {}).get("", os.curdir) |
204 | 205 | egg_info_dir = _to_filename(_safe_name(distribution.get_name())) + ".egg-info" |
205 | 206 | egg_info_dir = os.path.join(egg_base, egg_info_dir) |
206 | 207 | return os.path.join(egg_info_dir, "plux.json") |
207 | 208 |
|
208 | 209 |
|
209 | | -def read_plux_configuration(distribution) -> dict: |
| 210 | +def read_plux_configuration(distribution) -> config.PluxConfiguration: |
210 | 211 | """ |
211 | | - Try reading the [tool.plux] section of the `pyproject.toml` TOML file of the Distribution, and returns it as a |
212 | | - dictionary. |
| 212 | + Try reading the [tool.plux] section of the `pyproject.toml` TOML file of the Distribution, and parse it using our |
| 213 | + config parser. |
213 | 214 | """ |
214 | | - if find_spec("tomllib"): |
215 | | - # the tomllib library is part of the standard library since 3.11 |
216 | | - from tomllib import load as load_toml |
217 | | - elif find_spec("tomli"): |
218 | | - # setuptools vendors the tomli library in 3.10 |
219 | | - from tomli import load as load_toml |
220 | | - else: |
221 | | - # if we cannot find a TOML lib, we do not return any configuration |
222 | | - return {} |
223 | | - |
224 | 215 | dirs = distribution.package_dir |
225 | 216 | pyproject_base = (dirs or {}).get("", os.curdir) |
226 | 217 | pyproject_file = os.path.join(pyproject_base, "pyproject.toml") |
227 | 218 | if not os.path.exists(pyproject_file): |
228 | | - return {} |
229 | | - |
230 | | - with open(pyproject_file, "rb") as file: |
231 | | - pyproject_config = load_toml(file) |
232 | | - |
233 | | - tool_table = pyproject_config.get("tool", {}) |
234 | | - return tool_table.get("plux", {}) |
| 219 | + return config.PluxConfiguration() |
235 | 220 |
|
| 221 | + return config.parse_pyproject_toml(pyproject_file) |
236 | 222 |
|
237 | | -def update_entrypoints(distribution, ep: EntryPointDict): |
| 223 | +def update_entrypoints(distribution: setuptools.Distribution, ep: EntryPointDict): |
238 | 224 | if distribution.entry_points is None: |
239 | 225 | distribution.entry_points = {} |
240 | 226 |
|
|
0 commit comments