Skip to content

Commit d2c7f9c

Browse files
committed
chore: formatting
1 parent 2fd89db commit d2c7f9c

30 files changed

+179
-243
lines changed

pyproject.toml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,40 @@ build-backend = "poetry.core.masonry.api"
2424
package-mode = false
2525

2626
[tool.black]
27-
line-length = 88
27+
line-length = 120
2828
target-version = ['py313']
2929

30+
[tool.ruff]
31+
line-length = 120
32+
3033
[tool.ruff.lint]
31-
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
32-
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
33-
# McCabe complexity (`C901`) by default.
34-
select = ["E4", "E7", "E9", "F", "B", "ICN", "PT", "SIM", "TC", "PERF", "W", "C4"]
34+
select = ["ALL"]
35+
ignore = [
36+
"A001", # Variable `...` is shadowing a Python builtin
37+
"BLE001", # Do not catch blind exception: `Exception`
38+
"CPY001", # Missing copyright notice at top of file
39+
"D1",
40+
"D211", # `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
41+
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
42+
"DOC201", # `return` is not documented in docstring
43+
"D417", # Missing argument descriptions in the docstring for ...
44+
"EM101", # Exception must not use a string literal, assign to variable first
45+
"ERA001", # Found commented-out code
46+
"FBT001", # Boolean-typed positional argument in function definition
47+
"FBT003", # Boolean positional value in function call
48+
"N8",
49+
"PLW0603", # Using the global statement to update `...` is discouraged
50+
"PLR2004", # Magic value used in comparison
51+
"S101", # Use of `assert` detected
52+
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
53+
"TRY002", # Create your own exception
54+
"TRY003", # Avoid specifying long messages outside the exception class
55+
"TRY301", # Abstract `raise` to an inner function
56+
]
57+
58+
[tool.ruff.lint.mccabe]
59+
max-complexity = 15
60+
61+
[tool.ruff.lint.pylint]
62+
max-args = 8
63+
max-locals = 20

src/ashton_and_string.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
22

3+
import itertools
34
import os
45
import sys
5-
import itertools
6+
from pathlib import Path
67
from typing import IO
78

89

@@ -91,8 +92,8 @@ def main(fptr: IO) -> None:
9192

9293

9394
if __name__ == "__main__":
94-
if "OUTPUT_PATH" in os.environ:
95-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
95+
if path := os.getenv("OUTPUT_PATH"):
96+
with Path(path).open("wt", encoding="utf-8") as fptr:
9697
main(fptr)
9798
fptr.close()
9899
else:

src/bigger_is_greater.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
from pathlib import Path
56
from typing import IO
67

78

@@ -18,7 +19,7 @@ def switchAbove(word: list[int]) -> bool:
1819

1920
def switchBelow(word: list[int], best: list[int]) -> list[int]:
2021
previous_equal = True
21-
for i in range(0, len(word) - 1):
22+
for i in range(len(word) - 1):
2223
if previous_equal and word[i] == best[i]:
2324
continue
2425
previous_equal = False
@@ -57,8 +58,8 @@ def main(fptr: IO) -> None:
5758

5859

5960
if __name__ == "__main__":
60-
if "OUTPUT_PATH" in os.environ:
61-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
61+
if path := os.getenv("OUTPUT_PATH"):
62+
with Path(path).open("wt", encoding="utf-8") as fptr:
6263
main(fptr)
6364
fptr.close()
6465
else:

src/climbing_the_leaderboard.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22

3-
import sys
43
import os
4+
import sys
5+
from pathlib import Path
56
from typing import IO
67

78

@@ -38,8 +39,8 @@ def main(fptr: IO) -> None:
3839

3940

4041
if __name__ == "__main__":
41-
if "OUTPUT_PATH" in os.environ:
42-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
42+
if path := os.getenv("OUTPUT_PATH"):
43+
with Path(path).open("wt", encoding="utf-8") as fptr:
4344
main(fptr)
4445
fptr.close()
4546
else:

src/determining_dna_health.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#!/usr/bin/env python3
22

3-
import sys
4-
import os
53
import bisect
6-
from collections import defaultdict
7-
from typing import IO, Dict, List
8-
from collections import deque
4+
import os
5+
import sys
6+
from collections import defaultdict, deque
97
from operator import itemgetter
8+
from pathlib import Path
9+
from typing import IO
1010

1111

1212
class TrieNode:
13-
def __init__(self):
13+
def __init__(self) -> None:
1414
# Initialize TrieNode attributes
15-
self.children: Dict[str, TrieNode] = defaultdict(TrieNode)
16-
self.output: List[str] = []
15+
self.children: dict[str, TrieNode] = defaultdict(TrieNode)
16+
self.output: list[str] = []
1717
self.fail: TrieNode | None = None
1818

1919

@@ -116,10 +116,6 @@ def main(fptr: IO) -> None:
116116
len_min = min(len_min, len(g))
117117
alphabet.update(list(g))
118118

119-
print(
120-
f"Alphabet of {len(alphabet)}, genes length between {len_min} and {len_max}, {len(genes_dict)} genes, {s} strands"
121-
)
122-
123119
dnas = []
124120
for _ in range(s):
125121
first_multiple_input = input().rstrip().split()
@@ -132,7 +128,6 @@ def main(fptr: IO) -> None:
132128
min_h = sys.maxsize
133129

134130
if len_min == len_max:
135-
print("Fast Mode!")
136131
for first, last, d in dnas:
137132
h = 0
138133
for i in range(len(d) - len_min + 1):
@@ -144,7 +139,6 @@ def main(fptr: IO) -> None:
144139

