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

Fix randomly ordered languages from set() #1113

Merged
merged 1 commit into from
Jun 20, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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