Skip to content

Commit

Permalink
chore: lint and use Rye and bump version to 1.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
bolinocroustibat committed Feb 15, 2024
1 parent 1b3a32d commit 7c5a711
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 64 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/deploy_on_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Deploy to prod from ${{ github.ref_name }}/${{ github.sha }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install SSH key
uses: shimataro/ssh-key-action@v2
Expand All @@ -32,13 +32,13 @@ jobs:
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /root/www/word-generator-api
source /root/www/word-generator-api/.venv/bin/activate
pip install -r /root/www/word-generator-api/requirements.lock
cd /home/www/word-generator-api
source /home/www/word-generator-api/.venv/bin/activate
pip install -r /home/www/word-generator-api/requirements.lock
sudo systemctl restart word-generator-api.service
- name: Create Sentry release
uses: getsentry/action-release@v1.2.1
uses: getsentry/action-release@v1.7.0
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: "adrien-carpentier"
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ target/
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Python API with a PostgreSQL database, using FastAPI framework.

- Python 3.11
- [PDM](https://pdm.fming.dev/)
- [Rye](https://rye-up.com/)
- [FastAPI](https://fastapi.tiangolo.com/)
- [Tortoise ORM](https://tortoise-orm.readthedocs.io/)
- PostgreSQL database
Expand Down Expand Up @@ -44,9 +44,9 @@ Python API with a PostgreSQL database, using FastAPI framework.

## Install

Create a virtual environnement and install the dependencies in it with [PDM](https://pdm.fming.dev/) single command:
Create a virtual environnement and install the dependencies in it with [Rye](https://rye-up.com/) (or with [PDM](https://pdm.fming.dev/)) single command:
```bash
pdm install
rye sync
```

### Setup the config file
Expand Down Expand Up @@ -75,9 +75,9 @@ For the French language, you need to download the Spacy NLP data:
```bash
python3 -m spacy download fr_core_news_sm
```
or, with PDM:
or, with Rye:
```bash
pdm run python -m spacy download fr_core_news_sm
rye run python -m spacy download fr_core_news_sm
```

If any issue with the `fr_core_news_sm` model installing, one can install it manually with:
Expand All @@ -91,27 +91,39 @@ If any issue with pip in the venv for Spacy:
python3 -m ensurepip --default-pip
```

If Spacy lefff doesn't work, try to install it manually with pip and not with PDM in the venv:
If Spacy lefff doesn't work, try to install it manually with pip and not with Rye/PDM in the venv:
```bash
pip install spacy-lefff
```
or, with PDM:
or, with Rye:
```bash
pdm run pip install spacy-lefff
rye run pip install spacy-lefff
```


## Run the API

Launch the web server with:
```bash
uvicorn api:app --reload
rye run uvicorn api:app --reload
```

Inside the venv:
```bash
pdm run uvicorn api:app --reload
uvicorn api:app --reload
```

## Lint and format the code

Lint with:
```bash
rye lint --fix
```

Format with:
```bash
rye fmt
```

## Commands

Expand Down
2 changes: 0 additions & 2 deletions commands/batch_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@


def batch_generate(lang: str, number: int = 500) -> None:

if lang not in ["en", "fr"]:
typer.secho(f"Invalid language: {lang}", fg="red")
raise typer.Abort()

async def _main():

await prepare_db()

i = 0
Expand Down
4 changes: 0 additions & 4 deletions commands/build_proba_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
def build_1char_probabilities(
alphabet: list[str], dictionary_filepath: Path, json_filepath: Path
) -> dict[str, dict[str, int]]:

# Initialize the nested dictionary structure
temp: dict[str, int] = {char: 0 for char in alphabet}
temp["last_letter"] = 0
Expand Down Expand Up @@ -39,7 +38,6 @@ def build_1char_probabilities(
def build_2char_probabilities(
alphabet: list[str], dictionary_filepath: Path, json_filepath: Path
) -> dict:

# Initialize the nested dictionary structure
temp: dict = {}
for letter1 in alphabet:
Expand Down Expand Up @@ -88,7 +86,6 @@ def build_2char_probabilities(


def build_chars_probability_file(lang: str, chars_nb: int = 2) -> None:

if lang not in ["en", "es", "fr", "it"]:
typer.secho(f"Invalid language: {lang}", fg="red")
raise typer.Abort()
Expand All @@ -98,7 +95,6 @@ def build_chars_probability_file(lang: str, chars_nb: int = 2) -> None:
raise typer.Abort()

async def _main():

current_path = Path(__file__).parent.absolute()

with open(
Expand Down
2 changes: 0 additions & 2 deletions commands/classify_db_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@


def classify(lang: str) -> None:

if lang not in ["en", "fr"]:
raise typer.Abort(f"Invalid language: {lang}")

async def _main():

await prepare_db()

i = 0
Expand Down
2 changes: 0 additions & 2 deletions commands/clean_db_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@


def clean(lang: str) -> None:

if lang not in ["en", "fr"]:
typer.secho(f"Invalid language: {lang}", fg="red")
raise typer.Abort()

async def _main():

i = 0

await prepare_db()
Expand Down
2 changes: 0 additions & 2 deletions commands/clean_db_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@


def clean(lang: str) -> None:

if lang not in ["en", "fr"]:
typer.secho(f"Invalid language: {lang}", fg="red")
raise typer.Abort()

async def _main():

if lang == "en":
real_word_class = RealWordEN
elif lang == "fr":
Expand Down
1 change: 0 additions & 1 deletion commands/delete_duplicates_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

def delete_duplicates_fr() -> None:
async def _main():

await prepare_db()

entries = await RealWordFR.objects.all()
Expand Down
2 changes: 0 additions & 2 deletions commands/dictionary_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@


def dictionary_to_db(lang: str, classify=True) -> None:

if lang not in ["en", "fr"]:
raise typer.Abort(f"Invalid language: {lang}")

async def _main():

await prepare_db()

with open(f"{lang}/data/adverbs_{lang.upper()}.txt", "r") as dictionary_file:
Expand Down
1 change: 0 additions & 1 deletion common/style_text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def style_text(input_text: str, style: str) -> str:

if style not in ["bold", "italic"]:
print("Error: Invalid style type.")
return input_text
Expand Down
1 change: 0 additions & 1 deletion en/generate_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


async def generate_definition_en(percentage: float, ip: str | None = None) -> dict:

random_definition = await get_random_definition_en()
real_string = random_definition["real_string"]
type = random_definition["type"]
Expand Down
1 change: 0 additions & 1 deletion fr/generate_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


async def generate_definition_fr(percentage: float, ip: str | None = None) -> dict:

random_definition = await get_random_definition_fr()
real_string = random_definition["real_string"]
type = random_definition["type"]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "word-generator-api"
version = "1.5.4"
version = "1.5.5"
description = "Generates words that don't exist but sound English, French, Spanish or Italian, along with their altered dictionary definitions."
authors = [{ name = "Adrien Carpentier", email = "[email protected]" }]
dependencies = [
Expand Down
30 changes: 15 additions & 15 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,62 +25,62 @@ confection==0.1.4
cymem==2.0.8
deprecated==1.2.14
distlib==0.3.8
fastapi==0.109.0
fastapi==0.109.2
filelock==3.13.1
gunicorn==20.1.0
h11==0.14.0
identify==2.5.33
identify==2.5.34
idna==3.6
importlib-resources==6.1.1
iso8601==1.1.0
jinja2==3.1.3
joblib==1.3.2
langcodes==3.3.0
limits==3.7.0
limits==3.8.0
markupsafe==2.1.5
msgpack==0.5.6
murmurhash==1.0.10
mypy-extensions==1.0.0
nltk==3.8.1
nodeenv==1.8.0
numpy==1.26.3
numpy==1.26.4
oauthlib==3.2.2
packaging==23.2
pathspec==0.12.1
platformdirs==4.2.0
pluggy==1.4.0
pre-commit==3.6.0
pre-commit==3.6.1
preshed==3.0.9
pydantic==2.6.0
pydantic-core==2.16.1
pydantic==2.6.1
pydantic-core==2.16.2
pypika-tortoise==0.1.6
pytz==2024.1
pyyaml==6.0.1
regex==2023.12.25
requests==2.31.0
requests-oauthlib==1.3.1
ruff==0.2.0
sentry-sdk==1.40.0
slowapi==0.1.8
ruff==0.2.1
sentry-sdk==1.40.4
slowapi==0.1.9
smart-open==6.4.0
sniffio==1.3.0
spacy==3.7.2
spacy-lefff==0.5.1
spacy-legacy==3.0.12
spacy-loggers==1.0.5
srsly==2.4.8
starlette==0.35.1
thinc==8.2.2
starlette==0.36.3
thinc==8.2.3
tortoise-orm==0.20.0
tqdm==4.66.1
tqdm==4.66.2
tweepy==4.14.0
typer==0.9.0
typing-extensions==4.9.0
urllib3==2.2.0
uvicorn==0.27.0.post1
uvicorn==0.27.1
virtualenv==20.25.0
wasabi==1.1.2
weasel==0.3.4
wrapt==1.16.0
# The following packages are considered to be unsafe in a requirements file:
setuptools==69.0.3
setuptools==69.1.0
24 changes: 12 additions & 12 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cloudpathlib==0.16.0
confection==0.1.4
cymem==2.0.8
deprecated==1.2.14
fastapi==0.109.0
fastapi==0.109.2
gunicorn==20.1.0
h11==0.14.0
idna==3.6
Expand All @@ -32,46 +32,46 @@ iso8601==1.1.0
jinja2==3.1.3
joblib==1.3.2
langcodes==3.3.0
limits==3.7.0
limits==3.8.0
markupsafe==2.1.5
msgpack==0.5.6
murmurhash==1.0.10
mypy-extensions==1.0.0
nltk==3.8.1
numpy==1.26.3
numpy==1.26.4
oauthlib==3.2.2
packaging==23.2
pathspec==0.12.1
platformdirs==4.2.0
pluggy==1.4.0
preshed==3.0.9
pydantic==2.6.0
pydantic-core==2.16.1
pydantic==2.6.1
pydantic-core==2.16.2
pypika-tortoise==0.1.6
pytz==2024.1
regex==2023.12.25
requests==2.31.0
requests-oauthlib==1.3.1
sentry-sdk==1.40.0
slowapi==0.1.8
sentry-sdk==1.40.4
slowapi==0.1.9
smart-open==6.4.0
sniffio==1.3.0
spacy==3.7.2
spacy-lefff==0.5.1
spacy-legacy==3.0.12
spacy-loggers==1.0.5
srsly==2.4.8
starlette==0.35.1
thinc==8.2.2
starlette==0.36.3
thinc==8.2.3
tortoise-orm==0.20.0
tqdm==4.66.1
tqdm==4.66.2
tweepy==4.14.0
typer==0.9.0
typing-extensions==4.9.0
urllib3==2.2.0
uvicorn==0.27.0.post1
uvicorn==0.27.1
wasabi==1.1.2
weasel==0.3.4
wrapt==1.16.0
# The following packages are considered to be unsafe in a requirements file:
setuptools==69.0.3
setuptools==69.1.0

0 comments on commit 7c5a711

Please sign in to comment.