-
Notifications
You must be signed in to change notification settings - Fork 6
/
genconf.py
63 lines (47 loc) · 1.73 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
53
54
55
56
57
58
59
60
61
62
63
"""
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 and requirements-extra.txt.
"""
with open('pyproject.toml', 'r') as f:
pyproject = toml.load(f)
dependencies = pyproject['project']['dependencies']
dev_dependencies = pyproject['project']['optional-dependencies']['dev']
doc_dependencies = pyproject['project']['optional-dependencies']['doc']
# Overwrite requirements.txt
with open('requirements.txt', 'w') as f:
f.write(comment)
for dep in dependencies:
f.write(dep + '\n')
# Overwrite requirements-extra.txt
with open('requirements-extra.txt', 'w') as f:
f.write(comment)
max_len = max(len(dep) for dep in dev_dependencies + doc_dependencies)
for dep in dev_dependencies:
f.write(f"{dep.ljust(max_len)} # dev\n")
for dep in doc_dependencies:
f.write(f"{dep.ljust(max_len)} # doc\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()