Skip to content

Commit

Permalink
Merge pull request #13 from bendsouza2/enhancement/issue-11/mypy
Browse files Browse the repository at this point in the history
add mypy, close #11
  • Loading branch information
bendsouza2 authored Oct 7, 2024
2 parents 5bc9e58 + 444ea26 commit 6cb3284
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/python-unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ jobs:
- name: Test with pytest
run: |
pytest -vvv
- name: type check with mypy
run: |
mypy -v .
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
ignore_missing_imports = True
exclude = ^(python/tests/test_functions.py|venv/)$
3 changes: 2 additions & 1 deletion python/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Module for storing constants for the project"""
import os
from dataclasses import dataclass
from typing import Literal

LANGUAGE_TO_LEARN = "es"
NATIVE_LANGUAGE = "en"
Expand Down Expand Up @@ -28,7 +29,7 @@ class ModelTypes:

@dataclass
class VideoSettings:
IMAGE_SIZE = "1024x1024"
IMAGE_SIZE: Literal["1024x1024"] = "1024x1024"


class Paths:
Expand Down
21 changes: 11 additions & 10 deletions python/word_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ def __init__(self,
self.syllable_count = self.get_total_syllable_count_spanish()
self.sub_filepath = self.echogarden_generate_subtitles(sentence=self.sentence)

def text_to_speech(self, language: str, filepath: str = None) -> str:
def text_to_speech(self, language: str, filepath: Optional[str] = None) -> str:
"""
Generate an audio file
:param language: The language that the audio should be generated in
:param filepath: The filepath to save the resulting .mp3 file to
:param filepath: Optional, the filepath to save the resulting .mp3 file to
"""
if filepath is None:
dt = datetime.utcnow().strftime("%m-%d-%Y %H:%M:%S")
Expand Down Expand Up @@ -218,7 +218,7 @@ def generate_srt_file(self) -> str:
words = self.sentence.split(" ")
phrases = []
phrase = []
phrase_time = 0
phrase_time = 0.0
for index, word in enumerate(words):
syllable_count = spanish_syllable_count(word)
phrase_time += syllable_count * syllables_per_second
Expand Down Expand Up @@ -266,10 +266,11 @@ def echogarden_generate_subtitles(self, sentence: str) -> str:
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
raise subprocess.CalledProcessError(f"Command failed with exit code {e.returncode}. stderr {e.stderr}")
raise subprocess.CalledProcessError(
e.returncode, e.cmd, stderr=f"Command failed with exit code {e.returncode}. stderr {e.stderr}"
)

if result:
return output_file_path
return output_file_path

def read_text_file(self) -> list:
"""
Expand Down Expand Up @@ -303,7 +304,7 @@ def get_random_word(self) -> str:
raise ValueError("The text file is empty or does not exist. No content could be read from file")
return random.choice(self.text_file)

def test_real_word(self, word: str = None) -> bool:
def test_real_word(self, word: Optional[str] = None) -> bool:
"""
Test if a word is genuine by checking it is in the dictionary
:param word: The word to test
Expand Down Expand Up @@ -355,7 +356,7 @@ def generate_example_sentence(self) -> str:
)

sentence = completion.choices[0].message.content
return sentence
return sentence # type: ignore

def translate_example_sentence_gpt(self) -> ChatCompletion:
"""Generate an example sentence demonstrating the context of a given word"""
Expand All @@ -374,7 +375,7 @@ def translate_example_sentence_gpt(self) -> ChatCompletion:
return completion

def google_translate(
self, target_language: str, source_language: str = None
self, target_language: str, source_language: Optional[str] = None
) -> str:
"""
Translate a sentence into your target language
Expand All @@ -395,7 +396,7 @@ def __init__(self,
word: str,
sentences: List[str],
local_image_storage: bool = False,
image_path: str = None
image_path: Optional[str] = None
):
self.word = word
self.sentences = sentences
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ google-api-core==2.11.1
openai==1.7.2
black==23.12.1
requests~=2.31.0
types-requests==2.32.0.20240914
deep-translator==1.11.4
gTTS~=2.5.1
moviepy~=1.0.3
Expand All @@ -14,4 +15,5 @@ fastapi==0.114.0
pydantic~=2.5.3
botocore==1.35.7
pyenchant==3.2.2
spacy==3.7.6
spacy==3.7.6
mypy==1.11.2

0 comments on commit 6cb3284

Please sign in to comment.