Skip to content

Commit

Permalink
Fix randomly ordered languages from set()
Browse files Browse the repository at this point in the history
  • Loading branch information
abwiersma committed Jun 16, 2023
1 parent dbe6148 commit 59fd0ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/ocrmypdf/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ def check_platform() -> None:

def check_options_languages(options: Namespace, ocr_engine_languages: set[str]) -> None:
if not options.languages:
options.languages = {DEFAULT_LANGUAGE}
options.languages = [DEFAULT_LANGUAGE]
system_lang = locale.getlocale()[0]
if system_lang and not system_lang.startswith('en'):
log.debug("No language specified; assuming --language %s", DEFAULT_LANGUAGE)
if not ocr_engine_languages:
return
missing_languages = options.languages - ocr_engine_languages
missing_languages = set(options.languages) - ocr_engine_languages
if missing_languages:
lang_text = '\n'.join(lang for lang in missing_languages)
msg = (
Expand All @@ -79,7 +79,7 @@ def check_options_languages(options: Namespace, ocr_engine_languages: set[str])


def check_options_output(options: Namespace) -> None:
is_latin = options.languages.issubset(HOCR_OK_LANGS)
is_latin = set(options.languages).issubset(HOCR_OK_LANGS)

if options.pdf_renderer.startswith('hocr') and not is_latin:
log.warning(
Expand Down
6 changes: 3 additions & 3 deletions src/ocrmypdf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ class LanguageSetAction(argparse.Action):
def __init__(self, option_strings, dest, default=None, **kwargs):
"""Initialize the action."""
if default is None:
default = set()
default = list()
super().__init__(option_strings, dest, default=default, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
"""Add a language to the set."""
dest = getattr(namespace, self.dest)
if '+' in values:
dest.update(lang for lang in values.split('+'))
[dest.append(lang) for lang in values.split('+')]
else:
dest.add(values)
dest.append(values)


def get_parser():
Expand Down

0 comments on commit 59fd0ac

Please sign in to comment.