Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/setuptools/warnings.py @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 """Provide basic warnings used by setuptools modules. | |
2 | |
3 Using custom classes (other than ``UserWarning``) allow users to set | |
4 ``PYTHONWARNINGS`` filters to run tests and prepare for upcoming changes in | |
5 setuptools. | |
6 """ | |
7 | |
8 from __future__ import annotations | |
9 | |
10 import os | |
11 import warnings | |
12 from datetime import date | |
13 from inspect import cleandoc | |
14 from textwrap import indent | |
15 from typing import TYPE_CHECKING, Tuple | |
16 | |
17 if TYPE_CHECKING: | |
18 from typing_extensions import TypeAlias | |
19 | |
20 _DueDate: TypeAlias = Tuple[int, int, int] # time tuple | |
21 _INDENT = 8 * " " | |
22 _TEMPLATE = f"""{80 * '*'}\n{{details}}\n{80 * '*'}""" | |
23 | |
24 | |
25 class SetuptoolsWarning(UserWarning): | |
26 """Base class in ``setuptools`` warning hierarchy.""" | |
27 | |
28 @classmethod | |
29 def emit( | |
30 cls, | |
31 summary: str | None = None, | |
32 details: str | None = None, | |
33 due_date: _DueDate | None = None, | |
34 see_docs: str | None = None, | |
35 see_url: str | None = None, | |
36 stacklevel: int = 2, | |
37 **kwargs, | |
38 ) -> None: | |
39 """Private: reserved for ``setuptools`` internal use only""" | |
40 # Default values: | |
41 summary_ = summary or getattr(cls, "_SUMMARY", None) or "" | |
42 details_ = details or getattr(cls, "_DETAILS", None) or "" | |
43 due_date = due_date or getattr(cls, "_DUE_DATE", None) | |
44 docs_ref = see_docs or getattr(cls, "_SEE_DOCS", None) | |
45 docs_url = docs_ref and f"https://setuptools.pypa.io/en/latest/{docs_ref}" | |
46 see_url = see_url or getattr(cls, "_SEE_URL", None) | |
47 due = date(*due_date) if due_date else None | |
48 | |
49 text = cls._format(summary_, details_, due, see_url or docs_url, kwargs) | |
50 if due and due < date.today() and _should_enforce(): | |
51 raise cls(text) | |
52 warnings.warn(text, cls, stacklevel=stacklevel + 1) | |
53 | |
54 @classmethod | |
55 def _format( | |
56 cls, | |
57 summary: str, | |
58 details: str, | |
59 due_date: date | None = None, | |
60 see_url: str | None = None, | |
61 format_args: dict | None = None, | |
62 ) -> str: | |
63 """Private: reserved for ``setuptools`` internal use only""" | |
64 today = date.today() | |
65 summary = cleandoc(summary).format_map(format_args or {}) | |
66 possible_parts = [ | |
67 cleandoc(details).format_map(format_args or {}), | |
68 ( | |
69 f"\nBy {due_date:%Y-%b-%d}, you need to update your project and remove " | |
70 "deprecated calls\nor your builds will no longer be supported." | |
71 if due_date and due_date > today | |
72 else None | |
73 ), | |
74 ( | |
75 "\nThis deprecation is overdue, please update your project and remove " | |
76 "deprecated\ncalls to avoid build errors in the future." | |
77 if due_date and due_date < today | |
78 else None | |
79 ), | |
80 (f"\nSee {see_url} for details." if see_url else None), | |
81 ] | |
82 parts = [x for x in possible_parts if x] | |
83 if parts: | |
84 body = indent(_TEMPLATE.format(details="\n".join(parts)), _INDENT) | |
85 return "\n".join([summary, "!!\n", body, "\n!!"]) | |
86 return summary | |
87 | |
88 | |
89 class InformationOnly(SetuptoolsWarning): | |
90 """Currently there is no clear way of displaying messages to the users | |
91 that use the setuptools backend directly via ``pip``. | |
92 The only thing that might work is a warning, although it is not the | |
93 most appropriate tool for the job... | |
94 | |
95 See pypa/packaging-problems#558. | |
96 """ | |
97 | |
98 | |
99 class SetuptoolsDeprecationWarning(SetuptoolsWarning): | |
100 """ | |
101 Base class for warning deprecations in ``setuptools`` | |
102 | |
103 This class is not derived from ``DeprecationWarning``, and as such is | |
104 visible by default. | |
105 """ | |
106 | |
107 | |
108 def _should_enforce(): | |
109 enforce = os.getenv("SETUPTOOLS_ENFORCE_DEPRECATION", "false").lower() | |
110 return enforce in ("true", "on", "ok", "1") |