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

allow header_comment to be passed as an option to extract_message #720

Merged
merged 2 commits into from Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions babel/messages/frontend.py
Expand Up @@ -26,7 +26,7 @@
from babel import __version__ as VERSION
from babel import Locale, localedata
from babel.core import UnknownLocaleError
from babel.messages.catalog import Catalog
from babel.messages.catalog import Catalog, DEFAULT_HEADER
from babel.messages.extract import DEFAULT_KEYWORDS, DEFAULT_MAPPING, check_and_call_extract_file, extract_from_dir
from babel.messages.mofile import write_mo
from babel.messages.pofile import read_po, write_po
Expand Down Expand Up @@ -350,6 +350,8 @@ class extract_messages(Command):
('ignore-dirs=', None,
'Patterns for directories to ignore when scanning for messages. '
'Separate multiple patterns with spaces (default ".* ._")'),
('header-comment=', None,
'header comment for the catalog'),
]
boolean_options = [
'no-default-keywords', 'no-location', 'omit-header', 'no-wrap',
Expand Down Expand Up @@ -394,6 +396,7 @@ def initialize_options(self):
self.strip_comments = False
self.include_lineno = True
self.ignore_dirs = None
self.header_comment = None

def finalize_options(self):
if self.input_dirs:
Expand Down Expand Up @@ -478,7 +481,8 @@ def run(self):
version=self.version,
msgid_bugs_address=self.msgid_bugs_address,
copyright_holder=self.copyright_holder,
charset=self.charset)
charset=self.charset,
header_comment=(self.header_comment or DEFAULT_HEADER))

for path, method_map, options_map in mappings:
def callback(filename, method, options):
Expand Down
9 changes: 9 additions & 0 deletions tests/messages/test_frontend.py
Expand Up @@ -1518,3 +1518,12 @@ def test_extract_ignore_dirs(monkeypatch, capsys, tmp_path, with_underscore_igno
# unless we opt in to ignore it again
assert ('ssshhh....' in pot_content) != with_underscore_ignore
assert ('_hidden_by_default' in pot_content) != with_underscore_ignore


def test_extract_header_comment(monkeypatch, tmp_path):
pot_file = tmp_path / 'temp.pot'
monkeypatch.chdir(project_dir)
cmdinst = configure_cli_command(f"extract . -o '{pot_file}' --header-comment 'Boing' ")
cmdinst.run()
pot_content = pot_file.read_text()
assert 'Boing' in pot_content