Skip to content

option --init-missing of pybabel update should also create the corresponding directory #1139

@du33169

Description

@du33169

I use the option --init-missing of pybabel update to avoid redundant pybabel init command. However, this option only creates the *.po file, and will fail if the target directory ([locale]/LC_MESSAGES) does not exist yet:

creating catalog .\en_US\LC_MESSAGES\strings.po based on strings.pot
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "...\.venv\Scripts\pybabel.exe\__main__.py", line 8, in <module>
  File "...\.venv\Lib\site-packages\babel\messages\frontend.py", line 999, in main
    return CommandLineInterface().run(sys.argv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\babel\messages\frontend.py", line 925, in run
    return cmdinst.run()
           ^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\babel\messages\frontend.py", line 795, in run
    with open(filename, 'wb') as outfile:
         ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '.\\en_US\\LC_MESSAGES\\strings.po'

This behavior makes the option less useful. I suggest invoke os.makedirs in UpdateCatalog.finalize_options, just like in InitCatalog.finalize_options:

if not os.path.exists(os.path.dirname(self.output_file)):
os.makedirs(os.path.dirname(self.output_file))

but with extra exist_ok=True argument, as the directory may already exist for the update command.

Or it might be better to reuse the logic in InitCatalog.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions