-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
85 lines (75 loc) · 2.82 KB
/
setup.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
import os, sys, json
from os.path import join
from setuptools import setup
from generate_readme import generate_readme
if __name__ == "__main__":
with open("build_config.json") as f:
settings = json.load(f)
def make_toml(tables: dict):
toml = ""
for t in tables:
toml += f"[{t}]\n"
# Get table dict and write it
tab = tables[t]
for l in tab:
if isinstance(tab[l], str):
toml += f'{l} = "{tab[l]}"\n'
else:
toml += f"{l} = {tab[l]}\n"
toml += "\n"
return toml.strip()
data = {
"build-system": {
"requires": ["setuptools>=61.0"],
"build-backend": "setuptools.build_meta",
},
"project": {
"name": (name := settings["name"]),
# "author": (author := settings["author"]),
# "url": (baseurl := settings["url"] + f"{name}/"),
"version": settings["version"],
"description": settings["description"],
# "maintainter": author,
# "copyright": f"Copyright 2022, {author}",
"readme": "README.md",
"requires-python": ">=3.8",
"classifiers": [
"Development Status :: 1 - Planning",
"Environment :: Console",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
"dependencies": (requirements := settings["requirements"]),
"keywords": [],
},
"project.urls": {
'"Homepage"': (baseurl := settings["url"] + f"{name}/"),
'"Bug Tracker"': baseurl + "issues",
},
}
root = os.path.abspath(os.path.dirname(__file__))
# Regenerate pyproject.toml
with open(join(root, "pyproject.toml"), "w+") as f:
f.write(make_toml(data))
# Regenerate README.md
with open(join(root, "README.md"), "w+") as f:
readme = generate_readme(data, settings["changelog"])
f.write(readme)
# Regenerate requirements.txt
with open(join(root, "requirements.txt"), "w+") as f:
f.writelines(requirements)
# was getting error when reusing generated value rather than read from file
with open(join(root, "README.md"), "r") as f:
readme = f.read()
setup(
name=name,
author_email=settings["email"],
long_description=readme,
# long_description_content_type="",
)