Skip to content

Commit

Permalink
Fix Dockerfile and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec committed Apr 25, 2024
1 parent 0fdcb59 commit 895e0b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 1 addition & 3 deletions maintenance/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
24 changes: 12 additions & 12 deletions maintenance/scripts/get_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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():
Expand All @@ -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"]
Expand Down Expand Up @@ -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)}"
Expand Down Expand Up @@ -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')
Expand Down
5 changes: 4 additions & 1 deletion scripts/get_fonts_dev.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 895e0b7

Please sign in to comment.