Skip to content

Commit 3c4cbb1

Browse files
authored
refactor: bumps versions of pyright, requirements and ruff, also fixes type checker and ruff errors. (#217)
1 parent 99e5442 commit 3c4cbb1

File tree

23 files changed

+125
-97
lines changed

23 files changed

+125
-97
lines changed

.github/workflows/check_n_push_image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
pip install $(python3 setup.py --install-requirements)
3535
pip install $(python3 setup.py --build-requirements)
3636
pip install --requirement docs/notebooks/requirements.txt
37-
pip install pre-commit==3.4.0
37+
pip install pre-commit==4.1.0
3838
make pre-commit
3939
4040
docker-build-test-autotest:

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ default_language_version:
22
python: python3.10
33
repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
5-
rev: v0.6.4
5+
rev: v0.9.7
66
hooks:
77
- id: ruff
88
args: [ --fix ]
@@ -15,4 +15,4 @@ repos:
1515
language: node
1616
pass_filenames: false
1717
types: [ python ]
18-
additional_dependencies: [ '[email protected].305' ]
18+
additional_dependencies: [ '[email protected].394' ]

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
UTIL_VERSION := 0.5.12
1+
UTIL_VERSION := 0.5.13
22
UTIL_NAME := codeplag
33
PWD := $(shell pwd)
44

55
USER_UID ?= $(shell id --user)
66
USER_GID ?= $(shell id --group)
77

8-
BASE_DOCKER_VERSION := 1.0
8+
BASE_DOCKER_VERSION := 1.1
99
BASE_DOCKER_TAG := $(shell echo $(UTIL_NAME)-base-ubuntu22.04:$(BASE_DOCKER_VERSION) | tr A-Z a-z)
1010
TEST_DOCKER_TAG := $(shell echo $(UTIL_NAME)-test-ubuntu22.04:$(UTIL_VERSION) | tr A-Z a-z)
1111
DOCKER_TAG ?= $(shell echo $(UTIL_NAME)-ubuntu22.04:$(UTIL_VERSION) | tr A-Z a-z)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103

104104
- Testing for analyzers with pytest lib (required preinstalled pytest framework).
105105
```
106-
$ pip3 install pytest==7.4.0 pytest-mock==3.11.1
106+
$ pip3 install pytest==8.3.4 pytest-mock==3.14.0
107107
$ make test
108108
```
109109

docker/test_ubuntu2204.dockerfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive
44

55
RUN apt-get update
66
RUN apt-get install -y debhelper
7-
RUN pip3 install pytest==7.4.0 pytest-mock==3.11.1 @PYTHON_BUILD_LIBS@
7+
RUN pip3 install pytest==8.3.4 pytest-mock==3.14.0 @PYTHON_BUILD_LIBS@
88
RUN mkdir -p @LOGS_PATH@
99

1010
# TODO: Move to middle docker file or make another solution

docs/notebooks/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
matplotlib~=3.7.3
2-
numpy~=1.23.5
3-
pandas~=2.0.3
1+
matplotlib~=3.10.0
2+
numpy~=1.26.4
3+
pandas~=2.2.3
44
python-decouple~=3.8
5-
scipy~=1.10.1
5+
scipy~=1.15.2

docs/notebooks/utils.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import sys
34
from datetime import datetime
45
from time import perf_counter
56
from typing import Literal
@@ -34,28 +35,32 @@ def remove_unnecessary_blank_lines(source_code: str) -> str:
3435
return re.sub(pattern, "\n", source_code)
3536

3637

37-
def get_data_from_dir(path: str = "./data", max_count_lines: int | None = None) -> pd.DataFrame:
38+
def get_data_from_dir(
39+
path: str = "./data", max_count_lines: int | None = None
40+
) -> pd.DataFrame | None:
3841
df = pd.DataFrame()
3942
for filename in os.listdir(path):
4043
if not re.search(r".csv$", filename):
4144
continue
4245

43-
tmp_df = pd.read_csv(os.path.join(path, filename), sep=";", index_col=0)
46+
tmp_df = pd.read_csv(os.path.join(path, filename), sep=";", index_col=0) # type: ignore
4447
df = df.append(tmp_df, ignore_index=True)
4548

4649
if max_count_lines:
47-
return df[df.count_lines_without_blank_lines < max_count_lines]
50+
result = df[df.count_lines_without_blank_lines < max_count_lines]
51+
assert isinstance(result, pd.DataFrame) or result is None
52+
return result
4853

4954
return df
5055

5156

52-
def save_works_from_repo_url(url: str, check_policy: bool = True) -> None:
57+
def save_works_from_repo_url(url: str, check_policy: bool = True, min_lines: int = 5) -> None:
5358
current_repo_name = url.split("/")[-1]
5459
env_config = Config(RepositoryEnv("../../.env"))
5560
gh = GitHubParser(
5661
file_extensions=(re.compile(r".py$"),),
5762
check_all=check_policy,
58-
access_token=env_config.get("ACCESS_TOKEN"),
63+
access_token=env_config.get("ACCESS_TOKEN", default=""), # type: ignore
5964
)
6065
files = list(gh.get_files_generator_from_repo_url(url))
6166
files = [(remove_unnecessary_blank_lines(file.code), file.link) for file in files]
@@ -76,22 +81,34 @@ def save_works_from_repo_url(url: str, check_policy: bool = True) -> None:
7681
],
7782
}
7883
)
79-
df = df[df["count_lines_without_blank_lines"] > 5]
84+
filtered_df = df["count_lines_without_blank_lines"]
85+
assert filtered_df is not None
86+
df = df[filtered_df > min_lines]
87+
if df is None:
88+
print(f"Nothing to save with minimal count of lines '{min_lines}'.", file=sys.stderr)
89+
return
8090
df.to_csv(os.path.join("./data/", current_repo_name + ".csv"), sep=";")
8191

