Debian Codegraph @

babel/messages/setuptools_frontend.py

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