2020-04-06 11:13:27 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2021-04-25 03:45:27 -04:00
|
|
|
|
2020-04-06 11:13:27 +01:00
|
|
|
import os
|
2024-10-22 10:16:59 -04:00
|
|
|
import subprocess
|
2021-01-17 14:13:26 -05:00
|
|
|
import sys
|
2021-01-06 13:50:58 -05:00
|
|
|
import textwrap
|
2020-04-06 11:13:27 +01:00
|
|
|
import time
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import click
|
|
|
|
|
|
|
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def shell(cmd: str, *, check: bool, **kwargs: object) -> subprocess.CompletedProcess[str]:
|
|
|
|
|
return subprocess.run([cmd], shell=True, check=check, **kwargs) # type: ignore[call-overload, no-any-return]
|
2020-04-06 11:13:27 +01:00
|
|
|
|
|
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def git_repo_has_changes() -> bool:
|
|
|
|
|
unstaged_changes: bool = shell("git diff-index --quiet HEAD --", check=False).returncode != 0
|
|
|
|
|
staged_changes: bool = (
|
|
|
|
|
shell("git diff-index --quiet --cached HEAD --", check=False).returncode != 0
|
|
|
|
|
)
|
2020-04-06 11:13:27 +01:00
|
|
|
return unstaged_changes or staged_changes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
2024-10-22 10:16:59 -04:00
|
|
|
def main() -> None:
|
2021-05-03 11:45:43 -04:00
|
|
|
project_root = Path(__file__).parent / ".."
|
2020-04-06 11:13:27 +01:00
|
|
|
os.chdir(project_root)
|
|
|
|
|
|
2020-04-06 11:52:21 +01:00
|
|
|
if git_repo_has_changes():
|
2021-05-03 11:45:43 -04:00
|
|
|
print("Your git repo has uncommitted changes. Commit or stash before continuing.")
|
2021-01-17 14:13:26 -05:00
|
|
|
sys.exit(1)
|
2020-04-06 11:13:27 +01:00
|
|
|
|
2021-04-30 17:56:34 -04:00
|
|
|
previous_branch = shell(
|
2021-05-03 11:45:43 -04:00
|
|
|
"git rev-parse --abbrev-ref HEAD", check=True, capture_output=True, encoding="utf8"
|
2021-04-30 17:56:34 -04:00
|
|
|
).stdout.strip()
|
2020-04-06 11:13:27 +01:00
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
shell("git fetch origin", check=True)
|
2020-04-06 11:13:27 +01:00
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
timestamp = time.strftime("%Y-%m-%dT%H-%M-%S", time.gmtime())
|
|
|
|
|
branch_name = f"update-constraints-{timestamp}"
|
2020-04-06 11:13:27 +01:00
|
|
|
|
2021-05-27 10:28:52 +01:00
|
|
|
shell(f"git checkout -b {branch_name} origin/main", check=True)
|
2020-04-06 11:13:27 +01:00
|
|
|
|
|
|
|
|
try:
|
2021-05-03 11:45:43 -04:00
|
|
|
shell("bin/update_dependencies.py", check=True)
|
2020-04-06 11:13:27 +01:00
|
|
|
|
|
|
|
|
if not git_repo_has_changes():
|
2021-05-03 11:45:43 -04:00
|
|
|
print("Done: no constraint updates required.")
|
2020-04-06 11:13:27 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
shell('git commit -a -m "Update dependencies"', check=True)
|
2021-04-30 17:56:34 -04:00
|
|
|
body = textwrap.dedent(
|
2021-05-03 11:45:43 -04:00
|
|
|
f"""
|
2021-05-02 16:37:38 +02:00
|
|
|
Update the versions of our dependencies.
|
2020-04-06 11:13:27 +01:00
|
|
|
|
2025-02-28 11:56:29 -05:00
|
|
|
PR generated by `{Path(__file__).name}`.
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
2024-10-22 10:16:59 -04:00
|
|
|
subprocess.run(
|
2021-04-25 03:45:27 -04:00
|
|
|
[
|
2021-05-03 11:45:43 -04:00
|
|
|
"gh",
|
|
|
|
|
"pr",
|
|
|
|
|
"create",
|
2021-05-24 10:21:03 -04:00
|
|
|
"--repo=pypa/cibuildwheel",
|
2021-05-27 10:28:52 +01:00
|
|
|
"--base=main",
|
2021-05-01 19:39:36 +01:00
|
|
|
"--title=Update dependencies",
|
2021-04-25 03:45:27 -04:00
|
|
|
f"--body='{body}'",
|
2020-04-06 11:13:27 +01:00
|
|
|
],
|
2021-04-30 17:56:34 -04:00
|
|
|
check=True,
|
2020-04-06 11:13:27 +01:00
|
|
|
)
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
print("Done.")
|
2020-04-06 11:13:27 +01:00
|
|
|
finally:
|
|
|
|
|
# remove any local changes
|
2023-08-24 11:57:20 -04:00
|
|
|
shell("git checkout -- .", check=True)
|
2021-05-03 11:45:43 -04:00
|
|
|
shell(f"git checkout {previous_branch}", check=True)
|
|
|
|
|
shell(f"git branch -D --force {branch_name}", check=True)
|
2020-04-06 11:13:27 +01:00
|
|
|
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
if __name__ == "__main__":
|
2020-04-06 11:13:27 +01:00
|
|
|
main.main(standalone_mode=True)
|