8292

8393
def get_time_to_meta(df: pd.DataFrame, iterations: int = 10) -> pd.DataFrame:
8494
count_lines = []
8595
to_meta_time = []
86-
for index, content in df[["content", "link", "count_lines_without_blank_lines"]].iterrows():
96+
filtered_df = df[["content", "link", "count_lines_without_blank_lines"]]
97+
if filtered_df is None:
98+
raise Exception("DataFrame is empty, nothing to parse.")
99+
for index, content in filtered_df.iterrows():
100+
code = content[0]
101+
filepath = content[1]
102+
assert isinstance(code, str)
103+
assert isinstance(filepath, str)
87104
print(index, " " * 20, end="\r")
88105
for _ in range(iterations):
89-
tree = get_ast_from_content(content[0], content[1])
106+
tree = get_ast_from_content(code, filepath)
90107
if tree is None:
91108
break
92109
try:
93110
start = perf_counter()
94-
get_features_from_ast(tree, content[1])
111+
get_features_from_ast(tree, filepath)
95112
end = perf_counter() - start
96113
to_meta_time.append(end)
97114
count_lines.append(content[2])
@@ -130,7 +147,7 @@ def plot_and_save_result(
130147
p = np.poly1d(z)
131148
plt.plot(unique_count_lines, p(unique_count_lines), "r--", label="Линейный тренд.")
132149
elif trend == "n^2":
133-
popt_cons, _ = curve_fit(
150+
popt_cons, _ = curve_fit( # type: ignore
134151
square_func,
135152
unique_count_lines,
136153
mean_times,
@@ -144,7 +161,7 @@ def plot_and_save_result(
144161
label="Квадратичный тренд.",
145162
)
146163
elif trend == "n^3":
147-
popt_cons, _ = curve_fit(
164+
popt_cons, _ = curve_fit( # type: ignore
148165
cube_func,
149166
unique_count_lines,
150167
mean_times,
@@ -156,7 +173,7 @@ def plot_and_save_result(
156173
p = np.poly1d(popt_cons)
157174
plt.plot(unique_count_lines, p(unique_count_lines), "r--", label="Кубический тренд.")
158175
elif trend == "n^4":
159-
popt_cons, _ = curve_fit(
176+
popt_cons, _ = curve_fit( # type: ignore
160177
quart_func,
161178
unique_count_lines,
162179
mean_times,
@@ -200,14 +217,21 @@ def get_time_algorithms(
200217
raise Exception("Unexpected error when parsing first work.")
201218

202219
features1 = get_features_from_ast(tree1, work.link)
203-
for index, content in df[["content", "link", "count_lines_without_blank_lines"]].iterrows():
220+
filtered_df = df[["content", "link", "count_lines_without_blank_lines"]]
221+
if filtered_df is None:
222+
raise Exception("DataFrame is empty, nothing to parse.")
223+
for index, content in filtered_df.iterrows():
224+
code = content[0]
225+
filepath = content[1]
226+
assert isinstance(code, str)
227+
assert isinstance(filepath, str)
204228
for _ in range(iterations):
205229
print(index, " " * 20, end="\r")
206-
tree2 = get_ast_from_content(content[0], content[1])
230+
tree2 = get_ast_from_content(code, filepath)
207231
if tree2 is None:
208232
continue
209233
try:
210-
features2 = get_features_from_ast(tree2, content[1])
234+
features2 = get_features_from_ast(tree2, filepath)
211235
except Exception:
212236
continue
213237

locales/codeplag.pot

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#, fuzzy
66
msgid ""
77
msgstr ""
8-
"Project-Id-Version: codeplag 0.5.12\n"
9-
"POT-Creation-Date: 2025-01-03 14:06+0300\n"
8+
"Project-Id-Version: codeplag 0.5.13\n"
9+
"POT-Creation-Date: 2025-02-25 22:01+0300\n"
1010
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1111
"Last-Translator: Artyom Semidolin\n"
1212
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -190,33 +190,33 @@ msgid ""
190190
"languages."
191191
msgstr ""
192192

193-
#: src/codeplag/codeplagcli.py:366
193+
#: src/codeplag/codeplagcli.py:365
194194
msgid "Print current version number and exit."
195195
msgstr ""
196196

197-
#: src/codeplag/codeplagcli.py:372
197+
#: src/codeplag/codeplagcli.py:371
198198
msgid "Commands help."
199199
msgstr ""
200200

201-
#: src/codeplag/codeplagcli.py:387
201+
#: src/codeplag/codeplagcli.py:386
202202
msgid "No command is provided; please choose one from the available (--help)."
203203
msgstr ""
204204

205-
#: src/codeplag/codeplagcli.py:398
205+
#: src/codeplag/codeplagcli.py:397
206206
msgid "There is nothing to modify; please provide at least one argument."
207207
msgstr ""
208208

209-
#: src/codeplag/codeplagcli.py:402
209+
#: src/codeplag/codeplagcli.py:401
210210
msgid "The'repo-regexp' option requires the provided 'github-user' option."
211211
msgstr ""
212212

213-
#: src/codeplag/codeplagcli.py:410
213+
#: src/codeplag/codeplagcli.py:409
214214
msgid ""
215215
"The'path-regexp' option requires the provided 'directories', 'github-"
216216
"user', or 'github-project-folder' options."
217217
msgstr ""
218218

219-
#: src/codeplag/codeplagcli.py:421 src/codeplag/handlers/report.py:95
219+
#: src/codeplag/codeplagcli.py:420 src/codeplag/handlers/report.py:95
220220
msgid "All paths must be provided."
221221
msgstr ""
222222

locales/translations/en/LC_MESSAGES/codeplag.po

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
msgid ""
66
msgstr ""
7-
"Project-Id-Version: codeplag 0.5.12\n"
7+
"Project-Id-Version: codeplag 0.5.13\n"
88
"POT-Creation-Date: 2024-05-21 09:28+0300\n"
99
"PO-Revision-Date: 2024-05-16 19:15+0300\n"
1010
"Last-Translator: Artyom Semidolin\n"
@@ -214,35 +214,35 @@ msgstr ""
214214
"Program help to find similar parts of source codes for the different "
215215
"languages."
216216

217-
#: src/codeplag/codeplagcli.py:366
217+
#: src/codeplag/codeplagcli.py:365
218218
msgid "Print current version number and exit."
219219
msgstr "Print current version number and exit."
220220

221-
#: src/codeplag/codeplagcli.py:372
221+
#: src/codeplag/codeplagcli.py:371
222222
msgid "Commands help."
223223
msgstr "Commands help."
224224

225-
#: src/codeplag/codeplagcli.py:387
225+
#: src/codeplag/codeplagcli.py:386
226226
msgid "No command is provided; please choose one from the available (--help)."
227227
msgstr "No command is provided; please choose one from the available (--help)."
228228

229-
#: src/codeplag/codeplagcli.py:398
229+
#: src/codeplag/codeplagcli.py:397
230230
msgid "There is nothing to modify; please provide at least one argument."
231231
msgstr "There is nothing to modify; please provide at least one argument."
232232

233-
#: src/codeplag/codeplagcli.py:402
233+
#: src/codeplag/codeplagcli.py:401
234234
msgid "The'repo-regexp' option requires the provided 'github-user' option."
235235
msgstr "The'repo-regexp' option requires the provided 'github-user' option."
236236

237-
#: src/codeplag/codeplagcli.py:410
237+
#: src/codeplag/codeplagcli.py:409
238238
msgid ""
239239
"The'path-regexp' option requires the provided 'directories', 'github-"
240240
"user', or 'github-project-folder' options."
241241
msgstr ""
242242
"The'path-regexp' option requires the provided 'directories', 'github-"
243243
"user', or 'github-project-folder' options."
244244

245-
#: src/codeplag/codeplagcli.py:421 src/codeplag/handlers/report.py:95
245+
#: src/codeplag/codeplagcli.py:420 src/codeplag/handlers/report.py:95
246246
msgid "All paths must be provided."
247247
msgstr "All or none of the root paths must be specified."
248248

locales/translations/ru/LC_MESSAGES/codeplag.po

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
msgid ""
66
msgstr ""
7-
"Project-Id-Version: codeplag 0.5.12\n"
7+
"Project-Id-Version: codeplag 0.5.13\n"
88
"POT-Creation-Date: 2024-05-21 09:28+0300\n"
99
"PO-Revision-Date: 2024-05-11 12:05+0300\n"
1010
"Last-Translator: Artyom Semidolin\n"
@@ -224,39 +224,39 @@ msgstr ""
224224
"Программа помогает находить схожие части исходных кодов для разных языков"
225225
" программирования."
226226

227-
#: src/codeplag/codeplagcli.py:366
227+
#: src/codeplag/codeplagcli.py:365
228228
msgid "Print current version number and exit."
229229
msgstr "Выводит текущую версию программы."
230230

231-
#: src/codeplag/codeplagcli.py:372
231+
#: src/codeplag/codeplagcli.py:371
232232
msgid "Commands help."
233233
msgstr "Справка по командам."
234234

235-
#: src/codeplag/codeplagcli.py:387
235+
#: src/codeplag/codeplagcli.py:386
236236
msgid "No command is provided; please choose one from the available (--help)."
237237
msgstr ""
238238
"Ни одна из команд не выбрана, пожалуйста, выбери одну из доступных команд"
239239
" (--help)."
240240

241-
#: src/codeplag/codeplagcli.py:398
241+
#: src/codeplag/codeplagcli.py:397
242242
msgid "There is nothing to modify; please provide at least one argument."
243243
msgstr ""
244244
"Нечего модифицировать, пожалуйста, выберите один из параметров для "
245245
"модификации."
246246

247-
#: src/codeplag/codeplagcli.py:402
247+
#: src/codeplag/codeplagcli.py:401
248248
msgid "The'repo-regexp' option requires the provided 'github-user' option."
249249
msgstr "Аргумент 'repo-regexp' требует заданного параметра 'github-user'."
250250

251-
#: src/codeplag/codeplagcli.py:410
251+
#: src/codeplag/codeplagcli.py:409
252252
msgid ""
253253
"The'path-regexp' option requires the provided 'directories', 'github-"
254254
"user', or 'github-project-folder' options."
255255
msgstr ""
256256
"Аргумент 'path-regexp' требует заданного параметра 'directories', "
257257
"'github-user' или 'github-project-folder'."
258258

259-
#: src/codeplag/codeplagcli.py:421 src/codeplag/handlers/report.py:95
259+
#: src/codeplag/codeplagcli.py:420 src/codeplag/handlers/report.py:95
260260
msgid "All paths must be provided."
261261
msgstr "Необходимо указать все корневые пути или не указывать ни одного."
262262

0 commit comments

Comments
 (0)