-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.py
67 lines (53 loc) · 1.78 KB
/
release.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
"""Release setup
Check change log, version, and path.
"""
CHANGELOG_TEMPLATE = """
"""
INSERTS = [
(
"github_release",
"[Release {version}](https://github.com/patrick-csliu/TMDB-API-Python/releases/tag/{version})",
),
("version", "{version}"),
]
class Insert:
"""Replace file content"""
def __init__(self, file_content):
self.content = file_content
def insert_content(self, insert_point, content):
"""Insert the content to insert point"""
anchor = f"{{{{insert_point.{insert_point}}}}}"
self.content = self.content.replace(anchor, content)
def get_content(self):
"""return file content"""
return self.content
if __name__ == "__main__":
import tomllib
from os import mkdir
from os.path import exists
# get version from pyproject.toml
with open("pyproject.toml", "rb") as f:
parsed_toml = tomllib.load(f)
version = parsed_toml["project"]["version"]
# check change log
log_dir = "./docs/changelogs"
filepath = f"{log_dir}/changelog_{version}.md"
if not exists(log_dir):
mkdir(log_dir)
if not exists(filepath):
with open(filepath, "x", encoding="utf-8") as f:
f.write(CHANGELOG_TEMPLATE)
# Create README.md
with open("docs/readme_template.md", "r", encoding="utf-8") as f:
readme_file = Insert(f.read())
# point 0
content_p0 = INSERTS[0][1].format(version=version)
readme_file.insert_content(INSERTS[0][0], content_p0)
# point 1
content_p1 = INSERTS[1][1].format(version=version[1:])
readme_file.insert_content(INSERTS[1][0], content_p1)
# save the file
with open("README.md", "w", encoding="utf-8") as f:
f.write(readme_file.get_content())
# returns
print(version, filepath)