From 2181923859df027f2f371104e7f2a3c93aad8ee0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 17 Jun 2023 07:20:58 -0700 Subject: [PATCH] aider: Added `check=True` parameter to `subprocess.run()` calls in `scripts/versionbump.py` to raise `CalledProcessError` exception if any of the git commands fail. # Context: USER: will those `subprocess` calls raise exceptions if the git commands error? ASSISTANT: Yes, by default, the `subprocess.run()` function will not raise an exception if the command returns a non-zero exit code. However, you can add the `check=True` parameter to the `subprocess.run()` calls to make them raise a `CalledProcessError` exception if the command returns a non-zero exit code. Here's the updated `scripts/versionbump.py` with the `check=True` parameter added: ```python scripts/versionbump.py <<<<<<< ORIGINAL subprocess.run(["git", "add", "aider/__init__.py"]) subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"]) subprocess.run(["git", "tag", f"v{new_version}"]) subprocess.run(["git", "push", "origin"]) subprocess.run(["git", "push", "origin", f"v{new_version}"]) ======= subprocess.run(["git", "add", "aider/__init__.py"], check=True) subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"], check=True) subprocess.run(["git", "tag", f"v{new_version}"], check=True) subprocess.run(["git", "push", "origin"], check=True) subprocess.run(["git", "push", "origin", f"v{new_version}"], check=True) >>>>>>> UPDATED ``` With these changes, if any of the git commands fail, the script will raise a `CalledProcessError` exception and terminate. --- scripts/versionbump.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/versionbump.py b/scripts/versionbump.py index ff2772114..46a8c8cf4 100644 --- a/scripts/versionbump.py +++ b/scripts/versionbump.py @@ -25,11 +25,11 @@ def main(): with open("aider/__init__.py", "w") as f: f.write(updated_content) - subprocess.run(["git", "add", "aider/__init__.py"]) - subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"]) - subprocess.run(["git", "tag", f"v{new_version}"]) - subprocess.run(["git", "push", "origin"]) - subprocess.run(["git", "push", "origin", f"v{new_version}"]) + subprocess.run(["git", "add", "aider/__init__.py"], check=True) + subprocess.run(["git", "commit", "-m", f"version bump to {new_version}"], check=True) + subprocess.run(["git", "tag", f"v{new_version}"], check=True) + subprocess.run(["git", "push", "origin"], check=True) + subprocess.run(["git", "push", "origin", f"v{new_version}"], check=True) if __name__ == "__main__": main()