From 895e0b7e5093de09ff271b749edfd5a607f80c25 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Thu, 25 Apr 2024 16:35:02 -0400 Subject: [PATCH] Fix Dockerfile and linting --- maintenance/Dockerfile | 4 +--- maintenance/scripts/get_fonts.py | 24 ++++++++++++------------ scripts/get_fonts_dev.py | 5 ++++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/maintenance/Dockerfile b/maintenance/Dockerfile index 7e2302eaa7..402f2f7010 100644 --- a/maintenance/Dockerfile +++ b/maintenance/Dockerfile @@ -33,12 +33,10 @@ WORKDIR ${HOME} ENV PATH ${PATH}:${SCRIPT_DIR} -RUN mkdir -p ${SCRIPT_DIR}/font_lists - COPY --chown=user:user requirements.txt . RUN pip3 install -r requirements.txt COPY --chown=user:user scripts/*.py ${SCRIPT_DIR} COPY --chown=user:user scripts/*.sh ${SCRIPT_DIR} -COPY --chown=user:user scripts/font_lists/* ${SCRIPT_DIR}/font_lists +COPY --chown=user:user scripts/*.txt ${SCRIPT_DIR} diff --git a/maintenance/scripts/get_fonts.py b/maintenance/scripts/get_fonts.py index cac191ed73..4b1c9ecad3 100755 --- a/maintenance/scripts/get_fonts.py +++ b/maintenance/scripts/get_fonts.py @@ -20,7 +20,6 @@ scripts_dir = Path(__file__).resolve().parent file_name_fallback = "fallback.json" mlp_font_list = scripts_dir / "mui_language_picker_fonts.txt" -mlp_fonts_known_unavailable = [] url_font_families_info = "https://github.com/silnrsi/fonts/raw/main/families.json" url_lang_tags_list = "https://ldml.api.sil.org/en?query=langtags" url_script_font_table = ( @@ -125,10 +124,10 @@ def extract_lang_subtags(langs: List[str]) -> List[str]: return lang_list -def fetch_scripts_for_langs(langs: List[str], scripts: List[str] = None) -> List[str]: +def fetch_scripts_for_langs(langs: List[str]) -> List[str]: """Given a list of langtags, look up and return all script tags used with the languages.""" langs = [lang.lower() for lang in langs] - scripts = scripts if scripts else [] + scripts = [] logging.debug(f"Downloading lang-tag list from {url_lang_tags_list}") req = requests.get(url_lang_tags_list) for line in req.iter_lines(): @@ -147,7 +146,7 @@ def fetch_scripts_for_langs(langs: List[str], scripts: List[str] = None) -> List def fetch_fonts_for_scripts(scripts: List[str]) -> List[str]: """Given a list of script tags, look up the default fonts used with those scripts.""" - scripts = [script.capitalize() for script in scripts] + scripts = list({script.capitalize() for script in scripts}) # Always have the Mui-Language-Picker default/safe fonts. fonts = ["Annapurna SIL", "Charis SIL", "Noto Sans TC", "Scheherazade New"] @@ -211,13 +210,16 @@ def main() -> None: fonts = [f.strip() for f in mlp_fonts_list.readlines()] if offline: + scripts: List[str] = [] if args.langs: - logging.info(f"Language tags: {', '.join(args.langs)}") - scripts = fetch_scripts_for_langs(args.langs, args.scripts) - else: - scripts = args.scripts + logging.info(f"Specified languages: {', '.join(args.langs)}") + scripts = fetch_scripts_for_langs(args.langs) + logging.info(f"Scripts for specified languages: {', '.join(scripts)}") + + if args.scripts: + logging.info(f"Specified scripts: {', '.join(args.scripts)}") + scripts.extend(args.scripts) - logging.info(f"Scripts: {', '.join(scripts)}") script_fonts = fetch_fonts_for_scripts(scripts) logging.info( f"Fonts (default and those for specified languages/scripts): {', '.join(script_fonts)}" @@ -266,9 +268,7 @@ def main() -> None: # Check if font was determined available. if font_id == "" or font_id not in families.keys(): - if font in mlp_fonts_known_unavailable: - logging.debug(f'Font "{font}" not available (but we knew that already)') - elif offline: + if offline: logging.warning(f'Font "{font}" not available for download') else: logging.warning(f'Font "{font}" css info not available') diff --git a/scripts/get_fonts_dev.py b/scripts/get_fonts_dev.py index f82d25f050..a972dfd63b 100755 --- a/scripts/get_fonts_dev.py +++ b/scripts/get_fonts_dev.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 -"""Runs maintenance/scripts/get_fonts.py with dev arguments for -f and -o""" +""" +Runs maintenance/scripts/get_fonts.py with dev arguments for -f and -o. +Run this script with -U/--update whenever the MLP version is updated. +""" import argparse from pathlib import Path