Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

111 linhas
3.7 KiB

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