Skip to content

Commit

Permalink
Fix doc of tasks.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Jun 27, 2024
1 parent 2790a12 commit e513aef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ docstring-code-format = true
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"tests/**" = ["ANN201", "D", "PLR0124"]
"tasks.py" = ["D"]
"src/pymatgen/analysis/*" = ["D"]
"src/pymatgen/io/*" = ["D"]
"dev_scripts/*" = ["D"]
Expand Down
46 changes: 14 additions & 32 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
Pyinvoke tasks.py file for automating releases and admin stuff.
To cut a new pymatgen release, use `invoke update-changelog` followed by `invoke release`.
To cut a new pymatgen release:
Author: Shyue Ping Ong
invoke update-changelog
invoke release
"""

from __future__ import annotations
Expand Down Expand Up @@ -88,6 +89,13 @@ def publish(ctx: Context) -> None:

@task
def set_ver(ctx: Context, version: str):
"""
Set version in pyproject.toml file.
Args:
ctx (Context): The context.
version (str): An input version.
"""
with open("pyproject.toml") as file:
lines = [re.sub(r"^version = \"([^,]+)\"", f'version = "{version}"', line.rstrip()) for line in file]

Expand All @@ -104,6 +112,7 @@ def release_github(ctx: Context, version: str) -> None:
Release to Github using Github API.
Args:
ctx (Context): The context.
version (str): The version.
"""
with open("docs/CHANGES.md", encoding="utf-8") as file:
Expand All @@ -129,36 +138,6 @@ def release_github(ctx: Context, version: str) -> None:
print(response.text)


def post_discourse(version: str) -> None:
"""
Post release announcement to http://discuss.matsci.org/c/pymatgen.
Args:
version (str): The version.
"""
with open("CHANGES.rst", encoding="utf-8") as file:
contents = file.read()
tokens = re.split(r"\-+", contents)
desc = tokens[1].strip()
tokens = desc.split("\n")
desc = "\n".join(tokens[:-1]).strip()
raw = f"v{version}\n\n{desc}"
payload = {
"topic_id": 36,
"raw": raw,
}
response = requests.post(
"https://discuss.matsci.org/c/pymatgen/posts.json",
data=payload,
params={
"api_username": os.environ["DISCOURSE_API_USERNAME"],
"api_key": os.environ["DISCOURSE_API_KEY"],
},
timeout=600,
)
print(response.text)


@task
def update_changelog(ctx: Context, version: str | None = None, dry_run: bool = False) -> None:
"""Create a preliminary change log using the git logs.
Expand Down Expand Up @@ -238,6 +217,9 @@ def release(ctx: Context, version: str | None = None, nodoc: bool = False) -> No
def open_doc(ctx: Context) -> None:
"""
Open local documentation in web browser.
Args:
ctx (invoke.Context): The context object.
"""
pth = os.path.abspath("docs/_build/html/index.html")
webbrowser.open(f"file://{pth}")
Expand Down

0 comments on commit e513aef

Please sign in to comment.