-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrename.py
More file actions
33 lines (26 loc) · 788 Bytes
/
rename.py
File metadata and controls
33 lines (26 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# fix_toml.py
import re
# Read the file
with open('pyproject.toml', 'r') as f:
lines = f.readlines()
# Find and fix duplicate keys
seen_keys = set()
fixed_lines = []
in_table = None
for i, line in enumerate(lines, 1):
# Check for table headers
if line.strip().startswith('['):
in_table = line.strip()
seen_keys = set()
# Check for key-value pairs
if '=' in line and not line.strip().startswith('#'):
key = line.split('=')[0].strip()
if key in seen_keys:
print(f"Found duplicate at line {i}: {key}")
continue # Skip duplicate
seen_keys.add(key)
fixed_lines.append(line)
# Write back
with open('pyproject.toml', 'w') as f:
f.writelines(fixed_lines)
print("✅ Fixed pyproject.toml")