-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathtasks.py
129 lines (105 loc) · 3.46 KB
/
tasks.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""
Deployment file to facilitate releases of pymatgen.analysis.diffusion.
"""
from __future__ import annotations
import datetime
import glob
import json
import os
import re
import requests
from invoke import Context, task
from monty.os import cd
__author__ = "Shyue Ping Ong"
__date__ = "Apr 29, 2012"
NEW_VER = datetime.datetime.today().strftime("%Y.%-m.%-d")
@task
def make_doc(ctx: Context) -> None:
with cd("docs_rst"):
ctx.run("cp ../CHANGES.rst change_log.rst")
ctx.run(
"sphinx-apidoc --implicit-namespaces --separate -d 7 -o . -f ../pymatgen"
)
ctx.run("rm pymatgen*.tests.rst")
for f in glob.glob("*.rst"):
if f.startswith("pymatgen") and f.endswith("rst"):
newoutput = []
suboutput = []
subpackage = False
with open(f) as fid:
for line in fid:
clean = line.strip()
if clean == "Subpackages":
subpackage = True
if not subpackage and not clean.endswith("tests"):
newoutput.append(line)
else:
if not clean.endswith("tests"):
suboutput.append(line)
if clean.startswith("pymatgen") and not clean.endswith(
"tests"
):
newoutput.extend(suboutput)
subpackage = False
suboutput = []
with open(f, "w") as fid:
fid.write("".join(newoutput))
ctx.run("make html")
with cd("docs"):
ctx.run("cp -r html/* .")
ctx.run("rm -r html")
# Avoid ths use of jekyll so that _dir works as intended.
ctx.run("touch .nojekyll")
@task
def set_ver(ctx: Context) -> None:
lines = []
with open("pyproject.toml") as f:
for line in f:
lines.append(
re.sub(r"^version = ([^,]+)", f'version = "{NEW_VER}"', line.rstrip())
)
with open("pyproject.toml", "w") as f:
f.write("\n".join(lines))
f.write("\n")
ctx.run("ruff format pyproject.toml")
@task
def update_doc(
ctx: Context,
) -> None:
make_doc(ctx)
with cd("docs"):
ctx.run("git add .")
ctx.run('git commit -a -m "Update dev docs"')
ctx.run("git push")
@task
def publish(ctx: Context) -> None:
ctx.run("rm dist/*.*", warn=True)
ctx.run("python -m build", warn=True)
ctx.run("twine upload --skip-existing dist/*.whl", warn=True)
ctx.run("twine upload --skip-existing dist/*.tar.gz", warn=True)
@task
def release_github(ctx: Context) -> None:
payload = {
"tag_name": "v" + NEW_VER,
"target_commitish": "master",
"name": "v" + NEW_VER,
"body": "v" + NEW_VER,
"draft": False,
"prerelease": False,
}
response = requests.post(
"https://api.github.com/repos/materialsvirtuallab/pymatgen-analysis-diffusion/releases",
data=json.dumps(payload),
headers={"Authorization": "token " + os.environ["GITHUB_RELEASES_TOKEN"]},
)
print(response.text)
@task
def test(ctx: Context) -> None:
ctx.run("pytest pymatgen")
@task
def release(ctx: Context) -> None:
set_ver(ctx)
# test(ctx)
update_doc(ctx)
publish(ctx)
release_github(ctx)