Skip to content

Hardcode "ignore" method#678

Closed
sebleblanc wants to merge 1 commit intopython-babel:masterfrom
sebleblanc:sebleblanc-no-open-ignore
Closed

Hardcode "ignore" method#678
sebleblanc wants to merge 1 commit intopython-babel:masterfrom
sebleblanc:sebleblanc-no-open-ignore

Conversation

@sebleblanc
Copy link
Copy Markdown
Contributor

The "ignore" method forces the opening of a file, but this is pointless.

Some editors (emacs) create symbolic links to use as synchronization locks. These links have an extension that matches the opened file, but the links themselves do not point to an existing file, thus causing Babel to attempt to open a file that does not exist.

For example, on my machine, I have a file opened in my editor (project/i18n.py) resulting in the following link being created:

.#i18n.py -> sebleblanc@host.11171:1575144024

Babel will catch this file with the default **.py mapping, so I created a mapping with the pattern [ignore: **/.*] thinking it would ignore all files beginning with a dot, but instead, it pointlessly attempts to open such files and pass them through a "no-op" processor. Since it does not discriminate against links, this results in a FileNotFoundError, aborting extraction of all messages.

This fix skips opening of a file altogether when using the method "ignore" in the mapping file, by short-circuiting the extract_from_file function when the method matches "ignore".

Maybe Babel should by default silently skip a file when:

  • it raises FileNotFoundError
  • it is a symlink

The "ignore" method used to force the opening of the file. Some editors (emacs) create symbolic links to use as synchronization locks. Those links have an extension that matches the opened file, but the links themselves do not point to an existing file, thus causing Babel to attempt to open a file that does not exist.

This fix skips opening of a file altogether when using the method "ignore" in the mapping file.
Copy link
Copy Markdown
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

Aside from that else: nitpick, this looks good, thank you!

Comment thread babel/messages/extract.py
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.

2 participants