Skip to content

Commit 4cb57e5

Browse files
committed
chore: configure Ruff, Ty, and mypy for Python 3.14
1 parent 2065b25 commit 4cb57e5

6 files changed

Lines changed: 202 additions & 225 deletions

File tree

common/safe_path.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
from pathlib import Path
2-
from typing import Self
34

45
PyPath = Path | str
56

@@ -19,7 +20,7 @@ def __init__(self, path: PyPath) -> None:
1920
self._safe_path = save_path
2021
self._original_absolute: str = str(save_path.resolve().absolute())
2122

22-
def __truediv__(self, path_part: PyPath | Self) -> Self:
23+
def __truediv__(self, path_part: PyPath | SafePath) -> SafePath:
2324
if isinstance(path_part, SafePath):
2425
add_path_part = path_part.path
2526
else:
@@ -33,7 +34,7 @@ def __truediv__(self, path_part: PyPath | Self) -> Self:
3334

3435
save_path = SafePath(new_path)
3536
save_path._set_absolute(self._original_absolute)
36-
return save_path # type: ignore [return-value]
37+
return save_path
3738

3839
def _set_absolute(self, absolute_path: str) -> None:
3940
self._original_absolute = absolute_path

common/source_maps.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from common.error import Error, error
66
from common.map_counter import MapCounter
77

8+
SUPPORTED_SOURCE_MAP_VERSION = 3
9+
810

911
class SourceMap(NamedTuple):
1012
version: int
@@ -54,14 +56,14 @@ def parse_suffix(file_path: str) -> str:
5456
def decode(content: str) -> Error | DecodeResult:
5557
sm = parse_content(content)
5658

57-
if sm.version != 3:
59+
if sm.version != SUPPORTED_SOURCE_MAP_VERSION:
5860
return error(f"Source Maps версии {sm.version} не поддерживается")
5961

6062
files: dict[str, str] = {}
6163
suffix_stats = MapCounter()
6264

63-
for idx, file_path in enumerate(sm.sources):
64-
file_path = remove_prefix(file_path)
65+
for idx, source_path in enumerate(sm.sources):
66+
file_path = remove_prefix(source_path)
6567
file_content = sm.sourcesContent[idx]
6668

6769
suffix_stats.increment(parse_suffix(file_path))

decoder.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def get_saved_folder(map_file: Path) -> str:
4040
for suffix in suffixes:
4141
file_name = file_name.removesuffix(suffix)
4242

43-
assert not file_name.endswith(".js") and not file_name.endswith(".map"), "Не правильно удалились расширения"
43+
if file_name.endswith(".js") or file_name.endswith(".map"):
44+
raise RuntimeError("Не правильно удалились расширения")
45+
4446
return file_name
4547

4648

@@ -70,7 +72,8 @@ def save_decode_result(output_folder: Path, bundle_name: str, decode_result: sou
7072

7173
# Папка в который лежит бандл, относительной данной папки, мы и будет сохранять файлы
7274
relative_folder_in_sm = Path(decode_result.sourceMapStatistic["sourceMapPath"]).parent
73-
for file_path, file_content in decode_result.files.items():
75+
for original_file_path, file_content in decode_result.files.items():
76+
file_path = original_file_path
7477
if check_in_forbidden_symbols(file_path):
7578
forbidden_paths.append(file_path)
7679
print("[INFO]", f"Файл '{file_path}' был убран для сохранения")
@@ -112,15 +115,15 @@ def save_decode_result(output_folder: Path, bundle_name: str, decode_result: sou
112115

113116
def get_sources_maps_files(input_path: Path) -> list[Path]:
114117
if not input_path.exists():
115-
exit(f"Файл или папки '{input_path}' не существует")
118+
sys.exit(f"Файл или папки '{input_path}' не существует")
116119

117120
if input_path.is_dir():
118121
return [file for file in input_path.glob("*.map") if file.is_file()]
119122

120123
if input_path.is_file():
121124
return [input_path]
122125

123-
exit(f"Невозможно определить тип пути: {input_path}")
126+
sys.exit(f"Невозможно определить тип пути: {input_path}")
124127

125128

126129
def decoder(input_path: str, output_folder: str) -> None:

downloader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def parse_array_urls_line(urls_line: str) -> list[str]:
3232
def get_urls_from_file(input_file: str) -> list[str]:
3333
file_path = Path(input_file)
3434
if not file_path.exists():
35-
exit(f"Файл '{file_path.name}' не существует")
35+
sys.exit(f"Файл '{file_path.name}' не существует")
3636

3737
urls: list[str] = []
3838

@@ -61,7 +61,7 @@ def regexp_compile(regexp: str) -> Pattern[str] | None:
6161
def urls_filter(urls: list[str], filter_regexp: str) -> list[str]:
6262
_re = regexp_compile(filter_regexp)
6363
if _re is None:
64-
exit("Ошибка в регулярном выражении")
64+
sys.exit("Ошибка в регулярном выражении")
6565

6666
filtered_urls: list[str] = []
6767
for url in urls:
@@ -88,7 +88,7 @@ def urls_modify(urls: list[str], file_type: FileType) -> list[str]:
8888

8989
def download_by_url(url: str) -> str | None:
9090
try:
91-
_r = requests.get(url)
91+
_r = requests.get(url, timeout=30)
9292
except requests.exceptions.RequestException:
9393
return None
9494

pyproject.toml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,54 @@ authors = [
77
]
88
license = "MIT"
99
readme = "README.md"
10-
requires-python = ">=3.11,<4.0"
10+
requires-python = ">=3.14"
1111

1212
dependencies = [
13-
"requests>=2.28.2,<3.0.0",
13+
"requests>=2.34.2",
1414
]
1515

1616
[project.urls]
1717
Repository = "https://github.com/DanilBox/JavaScript-Source-Maps-Decoder"
1818

1919
[dependency-groups]
2020
dev = [
21-
"black>=23.3.0,<24.0.0",
22-
"isort>=5.12.0,<6.0.0",
23-
"mypy>=1.2.0,<2.0.0",
24-
"types-requests>=2.28.11.17,<3.0.0",
21+
"mypy>=2.3.1",
22+
"ruff>=0.16.3",
23+
"ty>=0.0.72",
24+
"types-requests>=2.28.11.17",
2525
]
2626

27-
[tool.black]
27+
[tool.ruff]
28+
target-version = "py314"
2829
line-length = 120
29-
target-version = ['py311']
30+
exclude = [
31+
".git",
32+
"__pycache__",
33+
".mypy_cache",
34+
"test",
35+
]
3036

31-
[tool.isort]
32-
line_length = 120
33-
profile = "black"
37+
[tool.ruff.lint]
38+
select = [
39+
"E", # pycodestyle
40+
"F", # pyflakes
41+
"I", # isort
42+
"PL", # pylint
43+
"PTH", # flake8-use-pathlib
44+
"PYI", # flake8-pyi
45+
"RUF", # ruff-specific-rules
46+
"S", # flake8-bandit
47+
"TC", # flake8-type-checking
48+
"UP", # pyupgrade
49+
]
50+
ignore = [
51+
"RUF001",
52+
]
3453

3554
[tool.mypy]
36-
python_version = 3.11
55+
python_version = 3.14
3756
strict = true
3857

3958
[tool.uv]
4059
package = false
60+
exclude-newer = "1 week"

0 commit comments

Comments
 (0)