|
3 | 3 | import warnings |
4 | 4 | from functools import partial, reduce |
5 | 5 | from itertools import chain, zip_longest |
6 | | -from typing import ( |
7 | | - Any, |
8 | | - Dict, |
9 | | - List, |
10 | | - Mapping, |
11 | | - Optional, |
12 | | - Sequence, |
13 | | - Set, |
14 | | - Tuple, |
15 | | - Type, |
16 | | - TypeVar, |
17 | | - Union, |
18 | | - cast, |
19 | | -) |
| 6 | +from typing import Any, Dict, List, Mapping, Sequence, Set, Tuple, Type, TypeVar, Union |
20 | 7 |
|
21 | 8 | try: |
22 | 9 | from packaging.requirements import Requirement |
|
86 | 73 | "bdist_wheel", |
87 | 74 | *getattr(distutils_commands, "__all__", []), |
88 | 75 | ) |
89 | | -DEFAULT_LICENSE_FILES = ("LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*") |
90 | | -# defaults from the `wheel` package |
91 | 76 |
|
92 | 77 |
|
93 | 78 | def activate(translator: Translator): |
@@ -152,8 +137,8 @@ def processing_rules(self) -> ProcessingRules: |
152 | 137 | # `merge_and_rename_long_description_and_content_type` |
153 | 138 | # --- |
154 | 139 | ("metadata", "license-files"): split_list_comma, |
155 | | - # => NOTICE: in PEP 621, it should be a single file |
156 | | - # further processed via `handle_license_and_files` |
| 140 | + # => NOTICE: not standard for now, needs PEP 639 |
| 141 | + # further processed via `remove_metadata_not_in_pep621` |
157 | 142 | # --- |
158 | 143 | ("metadata", "url"): split_url, |
159 | 144 | ("metadata", "download-url"): split_url, |
@@ -341,50 +326,20 @@ def merge_and_rename_long_description_and_content_type(self, doc: R) -> R: |
341 | 326 | metadata.rename("long-description", "readme") |
342 | 327 | return doc |
343 | 328 |
|
344 | | - def handle_license_and_files(self, doc: R) -> R: |
345 | | - """In :pep:`621` we have a single field for license, which might have a single |
346 | | - value (file path) or a dict-like structure:: |
347 | | -
|
348 | | - license-files => license.file |
349 | | - license => license.text |
| 329 | + def handle_license(self, doc: R) -> R: |
| 330 | + """In :pep:`621` we have a single field for license, which is not compatible |
| 331 | + with setuptools ``license-files``. |
| 332 | + This field is meant to fill the ``License`` core metadata as a plain license |
| 333 | + text (not a path to a file). Even when the ``project.license.file`` table field |
| 334 | + is given, the idea is that the file should be expanded into text. |
350 | 335 |
|
351 | | - We also have to be aware that :pep:`621` accepts a single file, so the option of |
352 | | - combining multiple files as presented in ``setup.cfg`` have to be handled via |
353 | | - ``dynamic``. |
| 336 | + This will likely change once :pep:`639` is accepted. |
| 337 | + Meanwhile we have to translate ``license-files`` into a setuptools specific |
| 338 | + configuration. |
354 | 339 | """ |
355 | 340 | metadata: IR = doc["metadata"] |
356 | | - files: Optional[CommentedList[str]] = metadata.get("license-files") |
357 | | - # Setuptools automatically includes license files if not present |
358 | | - # so let's make it dynamic |
359 | | - files_as_list = (files and files.as_list()) or list(DEFAULT_LICENSE_FILES) |
360 | | - text = metadata.get("license") |
361 | | - |
362 | | - # PEP 621 specifies a single "file". If there is more, we need to use "dynamic" |
363 | | - if files_as_list and ( |
364 | | - len(files_as_list) > 1 |
365 | | - or any(char in files_as_list[0] for char in "*?[") # glob pattern |
366 | | - or text # PEP 621 forbids both license and license-files at the same time |
367 | | - ): |
368 | | - metadata.setdefault("dynamic", []).append("license") |
369 | | - dynamic = doc.setdefault("options.dynamic", IR()) |
370 | | - if text: |
371 | | - dynamic.append("license", text) |
372 | | - dynamic.append("license-files", files_as_list) |
373 | | - # 'file' and 'text' are mutually exclusive in PEP 621 |
374 | | - metadata.pop("license", None) |
375 | | - metadata.pop("license-files", None) |
376 | | - return doc |
377 | | - |
378 | | - if files_as_list: |
379 | | - files = cast(CommentedList[str], files) |
380 | | - license = IR(file=Commented(files_as_list[0], files[0].comment)) |
381 | | - elif text: |
382 | | - license = IR(text=metadata["license"]) |
383 | | - else: |
384 | | - return doc |
385 | | - |
386 | | - fields = ("license-files", "license") |
387 | | - metadata.replace_first_remove_others(fields, "license", license) |
| 341 | + if "license" in metadata: |
| 342 | + metadata.rename("license", ("license", "text")) |
388 | 343 | return doc |
389 | 344 |
|
390 | 345 | def move_and_split_entrypoints(self, doc: R) -> R: |
@@ -438,9 +393,14 @@ def remove_metadata_not_in_pep621(self, doc: R) -> R: |
438 | 393 | """:pep:`621` does not cover all project metadata in ``setup.cfg "metadata"`` |
439 | 394 | section. That is left as "tool" specific configuration. |
440 | 395 | """ |
441 | | - specific = ["platforms", "provides", "obsoletes"] |
442 | | - metadata, options = doc["metadata"], doc["options"] |
443 | | - options.update({k: metadata.pop(k) for k in specific if k in metadata}) |
| 396 | + # TODO: PEP 621 does not specify an equivalent for 'License-file' metadata, |
| 397 | + # but once PEP 639 is approved this will change |
| 398 | + metadata = doc.get("metadata", IR()) |
| 399 | + non_standard = ("platforms", "provides", "obsoletes", "license-files") |
| 400 | + specific = [k for k in non_standard if k in metadata] |
| 401 | + if specific: |
| 402 | + options = doc.setdefault("options", IR()) |
| 403 | + options.update({k: metadata.pop(k) for k in specific}) |
444 | 404 | return doc |
445 | 405 |
|
446 | 406 | def rename_script_files(self, doc: R) -> R: |
@@ -665,7 +625,7 @@ def pep621_transform(self, doc: R) -> R: |
665 | 625 | self.merge_and_rename_urls, |
666 | 626 | self.merge_authors_maintainers_and_emails, |
667 | 627 | self.merge_and_rename_long_description_and_content_type, |
668 | | - self.handle_license_and_files, |
| 628 | + self.handle_license, |
669 | 629 | self.move_and_split_entrypoints, |
670 | 630 | self.move_options_missing_in_pep621, |
671 | 631 | self.remove_metadata_not_in_pep621, |
|
0 commit comments