Skip to content

Commit

Permalink
Black format refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Nov 4, 2024
1 parent a8e9c1e commit 30b2205
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 40 deletions.
4 changes: 1 addition & 3 deletions src/morphodict/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -310,5 +310,3 @@ def get_dict_source(request):
ret = [r.upper() for r in ret]
return ret
return None


7 changes: 5 additions & 2 deletions src/morphodict/paradigm/recordings.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]
yield terms[i : i + size]
27 changes: 18 additions & 9 deletions src/morphodict/paradigm/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@
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.
"""
# 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")
Expand Down
8 changes: 3 additions & 5 deletions src/morphodict/paradigm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
name="morphodict-paradigm-detail",
),
path(
"_paradigm_layout/",
views.paradigm_for_lemma,
name="morphodict-paradigm-layout"
)
]
"_paradigm_layout/", views.paradigm_for_lemma, name="morphodict-paradigm-layout"
),
]
25 changes: 13 additions & 12 deletions src/morphodict/paradigm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def paradigm_internal(request):
},
)


@require_GET
def paradigm_for_lemma(request):
"""
Expand All @@ -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",
Expand All @@ -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.
Expand Down Expand Up @@ -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":
Expand All @@ -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,
}


Expand All @@ -186,4 +187,4 @@ def remove_diacritics(item):
'maskwacis'
"""
item = item.translate(str.maketrans("ēīōāêîôâ", "eioaeioa"))
return item
return item
2 changes: 2 additions & 0 deletions src/morphodict/search/cvd_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
)
from morphodict.lexicon.models import Wordform

from numpy import float16

logger = logging.getLogger(__name__)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions src/morphodict/tests/test_context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/morphodict/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -45,4 +46,4 @@ def macron_to_circumflex(item):
'wâpamêw'
"""
item = item.translate(str.maketrans("ēīōā", "êîôâ"))
return item
return item

0 comments on commit 30b2205

Please sign in to comment.