Skip to content

Conversation

@akx
Copy link
Member

@akx akx commented Jan 7, 2026

Fixes #1139 (since _init_catalog creates directories on the way)

Closes #1142 (supersedes it)

Fixes #1139 (since `_init_catalog` creates directories on the way)

Co-authored-by: lando <du33169@qq.com>
@akx akx added this to the Babel 2.18 milestone Jan 7, 2026
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.06%. Comparing base (12a14b6) to head (9826fc5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1244      +/-   ##
==========================================
- Coverage   92.07%   92.06%   -0.01%     
==========================================
  Files          27       27              
  Lines        4692     4687       -5     
==========================================
- Hits         4320     4315       -5     
  Misses        372      372              
Flag Coverage Δ
macos-14-3.10 91.10% <100.00%> (-0.01%) ⬇️
macos-14-3.11 91.03% <100.00%> (-0.01%) ⬇️
macos-14-3.12 91.25% <100.00%> (-0.01%) ⬇️
macos-14-3.13 91.25% <100.00%> (-0.01%) ⬇️
macos-14-3.14 91.23% <100.00%> (-0.01%) ⬇️
macos-14-3.8 90.96% <100.00%> (-0.01%) ⬇️
macos-14-3.9 91.03% <100.00%> (-0.01%) ⬇️
macos-14-pypy3.10 91.10% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-3.10 91.12% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-3.11 91.06% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-3.12 91.27% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-3.13 91.27% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-3.14 91.25% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-3.8 90.99% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-3.9 91.05% <100.00%> (-0.01%) ⬇️
ubuntu-24.04-pypy3.10 91.12% <100.00%> (-0.01%) ⬇️
windows-2022-3.10 91.11% <100.00%> (-0.01%) ⬇️
windows-2022-3.11 91.05% <100.00%> (-0.01%) ⬇️
windows-2022-3.12 91.26% <100.00%> (-0.01%) ⬇️
windows-2022-3.13 91.26% <100.00%> (-0.01%) ⬇️
windows-2022-3.14 91.24% <100.00%> (-0.01%) ⬇️
windows-2022-3.8 91.08% <100.00%> (-0.01%) ⬇️
windows-2022-3.9 91.04% <100.00%> (-0.01%) ⬇️
windows-2022-pypy3.10 91.11% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@akx akx marked this pull request as ready for review January 9, 2026 20:22
@akx akx requested a review from Copilot January 9, 2026 20:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the catalog initialization logic to fix a bug where pybabel update --init-missing would fail if the target directory didn't exist. The refactoring extracts the catalog initialization code into a shared _init_catalog function that both InitCatalog and UpdateCatalog can use, ensuring consistent behavior including automatic directory creation.

Key changes:

  • Introduced a new _init_catalog helper function that encapsulates catalog initialization logic and directory creation
  • Refactored InitCatalog and UpdateCatalog commands to use the shared function
  • Added test coverage for directory creation with --init-missing flag

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
babel/messages/frontend.py Extracted catalog initialization into _init_catalog function; updated InitCatalog and UpdateCatalog to use shared function with directory creation
tests/messages/frontend/test_cli.py Added test to verify that pybabel update --init-missing creates parent directories when they don't exist

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

catalog.revision_date = datetime.datetime.now(LOCALTZ)
catalog.fuzzy = False

os.makedirs(os.path.dirname(output_file), exist_ok=True)
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

When output_file is just a filename without any directory component (e.g., "messages.po"), os.path.dirname(output_file) will return an empty string. Calling os.makedirs("", exist_ok=True) could lead to unexpected behavior or errors. Consider checking if the directory path is non-empty before calling os.makedirs, or use os.path.dirname(output_file) or "." to default to the current directory.

Suggested change
os.makedirs(os.path.dirname(output_file), exist_ok=True)
output_dir = os.path.dirname(output_file)
if output_dir:
os.makedirs(output_dir, exist_ok=True)

Copilot uses AI. Check for mistakes.
return mappings


def _init_catalog(*, input_file, output_file, locale: Locale, width: int) -> None:
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

The type hint for width parameter should be int | None instead of int, since width can be None when the no_wrap option is used. According to the write_po documentation, None is an acceptable value to disable line wrapping.

Suggested change
def _init_catalog(*, input_file, output_file, locale: Locale, width: int) -> None:
def _init_catalog(*, input_file, output_file, locale: Locale, width: int | None) -> None:

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants