Skip to content

Commit 8d14b8e

Browse files
committed
Fix tasks.py.
1 parent 27c1dea commit 8d14b8e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

pymatgen/analysis/diffusion/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
from __future__ import annotations
44

5+
from importlib.metadata import PackageNotFoundError, version
6+
57
__author__ = "Materials Virtual Lab"
68
__email__ = "[email protected]"
7-
__version__ = "2023.8.15"
9+
10+
try:
11+
__version__ = version("pymatgen")
12+
except PackageNotFoundError: # pragma: no cover
13+
# package is not installed
14+
pass

tasks.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
def make_doc(ctx):
2727
with cd("docs_rst"):
2828
ctx.run("cp ../CHANGES.rst change_log.rst")
29-
ctx.run("sphinx-apidoc --implicit-namespaces --separate -d 7 -o . -f ../pymatgen")
29+
ctx.run(
30+
"sphinx-apidoc --implicit-namespaces --separate -d 7 -o . -f ../pymatgen"
31+
)
3032
ctx.run("rm pymatgen*.tests.rst")
3133
for f in glob.glob("*.rst"):
3234
if f.startswith("pymatgen") and f.endswith("rst"):
@@ -43,7 +45,9 @@ def make_doc(ctx):
4345
else:
4446
if not clean.endswith("tests"):
4547
suboutput.append(line)
46-
if clean.startswith("pymatgen") and not clean.endswith("tests"):
48+
if clean.startswith("pymatgen") and not clean.endswith(
49+
"tests"
50+
):
4751
newoutput.extend(suboutput)
4852
subpackage = False
4953
suboutput = []
@@ -61,24 +65,15 @@ def make_doc(ctx):
6165

6266
@task
6367
def set_ver(ctx):
64-
lines = []
65-
with open("pymatgen/analysis/diffusion/__init__.py") as f:
66-
for l in f:
67-
if "__version__" in l:
68-
lines.append('__version__ = "%s"' % NEW_VER)
69-
else:
70-
lines.append(l.rstrip())
71-
with open("pymatgen/analysis/diffusion/__init__.py", "w") as f:
72-
f.write("\n".join(lines))
7368

7469
lines = []
75-
with open("setup.py") as f:
70+
with open("pyproject.toml") as f:
7671
for l in f:
77-
lines.append(re.sub(r"version=([^,]+),", 'version="%s",' % NEW_VER, l.rstrip()))
78-
with open("setup.py", "w") as f:
72+
lines.append(
73+
re.sub(r"^version = ([^,]+)", f'version = "{NEW_VER}"', l.rstrip())
74+
)
75+
with open("pyproject.toml", "w") as f:
7976
f.write("\n".join(lines))
80-
ctx.run("ruff format pymatgen")
81-
ctx.run("ruff format setup.py")
8277

8378

8479
@task

0 commit comments

Comments
 (0)