diff --git a/custodian/__init__.py b/custodian/__init__.py index e63c7146..3faaeb67 100644 --- a/custodian/__init__.py +++ b/custodian/__init__.py @@ -4,6 +4,7 @@ """ import os +from importlib.metadata import PackageNotFoundError, version from .custodian import Custodian @@ -11,7 +12,11 @@ "Shyue Ping Ong, William Davidson Richards, Stephen Dacek, Xiaohui Qu, Matthew Horton, " "Samuel M. Blau, Janosh Riebesell" ) -__version__ = "2024.4.18" +try: + __version__ = version("pymatgen") +except PackageNotFoundError: # pragma: no cover + # package is not installed + pass PKG_DIR = os.path.dirname(__file__) diff --git a/tasks.py b/tasks.py index f2cf6aba..6d8ea479 100644 --- a/tasks.py +++ b/tasks.py @@ -71,12 +71,6 @@ def test(ctx) -> None: @task def set_ver(ctx) -> None: - with open("custodian/__init__.py") as file: - lines = [f'__version__ = "{NEW_VER}"' if "__version__" in line else line.rstrip() for line in file] - - with open("custodian/__init__.py", "w") as file: - file.write("\n".join(lines) + "\n") - with open("pyproject.toml") as file: lines = [re.sub(r"^version = \"([^,]+)\"", f'version = "{NEW_VER}"', line.rstrip()) for line in file]