babel icon indicating copy to clipboard operation
babel copied to clipboard

symbolic links not followed during extract

Open jmoraleda opened this issue 9 months ago • 1 comments

Problem

Python files that are under symlinked directories are not processed by pybabel.

Expected result

The ** glob pattern in the configuration file instructs pybabel to traverse recursively all sub-directories, including symbolic links.

Am I missing some option in my configuration or command line or is this a bug/missing feature? Thank you.

Background

  • My python project has a complex structure that includes symbolic links to other directories and files.
  • I want to extract a template file for all translation strings in the project including those under directories that are sym-linked.
  • My configuration line includes [python: **.py].
  • I am on Debian Linux.

jmoraleda avatar Jun 12 '25 20:06 jmoraleda

I looked at the source code and realized that at the core of the traversal is function extract_from_dir which uses os.walk to traverse the directory. os.walk by default does not traverse symlinks. But it has a parameter followlinks that can be used to instruct it to follow them.

Since I needed this feature I went ahead and added an optional follow-links parameter in extract_from_dir and frontend. Now passing follow_links=True or --follow-links respectively one is able to tell babel to instruct os.walk to follow symbolic links. If no parameter is passed babel defaults to not follow links, just as before so this new feature should not impact any existing code or workflows.

I made a PR with the new feature #1212 , including documentation and a unit test.

jmoraleda avatar Jun 13 '25 15:06 jmoraleda