Skip to content

Commit a1e7ffe

Browse files
authored
refactor: cosmetic fixes to dev reqs updater (#2415)
Removed unnecessary import Unindented some code Renamed some vars to be more clear and consistent Added some input fixing (`lstrip` whitespaces), also corrected it in yml
1 parent 43ca5a1 commit a1e7ffe

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed
Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import re
22
from importlib.metadata import version
3-
from typing import List
43

54
new_pins = {"pre-commit": version("pre-commit")}
65
pre_commit_path = ".pre-commit-config.yaml"
76
with open(pre_commit_path) as f:
87
tools = f.read().split("repo")
9-
for tool in tools:
10-
package_match = re.search("id: (.*)", tool)
11-
if not package_match:
12-
continue
13-
version_match = re.search("rev: (.*)", tool)
14-
if not version_match:
15-
continue
16-
new_pins[package_match.group(1)] = version_match.group(1)
8+
for tool in tools:
9+
package_match = re.search("id: (.*)", tool)
10+
if not package_match:
11+
continue
12+
version_match = re.search("rev: (.*)", tool)
13+
if not version_match:
14+
continue
15+
new_pins[package_match.group(1).lstrip()] = version_match.group(1).lstrip()
1716

18-
lines: List[str] = []
1917
requirements_path = "dev-requirements.txt"
2018
with open(requirements_path) as f:
21-
lines = f.readlines()
22-
for ind, line in enumerate(lines):
23-
package_match = re.search("(.*)==(.*)", line)
24-
if not package_match:
25-
continue
26-
package_name = package_match.group(1)
27-
if package_name in new_pins:
28-
lines[ind] = re.sub("==(.*)", f"=={new_pins[package_name]}", line)
19+
tools = f.readlines()
20+
for ind, tool in enumerate(tools):
21+
package_match = re.search("(.*)==(.*)", tool)
22+
if not package_match:
23+
continue
24+
package_name = package_match.group(1)
25+
if package_name in new_pins:
26+
tools[ind] = re.sub("==(.*)", f"=={new_pins[package_name]}", tool)
2927
with open(requirements_path, "w") as f:
30-
f.writelines(lines)
28+
f.writelines(tools)

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ repos:
2828
args: ["-c", "bandit.conf"]
2929

3030
- repo: https://github.com/jorisroovers/gitlint
31-
rev: v0.17.0
31+
rev: v0.17.0
3232
hooks:
3333
- id: gitlint

0 commit comments

Comments
 (0)