Skip to content

Commit

Permalink
Merge pull request #12 from eshwen/esh-align-with-pre-commit-spec
Browse files Browse the repository at this point in the history
Use sys.exit() to align with pre-commit spec
  • Loading branch information
eshwen authored Oct 26, 2023
2 parents ac2d8ec + 1746dc8 commit f4dd019
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pyproject_version_sync/sync_pyproject_version.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
"""This pre-commit hook ensures that the version in pyproject.toml matches the latest git tag."""
import argparse
import logging
import re
import subprocess
import sys
from pathlib import Path

import tomli

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.INFO)
LOGGER.addHandler(logging.StreamHandler())


def _execute_in_shell(cmd: str) -> subprocess.CompletedProcess:
return subprocess.run(cmd.split(), check=True, capture_output=True) # noqa: S603
Expand Down Expand Up @@ -119,13 +115,15 @@ def main() -> None:

if version_pyproject != (version_git := find_latest_tag()):
if not fix:
raise ValueError(
sys.exit(
f"In pyproject.toml, found tool.poetry.version = {version_pyproject}. Expected {version_git}. "
f"Run with the `--fix` option to automatically update.",
f"Run with the `--fix` option to automatically sync.",
)

LOGGER.info("Updating version in pyproject.toml to match latest git tag.")
write_new_version_to_toml(toml_file, version_pyproject, version_git)
sys.exit("Syncing version in pyproject.toml to match latest git tag.")

sys.exit()


if __name__ == "__main__":
Expand Down

0 comments on commit f4dd019

Please sign in to comment.