Skip to content

Commit c7ccafd

Browse files
author
brain-dev-null
committed
ci: Add type checking to CI
Add invokation of mypy to CI pipeline and change the code to adhere to its standard
1 parent 657cc43 commit c7ccafd

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

.github/workflows/python-app.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ jobs:
2626
run: |
2727
python -m pip install --upgrade pip
2828
pip install -r requirements.txt
29-
pip install flake8
29+
pip install -r requirements_ci.txt
3030
- name: Run linter
3131
run: flake8 electrolog
32+
- name: Run type checker
33+
run: mypy electrolog
3234
- name: Build application
3335
run: |
3436
pyinstaller -F electrolog/__main__.py -n electrolog --hiddenimport xlwt
@@ -52,9 +54,11 @@ jobs:
5254
run: |
5355
python -m pip install --upgrade pip
5456
pip install -r requirements.txt
55-
pip install flake8
57+
pip install -r requirements_ci.txt
5658
- name: Run linter
5759
run: flake8 electrolog
60+
- name: Run type checker
61+
run: mypy electrolog
5862
- name: Build application
5963
run: |
6064
pyinstaller -F electrolog\__main__.py -n electrolog.exe --hiddenimport xlwt

electrolog/__main__.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@
1212
default_ip = ""
1313

1414
if in_dev:
15-
handler = logging.StreamHandler()
16-
log_level = logging.DEBUG
15+
logging.basicConfig(
16+
level=logging.DEBUG,
17+
style="{",
18+
format=(
19+
"{asctime} - {levelname:<8} - {filename}:{funcName}:{lineno} -"
20+
" {message}"
21+
),
22+
handlers=[logging.StreamHandler()],
23+
)
1724
else:
18-
handler = logging.FileHandler("electrolog.log")
19-
log_level = logging.INFO
20-
21-
logging.basicConfig(
22-
level=logging.DEBUG,
23-
style="{",
24-
format="{asctime} - {levelname:<8} - {filename}:{funcName}:{lineno} - "
25-
"{message}",
26-
handlers=[handler],
27-
)
25+
logging.basicConfig(
26+
level=logging.INFO,
27+
style="{",
28+
format=(
29+
"{asctime} - {levelname:<8} - {filename}:{funcName}:{lineno} -"
30+
" {message}"
31+
),
32+
handlers=[logging.FileHandler("electrolog.log")],
33+
)
2834

2935
main(in_dev, default_ip=default_ip)

electrolog/data/download_functions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def download_past_hour(session: Session, base_url: str) -> DataFrame:
1010
url = f"{base_url}/V"
1111

1212
responses = [
13-
session.get(url, params={"h": page, "f": "j"}) for page in range(1, 3)
13+
session.get(url, params={"h": str(page), "f": "j"})
14+
for page in range(1, 3)
1415
]
1516

1617
page_dataframes = [
@@ -25,7 +26,8 @@ def download_past_day(session: Session, base_url: str) -> DataFrame:
2526
url = f"{base_url}/V"
2627

2728
responses = [
28-
session.get(url, params={"w": page, "f": "j"}) for page in range(1, 4)
29+
session.get(url, params={"w": str(page), "f": "j"})
30+
for page in range(1, 4)
2931
]
3032

3133
page_dataframes = [
@@ -40,7 +42,8 @@ def download_past_week(session: Session, base_url: str) -> DataFrame:
4042
url = f"{base_url}/V"
4143

4244
responses = [
43-
session.get(url, params={"d": page, "f": "j"}) for page in range(1, 7)
45+
session.get(url, params={"d": str(page), "f": "j"})
46+
for page in range(1, 7)
4447
]
4548

4649
page_dataframes = [
@@ -55,7 +58,8 @@ def download_past_year(session: Session, base_url: str) -> DataFrame:
5558
url = f"{base_url}/V"
5659

5760
responses = [
58-
session.get(url, params={"m": page, "f": "j"}) for page in range(1, 13)
61+
session.get(url, params={"m": str(page), "f": "j"})
62+
for page in range(1, 13)
5963
]
6064

6165
page_dataframes = [

electrolog/views/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
class LoginView:
2525
def __init__(self, root: tk.Tk, default_ip: Optional[str] = "") -> None:
26-
2726
if os.path.isfile("ip.txt"):
2827
with open("ip.txt", "r") as ip_file:
2928
default_ip = ip_file.read()

requirements.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
pandas==1.5.2
2-
pyinstaller==5.7.0
3-
requests==2.28.1
4-
tk==0.1.0
5-
xlwt==1.3.0
1+
pandas
2+
requests
3+
tk
4+
xlwt

requirements_ci.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pandas-stubs
2+
pyinstaller
3+
types-requests
4+
mypy
5+
flake8
6+
pytest

0 commit comments

Comments
 (0)