145140
else:
146141
# Build the Aho-Corasick automaton
147-
print("Aho-Corasick!")
148142
genes_unique = set(genes)
149143
trie = build_automaton(genes_unique)
150144
for first, last, d in dnas:
@@ -156,8 +150,8 @@ def main(fptr: IO) -> None:
156150

157151

158152
if __name__ == "__main__":
159-
if "OUTPUT_PATH" in os.environ:
160-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
153+
if path := os.getenv("OUTPUT_PATH"):
154+
with Path(path).open("wt", encoding="utf-8") as fptr:
161155
main(fptr)
162156
fptr.close()
163157
else:

src/encryption.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
22

3+
import math
34
import os
45
import sys
5-
import math
6+
from pathlib import Path
67
from typing import IO
78

89

@@ -31,8 +32,8 @@ def main(fptr: IO) -> None:
3132

3233

3334
if __name__ == "__main__":
34-
if "OUTPUT_PATH" in os.environ:
35-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
35+
if path := os.getenv("OUTPUT_PATH"):
36+
with Path(path).open("wt", encoding="utf-8") as fptr:
3637
main(fptr)
3738
fptr.close()
3839
else:

src/magic_square_forming.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
from pathlib import Path
56
from typing import IO
67

78
min_cost = 100
@@ -37,8 +38,6 @@ def loop(s: list[int], pos: int, cost: int) -> None:
3738
else:
3839
loop(s, pos + 1, c)
3940

40-
return
41-
4241

4342
def formingMagicSquare(s: list[list[int]]) -> int:
4443
flat = [x for xs in s for x in xs]
@@ -53,8 +52,8 @@ def main(fptr: IO) -> None:
5352

5453

5554
if __name__ == "__main__":
56-
if "OUTPUT_PATH" in os.environ:
57-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
55+
if path := os.getenv("OUTPUT_PATH"):
56+
with Path(path).open("wt", encoding="utf-8") as fptr:
5857
main(fptr)
5958
fptr.close()
6059
else:

src/matrix_rotation_algo.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
#!/usr/bin/env python3
22

3-
import sys
43
import os
4+
import sys
5+
from pathlib import Path
56
from typing import IO
67

78

8-
def print_matrix(matrix: list[list[int]]) -> None:
9-
for r in matrix:
10-
fptr.write(" ".join(map(str, r)) + "\n")
11-
12-
139
def rotate(matrix: list[list[int]], layer: int, m: int, n: int) -> None:
14-
"""Rotate matrix with m lines, n columns"""
10+
"""Rotate matrix with m lines, n columns."""
1511
tmp = matrix[layer][layer]
1612
# left border
1713
for i in range(layer + 1, m - layer):
@@ -57,12 +53,12 @@ def main(fptr: IO) -> None:
5753
assert len(line) == n
5854
matrix.append(line)
5955
matrixRotation(matrix, r, m, n)
60-
print_matrix(matrix)
56+
fptr.writelines(" ".join(map(str, r)) + "\n" for r in matrix)
6157

6258

6359
if __name__ == "__main__":
64-
if "OUTPUT_PATH" in os.environ:
65-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
60+
if path := os.getenv("OUTPUT_PATH"):
61+
with Path(path).open("wt", encoding="utf-8") as fptr:
6662
main(fptr)
6763
fptr.close()
6864
else:

src/morgan_and_a_string.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22

3-
import sys
43
import os
4+
import sys
5+
from pathlib import Path
56
from typing import IO
67

78

@@ -27,8 +28,8 @@ def main(fptr: IO) -> None:
2728

2829

2930
if __name__ == "__main__":
30-
if "OUTPUT_PATH" in os.environ:
31-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
31+
if path := os.getenv("OUTPUT_PATH"):
32+
with Path(path).open("wt", encoding="utf-8") as fptr:
3233
main(fptr)
3334
fptr.close()
3435
else:

src/quadrant_queries_v1.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import math
44
import os
55
import sys
6+
from pathlib import Path
67
from typing import IO
78

89

910
# count nodes in a range
1011
def countNodes(
11-
start: int, end: int, level: int, leaf_start: int, leaf_end: int
12+
start: int, end: int, level: int, leaf_start: int, leaf_end: int,
1213
) -> list[int]:
1314
leafs = 2 ** (levels - level)
1415
node_idx = 2 ** (level - 1) - 1 + leaf_end // leafs - 1
@@ -58,10 +59,10 @@ def flipNodes(
5859
else:
5960
split = leaf_start + (leaf_end - leaf_start) // 2
6061
left = flipNodes(
61-
start, min(end, split), level + 1, leaf_start, split, flip, deepInit
62+
start, min(end, split), level + 1, leaf_start, split, flip, deepInit,
6263
)
6364
right = flipNodes(
64-
max(start, split + 1), end, level + 1, split + 1, leaf_end, flip, deepInit
65+
max(start, split + 1), end, level + 1, split + 1, leaf_end, flip, deepInit,
6566
)
6667
n = [left[i] + right[i] for i in range(4)]
6768
tree[node_idx][:4] = n
@@ -125,8 +126,8 @@ def main(fptr: IO) -> None:
125126

126127

127128
if __name__ == "__main__":
128-
if "OUTPUT_PATH" in os.environ:
129-
with open(os.environ["OUTPUT_PATH"], "wt") as fptr:
129+
if path := os.getenv("OUTPUT_PATH"):
130+
with Path(path).open("wt", encoding="utf-8") as fptr:
130131
main(fptr)
131132
fptr.close()
132133
else:

0 commit comments

Comments
 (0)