From 498fa7272e8b86ec0abab59de0ef23f2be3b7f74 Mon Sep 17 00:00:00 2001 From: Colton Hicks Date: Thu, 8 Aug 2024 19:26:54 -0700 Subject: [PATCH] Bumped version to 0.6.1. Updated CHANGELOG. --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 9 +++- poetry.lock | 13 ++++- pyproject.toml | 5 +- scripts/release.py | 115 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 scripts/release.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dc4b673..185e0de 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: hooks: - id: mypy additional_dependencies: - [tokenize-rt==3.2.0, pydantic>=1.0.0, types-paramiko] + [tokenize-rt==3.2.0, pydantic>=1.0.0, types-paramiko, types-toml] - repo: local hooks: - id: tests diff --git a/CHANGELOG.md b/CHANGELOG.md index 89d61f8..9a76c97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [unreleased] +## [0.6.1] - 2024-08-08 + +### Added + +- Program version parser for `CREST` stdout. + ## [0.6.0] - 2024-06-10 ### Changed @@ -108,7 +114,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Can return either `AtomicResult` or `FailedOperation` objects depending on whether calculation succeeded or failed. - Tests for all parsers and the main `parse` function. -[unreleased]: https://github.com/coltonbh/qcparse/compare/0.6.0...HEAD +[unreleased]: https://github.com/coltonbh/qcparse/compare/0.6.1...HEAD +[0.6.1]: https://github.com/coltonbh/qcparse/releases/tag/0.6.1 [0.6.0]: https://github.com/coltonbh/qcparse/releases/tag/0.6.0 [0.5.3]: https://github.com/coltonbh/qcparse/releases/tag/0.5.3 [0.5.2]: https://github.com/coltonbh/qcparse/releases/tag/0.5.2 diff --git a/poetry.lock b/poetry.lock index 6d50ad2..c46bccf 100644 --- a/poetry.lock +++ b/poetry.lock @@ -701,6 +701,17 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "types-toml" +version = "0.10.8.20240310" +description = "Typing stubs for toml" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-toml-0.10.8.20240310.tar.gz", hash = "sha256:3d41501302972436a6b8b239c850b26689657e25281b48ff0ec06345b8830331"}, + {file = "types_toml-0.10.8.20240310-py3-none-any.whl", hash = "sha256:627b47775d25fa29977d9c70dc0cbab3f314f32c8d8d0c012f2ef5de7aaec05d"}, +] + [[package]] name = "typing-extensions" version = "4.12.2" @@ -735,4 +746,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "855f105b636651f904cb6f9143c29e1862cbdd8e19817038eaad68b144a528ed" +content-hash = "c621a17fd99fa64cfc359a2b1a0e28f93351f27b6896eaca75a07c8e9cf6bb94" diff --git a/pyproject.toml b/pyproject.toml index 1748538..af38ff7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,12 @@ [tool.poetry] name = "qcparse" -version = "0.6.0" +version = "0.6.1" description = "A package for parsing Quantum Chemistry program file outputs into structured qcio data objects." authors = ["Colton Hicks "] license = "MIT" readme = "README.md" +repository = "https://github.com/coltonbh/qcparse" +homepage = "https://github.com/coltonbh/qcparse" [tool.poetry.dependencies] python = "^3.8" @@ -19,6 +21,7 @@ pre-commit = "^3.2.0" pytest-cov = "^4.0.0" black = ">=24.0.0" ruff = "^0.0.275" +types-toml = "^0.10.8.20240310" [tool.poetry.scripts] qcparse = "qcparse.cli:main" diff --git a/scripts/release.py b/scripts/release.py new file mode 100644 index 0000000..4d1e9ef --- /dev/null +++ b/scripts/release.py @@ -0,0 +1,115 @@ +import subprocess +import sys +from datetime import datetime + +import toml + + +def get_repo_url(): + """Get the repository URL from pyproject.toml or ask the user for it.""" + try: + with open("pyproject.toml", "r") as file: + pyproject = toml.load(file) + repo_url = pyproject["tool"]["poetry"]["repository"] + return repo_url + except KeyError: + return input("Enter the repository URL (e.g., https://github.com/user/repo): ") + + +def update_version_with_poetry(version): + """Update the version in pyproject.toml using Poetry.""" + print("Updating version in pyproject.toml...") + subprocess.run(["poetry", "version", version], check=True) + + +def update_changelog(version, repo_url): + """Update the CHANGELOG.md file with the new version and today's date.""" + print("Updating CHANGELOG.md...") + with open("CHANGELOG.md", "r") as file: + lines = file.readlines() + + today = datetime.today().strftime("%Y-%m-%d") + new_entry = f"\n## [{version}] - {today}\n" + + # Insert the new entry after the ## [unreleased] section + for i, line in enumerate(lines): + if line.startswith("## [unreleased]"): + lines.insert(i + 1, new_entry) + break + + # Update links at the bottom + unreleased_link = f"[unreleased]: {repo_url}/compare/{version}...HEAD\n" + new_version_link = f"[{version}]: {repo_url}/releases/tag/{version}\n" + + # Ensure the new version link is added right after the [unreleased] link + for i, line in enumerate(lines): + if line.startswith("[unreleased]:"): + lines[i] = unreleased_link + lines.insert(i + 1, new_version_link) + break + + with open("CHANGELOG.md", "w") as file: + file.writelines(lines) + + +def run_git_commands(version): + """Run the git commands to commit the changes, create a new tag, and push.""" + print("Running git commands...") + subprocess.run(["git", "add", "."], check=True) + subprocess.run( + ["git", "commit", "-m", f"Bumped version to {version}. Updated CHANGELOG."], + check=True, + ) + subprocess.run(["git", "tag", version], check=True) + subprocess.run(["git", "push", "--tags"], check=True) + subprocess.run(["git", "push"], check=True) + + +def confirm_version(version: str): + """Ask the user to confirm the version number before proceeding.""" + while True: + response = ( + input(f"Are you sure you want to release {version}? (Y/N): ") + .strip() + .lower() + ) + if response in ["y", "n"]: + return response == "y" + else: + print("Invalid input. Please enter 'Y' or 'N'.") + + +def main(): + """Main entry point for the script.""" + from pathlib import Path + + if len(sys.argv) != 2: + print("Usage: release.py ") + sys.exit(1) + + version = sys.argv[1] + + original_pyproject = Path("pyproject.toml").read_text() + original_changelog = Path("CHANGELOG.md").read_text() + + repo_url = get_repo_url() + update_version_with_poetry(version) + update_changelog(version, repo_url) + if confirm_version(version): + print("Proceeding with the release...") + else: + print("Reverting changes...") + Path("pyproject.toml").write_text(original_pyproject) + Path("CHANGELOG.md").write_text(original_changelog) + sys.exit(1) + try: + run_git_commands(version) + except Exception: + print("Reverting changes...") + Path("pyproject.toml").write_text(original_pyproject) + Path("CHANGELOG.md").write_text(original_changelog) + sys.exit(1) + + +if __name__ == "__main__": + main()