setuptools_frontend.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from __future__ import annotations
  2. from babel.messages import frontend
  3. try:
  4. # See: https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html
  5. from setuptools import Command
  6. try:
  7. from setuptools.errors import BaseError, OptionError, SetupError
  8. except ImportError: # Error aliases only added in setuptools 59 (2021-11).
  9. OptionError = SetupError = BaseError = Exception
  10. except ImportError:
  11. from distutils.cmd import Command
  12. from distutils.errors import DistutilsSetupError as SetupError
  13. def check_message_extractors(dist, name, value):
  14. """Validate the ``message_extractors`` keyword argument to ``setup()``.
  15. :param dist: the distutils/setuptools ``Distribution`` object
  16. :param name: the name of the keyword argument (should always be
  17. "message_extractors")
  18. :param value: the value of the keyword argument
  19. :raise `DistutilsSetupError`: if the value is not valid
  20. """
  21. assert name == "message_extractors"
  22. if not isinstance(value, dict):
  23. raise SetupError(
  24. 'the value of the "message_extractors" parameter must be a dictionary',
  25. )
  26. class compile_catalog(frontend.CompileCatalog, Command):
  27. """Catalog compilation command for use in ``setup.py`` scripts.
  28. If correctly installed, this command is available to Setuptools-using
  29. setup scripts automatically. For projects using plain old ``distutils``,
  30. the command needs to be registered explicitly in ``setup.py``::
  31. from babel.messages.setuptools_frontend import compile_catalog
  32. setup(
  33. ...
  34. cmdclass = {'compile_catalog': compile_catalog}
  35. )
  36. .. versionadded:: 0.9
  37. """
  38. class extract_messages(frontend.ExtractMessages, Command):
  39. """Message extraction command for use in ``setup.py`` scripts.
  40. If correctly installed, this command is available to Setuptools-using
  41. setup scripts automatically. For projects using plain old ``distutils``,
  42. the command needs to be registered explicitly in ``setup.py``::
  43. from babel.messages.setuptools_frontend import extract_messages
  44. setup(
  45. ...
  46. cmdclass = {'extract_messages': extract_messages}
  47. )
  48. """
  49. class init_catalog(frontend.InitCatalog, Command):
  50. """New catalog initialization command for use in ``setup.py`` scripts.
  51. If correctly installed, this command is available to Setuptools-using
  52. setup scripts automatically. For projects using plain old ``distutils``,
  53. the command needs to be registered explicitly in ``setup.py``::
  54. from babel.messages.setuptools_frontend import init_catalog
  55. setup(
  56. ...
  57. cmdclass = {'init_catalog': init_catalog}
  58. )
  59. """
  60. class update_catalog(frontend.UpdateCatalog, Command):
  61. """Catalog merging command for use in ``setup.py`` scripts.
  62. If correctly installed, this command is available to Setuptools-using
  63. setup scripts automatically. For projects using plain old ``distutils``,
  64. the command needs to be registered explicitly in ``setup.py``::
  65. from babel.messages.setuptools_frontend import update_catalog
  66. setup(
  67. ...
  68. cmdclass = {'update_catalog': update_catalog}
  69. )
  70. .. versionadded:: 0.9
  71. """
  72. COMMANDS = {
  73. "compile_catalog": compile_catalog,
  74. "extract_messages": extract_messages,
  75. "init_catalog": init_catalog,
  76. "update_catalog": update_catalog,
  77. }