Skip to content

feat: add ignore_hidden parameter to extract_from_dir - #1410

Open
2025sl93041-gkb wants to merge 1 commit into
python-babel:masterfrom
2025sl93041-gkb:fix/extract-ignore-hidden-files
Open

2025sl93041-gkb wants to merge 1 commit into
python-babel:masterfrom
2025sl93041-gkb:fix/extract-ignore-hidden-files

Conversation

@2025sl93041-gkb

Copy link
Copy Markdown

Summary

Adds an ignore_hidden: bool = False parameter to extract_from_dir().
When True, any file or directory whose name starts with . is skipped
during traversal.

Motivation

Closes #471. Prior to this change there was no way for a user to exclude
hidden files (e.g. .gitignore, .env.py, .hidden_template.html) from
message extraction. Hidden directories were already filtered by the
default directory filter (since Babel 2.9), but hidden files were
always extracted if they matched a pattern in the method map.

What this does

  • Adds ignore_hidden to extract_from_dir() signature (default False
    for backwards compatibility).
  • When True, the os.walk loop skips filenames and subdirectory names
    starting with ., regardless of what the directory_filter callback
    returns.
  • Updates the docstring with the new parameter.
  • Adds a changelog entry under Version 2.19.0 (Unreleased).

Tests

Added test_extract_from_dir_ignore_hidden in
tests/messages/test_extract.py covering:

  1. Default (ignore_hidden=False): hidden files are extracted.
  2. ignore_hidden=True: hidden files are not extracted.
  3. ignore_hidden=True overrides a permissive directory_filter to
    also exclude hidden directories.

Add an `ignore_hidden: bool = False` parameter to `extract_from_dir()`.
When True, files and directories whose names start with a dot are skipped
during the os.walk traversal.

Previously there was no way to exclude hidden files (e.g. `.gitignore`,
`.env.py`) from extraction; only hidden directories were filtered by the
default directory filter. This adds an explicit opt-in mechanism.

Closes python-babel#471

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract_messges seems can not ignore hidden files

2 participants