From 30b2205fad87fd05d5d7afa28fdd5a189fc3f496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Ba=C3=B1ados=20Schwerter?= Date: Mon, 4 Nov 2024 21:01:31 +0000 Subject: [PATCH] Black format refactoring --- src/morphodict/frontend/views.py | 4 +-- src/morphodict/paradigm/recordings.py | 7 +++-- src/morphodict/paradigm/test_layout.py | 27 ++++++++++++------- src/morphodict/paradigm/urls.py | 8 +++--- src/morphodict/paradigm/views.py | 25 ++++++++--------- src/morphodict/search/cvd_search.py | 2 ++ .../commands/runsamplequeriesonbranches.py | 5 +--- .../tests/test_context_processors.py | 4 +-- src/morphodict/utils/__init__.py | 5 ++-- 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/morphodict/frontend/views.py b/src/morphodict/frontend/views.py index 4b95952b1..66c6bd696 100644 --- a/src/morphodict/frontend/views.py +++ b/src/morphodict/frontend/views.py @@ -73,7 +73,7 @@ def entry_details(request, slug: str): dict_source=dict_source, show_emoji=should_show_emoji, ), - **paradigm_context_for_lemma(lemma, request) + **paradigm_context_for_lemma(lemma, request), ) context["show_morphemes"] = request.COOKIES.get("show_morphemes") context["morphemes"] = morphemes @@ -310,5 +310,3 @@ def get_dict_source(request): ret = [r.upper() for r in ret] return ret return None - - diff --git a/src/morphodict/paradigm/recordings.py b/src/morphodict/paradigm/recordings.py index 6d001f0a2..087b49ddf 100644 --- a/src/morphodict/paradigm/recordings.py +++ b/src/morphodict/paradigm/recordings.py @@ -1,7 +1,10 @@ from morphodict.utils import get_recordings_from_url from morphodict.paradigm.panes import WordformCell -def get_recordings_from_paradigm(paradigm, paradigm_audio: bool, speech_db_eq: list[str]): + +def get_recordings_from_paradigm( + paradigm, paradigm_audio: bool, speech_db_eq: list[str] +): if not paradigm_audio: return paradigm @@ -39,4 +42,4 @@ def get_recordings_from_paradigm(paradigm, paradigm_audio: bool, speech_db_eq: l def divide_chunks(terms, size): # looping till length l for i in range(0, len(terms), size): - yield terms[i : i + size] \ No newline at end of file + yield terms[i : i + size] diff --git a/src/morphodict/paradigm/test_layout.py b/src/morphodict/paradigm/test_layout.py index 262f1374d..ba4304358 100644 --- a/src/morphodict/paradigm/test_layout.py +++ b/src/morphodict/paradigm/test_layout.py @@ -4,15 +4,28 @@ from django.test import Client from django.urls import reverse + @pytest.mark.parametrize( ("lemma_text", "layout", "paradigm_size", "entries"), [ - ("wâpamêw", "VTA", "full", ["kiwâpamikonaw", "ê-kî-wâpamiskik", "ê-wâpamitân", "niwâpamâw"]), - ("kotiskâwêw", "VAI", "full", ["nikotiskâwân", "ê-wî-kotiskâwêt", "kotiskâwê", "nikotiskâwân"]), - ("acimosis", "NA", "full", ["acimosis", "acimosisak", "kicacimosisimiwâwa"]) + ( + "wâpamêw", + "VTA", + "full", + ["kiwâpamikonaw", "ê-kî-wâpamiskik", "ê-wâpamitân", "niwâpamâw"], + ), + ( + "kotiskâwêw", + "VAI", + "full", + ["nikotiskâwân", "ê-wî-kotiskâwêt", "kotiskâwê", "nikotiskâwân"], + ), + ("acimosis", "NA", "full", ["acimosis", "acimosisak", "kicacimosisimiwâwa"]), ], ) -def test_paradigm_from_full_page_and_api(client: Client, lemma_text: str, paradigm_size: str, layout: str, entries: list[str]): +def test_paradigm_from_full_page_and_api( + client: Client, lemma_text: str, paradigm_size: str, layout: str, entries: list[str] +): """ The paradigm returned from the full details page and the API endpoint should contain the exact same information. @@ -20,11 +33,7 @@ def test_paradigm_from_full_page_and_api(client: Client, lemma_text: str, paradi # Get standalone page: response = client.get( reverse("morphodict-paradigm-layout"), - { - "paradigm-size": paradigm_size, - "lemma":lemma_text, - "layout": layout - }, + {"paradigm-size": paradigm_size, "lemma": lemma_text, "layout": layout}, ) assert response.status_code == HTTPStatus.OK standalone_html = response.content.decode("UTF-8") diff --git a/src/morphodict/paradigm/urls.py b/src/morphodict/paradigm/urls.py index f92c5dcac..6abe3cd98 100644 --- a/src/morphodict/paradigm/urls.py +++ b/src/morphodict/paradigm/urls.py @@ -11,8 +11,6 @@ name="morphodict-paradigm-detail", ), path( - "_paradigm_layout/", - views.paradigm_for_lemma, - name="morphodict-paradigm-layout" - ) -] \ No newline at end of file + "_paradigm_layout/", views.paradigm_for_lemma, name="morphodict-paradigm-layout" + ), +] diff --git a/src/morphodict/paradigm/views.py b/src/morphodict/paradigm/views.py index 3ab121ff2..46e25bd64 100644 --- a/src/morphodict/paradigm/views.py +++ b/src/morphodict/paradigm/views.py @@ -66,6 +66,7 @@ def paradigm_internal(request): }, ) + @require_GET def paradigm_for_lemma(request): """ @@ -86,13 +87,13 @@ def paradigm_for_lemma(request): paradigm_size = request.GET.get("paradigm-size") manager = default_paradigm_manager() - + try: if not (paradigm := manager.paradigm_for(layout, lemma, paradigm_size)): return HttpResponseBadRequest("paradigm does not exist") except ParadigmDoesNotExistError: return HttpResponseBadRequest("paradigm does not exist") - + return render( request, "morphodict/components/paradigm.html", @@ -104,6 +105,7 @@ def paradigm_for_lemma(request): }, ) + def paradigm_for(wordform: Wordform, paradigm_size: str) -> Optional[Paradigm]: """ Returns a paradigm for the given wordform at the desired size. @@ -150,16 +152,15 @@ def paradigm_context_for_lemma(lemma: Wordform, request) -> dict[str, Any]: if size not in sizes: size = default_size - paradigm = get_recordings_from_paradigm(paradigm_for(lemma, size), **recordings_info(request)) + paradigm = get_recordings_from_paradigm( + paradigm_for(lemma, size), **recordings_info(request) + ) + + return {"paradigm": paradigm, "paradigm_size": size, "paradigm_sizes": sizes} - return { - "paradigm": paradigm, - "paradigm_size": size, - "paradigm_sizes": sizes - } - return {} + def recordings_info(request) -> dict: if source := request.COOKIES.get("audio_source"): if source != "both": @@ -171,10 +172,10 @@ def recordings_info(request) -> dict: if request.COOKIES.get("synthesized_audio_in_paradigm") == "yes": speech_db_eq.insert(0, "synth") - + return { "paradigm_audio": not request.COOKIES.get("paradigm_audio") in ["no", None], - "speech_db_eq": speech_db_eq + "speech_db_eq": speech_db_eq, } @@ -186,4 +187,4 @@ def remove_diacritics(item): 'maskwacis' """ item = item.translate(str.maketrans("ēīōāêîôâ", "eioaeioa")) - return item \ No newline at end of file + return item diff --git a/src/morphodict/search/cvd_search.py b/src/morphodict/search/cvd_search.py index 8036073a7..7b25f11da 100644 --- a/src/morphodict/search/cvd_search.py +++ b/src/morphodict/search/cvd_search.py @@ -16,6 +16,8 @@ ) from morphodict.lexicon.models import Wordform +from numpy import float16 + logger = logging.getLogger(__name__) diff --git a/src/morphodict/search_quality/management/commands/runsamplequeriesonbranches.py b/src/morphodict/search_quality/management/commands/runsamplequeriesonbranches.py index 757303b5e..c99f8fe30 100644 --- a/src/morphodict/search_quality/management/commands/runsamplequeriesonbranches.py +++ b/src/morphodict/search_quality/management/commands/runsamplequeriesonbranches.py @@ -258,10 +258,7 @@ def handle(self, *args, **options) -> None: shutil.copy( sample_csv_file, - branch.checkout_dir - / "morphodict" - / "search_quality" - / "sample.csv", + branch.checkout_dir / "morphodict" / "search_quality" / "sample.csv", ) branch.setup_package_managers() diff --git a/src/morphodict/tests/test_context_processors.py b/src/morphodict/tests/test_context_processors.py index 0fbf9c508..1276d040f 100644 --- a/src/morphodict/tests/test_context_processors.py +++ b/src/morphodict/tests/test_context_processors.py @@ -11,9 +11,7 @@ @pytest.fixture(autouse=True) def ensure_context_processors_are_enabled(settings): - desired_processor = ( - "morphodict.frontend.context_processors.display_options" - ) + desired_processor = "morphodict.frontend.context_processors.display_options" settings.TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", diff --git a/src/morphodict/utils/__init__.py b/src/morphodict/utils/__init__.py index 68d9fbbb2..48d3e7424 100644 --- a/src/morphodict/utils/__init__.py +++ b/src/morphodict/utils/__init__.py @@ -1,11 +1,12 @@ from .cree_lev_dist import get_modified_distance # Unused but exported -from .shared_res_dir import shared_res_dir # Unused but exported +from .shared_res_dir import shared_res_dir # Unused but exported from urllib.parse import ParseResult, urlencode, urlunparse from django.urls import reverse import requests import urllib + def url_for_query(user_query: str) -> str: """ Produces a relative URL to search for the given user query. @@ -45,4 +46,4 @@ def macron_to_circumflex(item): 'wâpamêw' """ item = item.translate(str.maketrans("ēīōā", "êîôâ")) - return item \ No newline at end of file + return item