Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pybabel update --init-missing not creating parent directory #1142

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ def finalize_options(self):
self.output_file = os.path.join(self.output_dir, self.locale,
'LC_MESSAGES', f"{self.domain}.po")

if not os.path.exists(os.path.dirname(self.output_file)):
os.makedirs(os.path.dirname(self.output_file))
os.makedirs(os.path.dirname(self.output_file),exist_ok=True)
du33169 marked this conversation as resolved.
Show resolved Hide resolved

if self.no_wrap and self.width:
raise OptionError("'--no-wrap' and '--width' are mutually exclusive")
if not self.no_wrap and not self.width:
Expand Down Expand Up @@ -779,21 +779,17 @@ def run(self):
if self.check:
check_status[filename] = False
continue
self.log.info(
'creating catalog %s based on %s', filename, self.input_file,
)

with open(self.input_file, 'rb') as infile:
# Although reading from the catalog template, read_po must
# be fed the locale in order to correctly calculate plurals
catalog = read_po(infile, locale=self.locale)

catalog.locale = self._locale
catalog.revision_date = datetime.datetime.now(LOCALTZ)
catalog.fuzzy = False

with open(filename, 'wb') as outfile:
write_po(outfile, catalog)
tmpInitCatalog = InitCatalog(self.distribution)
tmpInitCatalog.output_dir = None
tmpInitCatalog.output_file = filename
tmpInitCatalog.input_file = self.input_file
tmpInitCatalog.locale = self.locale
tmpInitCatalog.domain = self.domain
tmpInitCatalog.no_wrap = self.no_wrap
tmpInitCatalog.width = self.width
tmpInitCatalog.finalize_options()
tmpInitCatalog.run()

Comment on lines +783 to 793
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names should be in snake_case, not camelCase.

self.log.info('updating catalog %s based on %s', filename, self.input_file)
with open(filename, 'rb') as infile:
Expand Down
Loading