-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathtasks.py
106 lines (85 loc) · 2.41 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
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.
import json
import os
import webbrowser
from importlib import metadata
import requests
from invoke import task
from monty.os import cd
"""
Deployment file to facilitate releases.
"""
__author__ = "Shyue Ping Ong, Anubhav Jain"
__email__ = "ongsp@ucsd.edu"
__date__ = "Sep 1, 2014"
fw_version = f"v{metadata.version('fireworks')}"
@task
def make_doc(ctx) -> None:
with cd("docs_rst"):
ctx.run("sphinx-apidoc -o . -f ../fireworks")
ctx.run("make html")
with cd("docs"):
ctx.run("cp -r html/* .")
ctx.run("rm -r html")
ctx.run("rm -r doctrees")
# Avoid the use of jekyll so that _dir works as intended.
ctx.run("touch .nojekyll")
@task
def update_doc(ctx) -> None:
make_doc(ctx)
with cd("docs"):
ctx.run("git add .")
ctx.run(f'git commit -a -m "Update to {fw_version}"')
ctx.run("git push")
@task
def publish(ctx) -> None:
"""
Build and publish the package to PyPI.
"""
# Clean up previous build artifacts
ctx.run("rm -rf dist/ build/ *.egg-info")
# Build source and wheel distributions
ctx.run("python -m build")
# Upload to PyPI using twine
ctx.run("twine upload dist/*")
@task
def release_github(ctx) -> None:
"""
Create a new release on GitHub.
"""
payload = {
"tag_name": fw_version,
"target_commitish": "master",
"name": fw_version,
"body": "",
"draft": False,
"prerelease": False,
}
# For this to work properly, you need to go to your Github profile, generate
# a "Personal access token". Then do export GITHUB_RELEASES_TOKEN="xyz1234"
# (or add it to your bash_profile).
response = requests.post(
"https://api.github.com/repos/materialsproject/fireworks/releases",
data=json.dumps(payload),
headers={"Authorization": "token " + os.environ["GITHUB_RELEASES_TOKEN"]},
)
print(response.text)
@task
def release(ctx) -> None:
"""
Full release process:
- Publish the package to PyPI.
- Update the documentation.
- Create a GitHub release.
"""
publish(ctx)
update_doc(ctx)
release_github(ctx)
@task
def open_doc(ctx) -> None:
"""
Open the local documentation in a web browser.
"""
pth = os.path.abspath("docs/index.html")
webbrowser.open("file://" + pth)