-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenconf.py
52 lines (37 loc) · 1.19 KB
/
genconf.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Generate configurations from pyproject.toml.
"""
import toml
from datetime import datetime
# Get the current date
current_date = datetime.now().strftime("%Y-%m-%d")
comment = f"# Generated on {current_date}.\n"
def write_req():
"""
Write requirements from pyproject.toml to requirements.txt.
"""
with open('pyproject.toml', 'r') as f:
pyproject = toml.load(f)
dependencies = pyproject['project']['dependencies']
# Overwrite requirements.txt
with open('requirements.txt', 'w') as f:
f.write(comment)
for dep in dependencies:
f.write(dep + '\n')
print("Requirements files generated successfully.")
def write_cfg():
"""
Write versioneer configuration from pyproject.toml to setup.cfg.
"""
with open('pyproject.toml', 'r') as f:
pyproject = toml.load(f)
versioneer = pyproject['tool']['versioneer']
with open('setup.cfg', 'w') as f:
f.write(comment)
f.write("[versioneer]\n")
for key, value in versioneer.items():
f.write(f"{key} = {value}\n")
print("Versioneer configuration generated successfully.")
if __name__ == "__main__":
write_req()
write_cfg()