Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class CommandMixin:
#: Log object. To allow replacement in the script command line runner.
log = log

no_wrap: bool
width: int | None

def __init__(self, dist=None):
# A less strict version of distutils' `__init__`.
self.distribution = dist
Expand All @@ -159,6 +162,15 @@ def finalize_options(self):
f"abstract method -- subclass {self.__class__} must override",
)

def _finalize_width(self) -> None:
"""Validate and normalize the `--width` / `--no-wrap` pair."""
if self.no_wrap and self.width:
raise OptionError("'--no-wrap' and '--width' are mutually exclusive")
if not self.no_wrap and not self.width:
self.width = 76
elif self.width is not None:
self.width = int(self.width)


class CompileCatalog(CommandMixin):
description = 'compile message catalogs to binary MO files'
Expand Down Expand Up @@ -418,14 +430,7 @@ def finalize_options(self):

if not self.output_file:
raise OptionError('no output file specified')
if self.no_wrap and self.width:
raise OptionError(
"'--no-wrap' and '--width' are mutually exclusive",
)
if not self.no_wrap and not self.width:
self.width = 76
elif self.width is not None:
self.width = int(self.width)
self._finalize_width()

if self.sort_output and self.sort_by_file:
raise OptionError(
Expand Down Expand Up @@ -663,12 +668,7 @@ def finalize_options(self):
lc_messages_path = pathlib.Path(self.output_dir) / self.locale / "LC_MESSAGES"
self.output_file = str(lc_messages_path / f"{self.domain}.po")

if self.no_wrap and self.width:
raise OptionError("'--no-wrap' and '--width' are mutually exclusive")
if not self.no_wrap and not self.width:
self.width = 76
elif self.width is not None:
self.width = int(self.width)
self._finalize_width()

def run(self):
self.log.info(
Expand Down Expand Up @@ -772,12 +772,7 @@ def finalize_options(self):
else:
self._locale = None

if self.no_wrap and self.width:
raise OptionError("'--no-wrap' and '--width' are mutually exclusive")
if not self.no_wrap and not self.width:
self.width = 76
elif self.width is not None:
self.width = int(self.width)
self._finalize_width()
if self.no_fuzzy_matching and self.previous:
self.previous = False

Expand Down Expand Up @@ -942,12 +937,7 @@ def finalize_options(self):
if not self.input_files:
raise OptionError('you must specify the input files')

if self.no_wrap and self.width:
raise OptionError("'--no-wrap' and '--width' are mutually exclusive")
if not self.no_wrap and not self.width:
self.width = 76
elif self.width is not None:
self.width = int(self.width)
self._finalize_width()

if self.more_than is None:
self.more_than = 0
Expand Down Expand Up @@ -1090,12 +1080,7 @@ def finalize_options(self):
if not self.output_file and not self.update:
raise OptionError('you must specify the output file or use --update')

if self.no_wrap and self.width:
raise OptionError("'--no-wrap' and '--width' are mutually exclusive")
if not self.no_wrap and not self.width:
self.width = 76
elif self.width is not None:
self.width = int(self.width)
self._finalize_width()

def _get_messages_from_compendiums(self, compendium_paths):
for file_path in compendium_paths:
Expand Down
Loading