Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaKozlovtcev committed Jul 16, 2024
1 parent 51d73d8 commit 53d3f4d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ You can change config of the service by changing the environment variables. Here
* `SPELLCHECK_DICTIONARIES_DISABLED` switches off user dictionaries API no matter what. Default value is `False`.
* `SPELLCHECK_USERNAME_MIN_LENGTH` minimum length of username. Default value is `3`.
* `SPELLCHECK_USERNAME_MAX_LENGTH` maximum length of username. Default value is `60`.
* `SPELLCHECK_EXCLUSION_WORDS_STR` list of words which will ignored by default(string separated by comma). Example: 'foo, bar'. Default value is empty string.
* `SPELLCHECK_EXCLUSION_WORDS_SET` set of words which will ignored by default(filled from exclusion_words_str).
Example: '["foo", "bar"]' . Default value is `set()`.
* `SPELLCHECK_EXCLUSION_WORDS_STR` String with list of words which will be ignored in /api/check endpoint each request. Example: `'foo, bar'`. Default value is empty string.

### Deployment
Note: all docker & docker-compose variants use named volumes to store user dictionaries.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_spell.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_default_excluded_words(
monkeypatch: typing.Any,
) -> None:
with monkeypatch.context() as patcher:
patcher.setattr(SETTINGS, "exclusion_words_set", excluded_words)
patcher.setattr(SETTINGS, "_exclusion_words_set", excluded_words)
fake_engine: SpellCheckService = SpellCheckService()
prepared = fake_engine.prepare(
models.SpellCheckRequest(text=wannabe_user_input, language=RU_LANG, exclude_urls=False),
Expand Down
22 changes: 14 additions & 8 deletions whole_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import structlog
import toml
import typing_extensions
from pydantic import computed_field
from pydantic_settings import BaseSettings


Expand Down Expand Up @@ -199,23 +200,28 @@ class SettingsOfMicroservice(BaseSettings):
exclusion_words_str: typing.Annotated[
str,
pydantic.Field(
description="list of words which will ignored by default(string separated by comma). " "Example: 'foo, bar'"
description="String with list of words which will be ignored in /api/check endpoint each request. "
"Example: `'foo, bar'`"
),
] = ""
exclusion_words_set: typing.Annotated[
_exclusion_words_set: typing.Annotated[
set[str],
pydantic.Field(
description="""set of words which will ignored by default(filled from exclusion_words_str).
Example: '["foo", "bar"]' """,
Example: `'["foo", "bar"]'` """,
),
] = set()

@computed_field # type: ignore[misc]
@property
def exclusion_words_set(self) -> set[str]:
return self._exclusion_words_set

@pydantic.model_validator(mode="after")
def assemble_exclusion_words_set(self) -> "typing_extensions.Self":
if not self.exclusion_words_set:
self.exclusion_words_set = {
one_word.strip().lower() for one_word in self.exclusion_words_str.split(",") if one_word
}
def _assemble_exclusion_words_set(self) -> "typing_extensions.Self":
self._exclusion_words_set = {
one_word.strip().lower() for one_word in self.exclusion_words_str.split(",") if one_word
}
return self

class Config:
Expand Down

0 comments on commit 53d3f4d

Please sign in to comment.