From bb4bf6de105cee6b82df3fd95ac7bfd9b0ee1d8c Mon Sep 17 00:00:00 2001 From: axif Date: Thu, 7 Nov 2024 14:52:34 +0600 Subject: [PATCH] revert PyICU --- src/scribe_data/check/check_pyicu.py | 3 -- src/scribe_data/cli/get.py | 15 +----- .../unicode/generate_emoji_keywords.py | 53 +++++++++++-------- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/scribe_data/check/check_pyicu.py b/src/scribe_data/check/check_pyicu.py index 7ae9ea46..9e9bdd50 100644 --- a/src/scribe_data/check/check_pyicu.py +++ b/src/scribe_data/check/check_pyicu.py @@ -69,9 +69,6 @@ def fetch_wheel_releases(): """ url = "https://api.github.com/repos/cgohlke/pyicu-build/releases" response = requests.get(url) - if response.status_code == 403 and "rate limit exceeded" in response.text.lower(): - print("GitHub API rate limit exceeded. Please try again later.") - return [], 0.0 # Return empty list and zero size when rate limit is hit response.raise_for_status() # raise an error for bad responses available_wheels = [] diff --git a/src/scribe_data/cli/get.py b/src/scribe_data/cli/get.py index 1d78c3b9..6a0e0426 100644 --- a/src/scribe_data/cli/get.py +++ b/src/scribe_data/cli/get.py @@ -22,7 +22,6 @@ import os # for removing original JSON files import subprocess -import sys from pathlib import Path from typing import List, Union @@ -36,11 +35,6 @@ ) from scribe_data.wikidata.query_data import query_data -from scribe_data.check.check_pyicu import ( - check_and_install_pyicu, - check_if_pyicu_installed, -) - def get_data( language: str = None, @@ -142,14 +136,7 @@ def get_data( # MARK: Emojis elif data_type in {"emoji-keywords", "emoji_keywords"}: - if not check_if_pyicu_installed(): - check_and_install_pyicu() - # Try to dynamically import the PyICU module - try: - generate_emoji(language=language, output_dir=output_dir) - except ImportError: - os.execv(sys.executable, ["python"] + sys.argv) - generate_emoji(language=language, output_dir=output_dir) + generate_emoji(language=language, output_dir=output_dir) # MARK: Query Data diff --git a/src/scribe_data/unicode/generate_emoji_keywords.py b/src/scribe_data/unicode/generate_emoji_keywords.py index 3a1eb8ab..beb34257 100644 --- a/src/scribe_data/unicode/generate_emoji_keywords.py +++ b/src/scribe_data/unicode/generate_emoji_keywords.py @@ -23,6 +23,10 @@ import os from pathlib import Path +from scribe_data.check.check_pyicu import ( + check_and_install_pyicu, + check_if_pyicu_installed, +) from scribe_data.unicode.process_unicode import gen_emoji_lexicon from scribe_data.utils import export_formatted_data, get_language_iso @@ -51,30 +55,33 @@ def generate_emoji(language, output_dir: str = None): ------- None: The function does not return any value but outputs data to the specified directory. """ + if check_and_install_pyicu() and check_if_pyicu_installed() is False: + print("Thank you.") - iso = get_language_iso(language=language) - path_to_cldr_annotations = ( - Path(__file__).parent / "cldr-annotations-full" / "annotations" - ) - if iso in os.listdir(path_to_cldr_annotations): - print(f"Emoji Generation for language {language} is supported") + if check_if_pyicu_installed(): + iso = get_language_iso(language=language) + path_to_cldr_annotations = ( + Path(__file__).parent / "cldr-annotations-full" / "annotations" + ) + if iso in os.listdir(path_to_cldr_annotations): + print(f"Emoji Generation for language {language} is supported") - else: - print(f"Emoji Generation for language {language} is not supported") - return + else: + print(f"Emoji Generation for language {language} is not supported") + return - updated_path = output_dir[2:] if output_dir.startswith("./") else output_dir - export_dir = Path(updated_path) / language.capitalize() - export_dir.mkdir(parents=True, exist_ok=True) + updated_path = output_dir[2:] if output_dir.startswith("./") else output_dir + export_dir = Path(updated_path) / language.capitalize() + export_dir.mkdir(parents=True, exist_ok=True) - if emoji_keywords_dict := gen_emoji_lexicon( - language=language, - emojis_per_keyword=EMOJI_KEYWORDS_DICT, - ): - export_formatted_data( - file_path=output_dir, - formatted_data=emoji_keywords_dict, - query_data_in_use=True, - language=language.capitalize(), - data_type=DATA_TYPE, - ) + if emoji_keywords_dict := gen_emoji_lexicon( + language=language, + emojis_per_keyword=EMOJI_KEYWORDS_DICT, + ): + export_formatted_data( + file_path=output_dir, + formatted_data=emoji_keywords_dict, + query_data_in_use=True, + language=language.capitalize(), + data_type=DATA_TYPE, + )