Skip to content

Commit

Permalink
Merge pull request #213 from w-bonelli/fix-update-version
Browse files Browse the repository at this point in the history
fix update_version.py: read authors from CITATION.cff, write to version.py
  • Loading branch information
jmccreight committed Jul 18, 2023
2 parents f8a9fdd + ee516f9 commit e186c72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import textwrap
import yaml
from datetime import datetime
from pathlib import Path

Expand All @@ -10,6 +11,7 @@
_project_name = "pywatershed"
_project_root_path = Path(__file__).parent.parent.parent
_version_txt_path = _project_root_path / "version.txt"
_citation_cff_path = _project_root_path / "CITATION.cff"
_version_py_path = _project_root_path / _project_name / "version.py"
_initial_version = Version("0.0.1")
_current_version = Version(_version_txt_path.read_text().strip())
Expand All @@ -21,13 +23,31 @@ def update_version_txt(version: Version):
print(f"Updated {_version_txt_path} to version {version}")


def get_authors():
citation = yaml.safe_load(_citation_cff_path.read_text())
return citation["authors"]


def update_version_py(timestamp: datetime, version: Version):
lines = open(_version_py_path, "r").readlines() if _version_py_path.exists() else []
authors = get_authors()
with open(_version_py_path, "w") as f:
f.write(
f"# {_project_name} version file automatically created using "
f"{Path(__file__).name} on {timestamp:%B %d, %Y %H:%M:%S}\n\n"
)
f.write(f'__version__ = "{version}"\n')
f.writelines(
[
f"__pakname__ = \"{_project_name}\"\n",
"\n",
"author_dict = {\n",
] + [f" \"{a['given-names']} {a['family-names']}\": \"{a['email']}\",\n" for a in authors] + [
"}\n",
"__author__ = \", \".join(author_dict.keys())\n",
"__author_email__ = \", \".join(s for _, s in author_dict.items())\n",
]
)
f.close()
print(f"Updated {_version_py_path} to version {version}")

Expand Down
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ authors:
- family-names: McCreight
given-names: James
orcid: https://orcid.org/0000-0001-6018-425X
email: jmccreight@usgs.gov
- family-names: Langevin
given-names: Christian D.
orcid: https://orcid.org/0000-0001-5610-9759
email: langevin@usgs.gov
- family-names: Hughes
given-names: Joseph D.
orcid: https://orcid.org/0000-0003-1311-2354
email: jdhughes@usgs.gov

0 comments on commit e186c72

Please sign in to comment.