Avoid calling setup.py in the extract_messages command

The setup.py has been deprecated in Python for quite a while, and it has
been generating a lot of warnings. We can avoid it completely, together
with the shell call, by calling the babel functions directly.

I'm also moving the extractor settings from pyproject.toml to the
relevant babel-*.cfg files, to keep everything together.

Signed-off-by: Radomir Dopieralski <openstack@dopieralski.pl>
Change-Id: Ie0616b5f2a96cf8560135e5f6849c737aa9b88d0
This commit is contained in:
Radomir Dopieralski
2026-04-30 10:46:27 +02:00
parent a0def88689
commit 63ed6a1d6b
4 changed files with 16 additions and 23 deletions
+2
View File
@@ -1,3 +1,5 @@
[python: **.py]
[django: **/templates/**.html]
[django: **/templates/**.csv]
[extractors]
django = horizon.utils.babel_extract_django:extract_django
+2
View File
@@ -5,3 +5,5 @@
# /openstack_dashboard/dashboards/XYZ/static which will ensure
# that plugins are also translated.
[angular: **/static/**.html]
[extractors]
angular = horizon.utils.babel_extract_angular:extract_angular
@@ -13,10 +13,9 @@
# limitations under the License.
import os
from subprocess import call
from babel.messages.frontend import CommandLineInterface
from django.core.management.base import BaseCommand
from setuptools.dist import Distribution
DOMAINS = ['django', 'djangojs']
@@ -44,17 +43,6 @@ class Command(BaseCommand):
"polluting the source code"))
def handle(self, *args, **options):
cmd = ('python setup.py {quiet} extract_messages '
'-F babel-{domain}.cfg '
'--input-dirs {module} '
'-o {potfile}')
distribution = Distribution()
distribution.parse_config_files(distribution.find_config_files())
quiet = '-q' if int(options['verbosity']) == 0 else ''
if options['check_only']:
cmd += " ; rm {potfile}"
for module in options['module']:
for domain in options['domain']:
potfile = '{module}/locale/{domain}.pot'.format(module=module,
@@ -62,6 +50,14 @@ class Command(BaseCommand):
if not os.path.exists(potfile):
with open(potfile, 'wb') as f:
f.write(b'')
call(cmd.format(module=module, domain=domain, potfile=potfile,
quiet=quiet), shell=True)
command = [
'pybabel', 'extract',
'-F', f'babel-{domain}.cfg',
'--input-dirs', module,
'-o', potfile,
]
if int(options['verbosity']) == 0:
command.insert(1, '-q')
CommandLineInterface().run(command)
if options['check_only']:
os.remove(potfile)
-7
View File
@@ -36,13 +36,6 @@ classifiers = [
openstack_dashboard = "openstack_dashboard.utils.config:list_options"
openstack_dashboard_integration_tests = "openstack_dashboard.test.integration_tests.config:list_opts"
[project.entry-points."babel.extractors"]
# We use a custom extractor to find translatable strings in AngularJS templates.
# See https://babel.pocoo.org/en/latest/messages.html#referencing-extraction-methods
# for details on how this works.
angular = "horizon.utils.babel_extract_angular:extract_angular"
django = "horizon.utils.babel_extract_django:extract_django"
[project.urls]
Homepage = "https://docs.openstack.org/horizon"
Repository = "https://opendev.org/openstack/horizon/"