diff options
author | Franck Cuny <franck@fcuny.net> | 2024-07-22 17:46:36 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2024-07-22 17:46:36 -0700 |
commit | d4b6d2b2053e335e5457e34c128ec8a1a156671d (patch) | |
tree | 95dc405071eed3c61142754249b9de9326f4285d | |
parent | delete github actions (diff) | |
download | world-d4b6d2b2053e335e5457e34c128ec8a1a156671d.tar.gz |
add lint as a target and reformat
Diffstat (limited to '')
-rw-r--r-- | justfile | 3 | ||||
-rwxr-xr-x | packages/git-blame-stats/git-blame-stats.py | 9 | ||||
-rwxr-xr-x | packages/git-broom/git-broom.py | 79 | ||||
-rw-r--r-- | src/cli/gha_billing.py | 1 | ||||
-rwxr-xr-x | src/cli/nomad_allocs.py | 2 | ||||
-rw-r--r-- | src/term/link.py | 2 |
6 files changed, 29 insertions, 67 deletions
diff --git a/justfile b/justfile index 28e05da..829e8f9 100644 --- a/justfile +++ b/justfile @@ -13,3 +13,6 @@ switch-darwin: test-nix: nix flake check nix develop -c echo OK + +fmt: + nix fmt diff --git a/packages/git-blame-stats/git-blame-stats.py b/packages/git-blame-stats/git-blame-stats.py index 3cc4f4a..5f2a43f 100755 --- a/packages/git-blame-stats/git-blame-stats.py +++ b/packages/git-blame-stats/git-blame-stats.py @@ -4,11 +4,8 @@ import argparse import subprocess from typing import Any - parser = argparse.ArgumentParser() -parser.add_argument( - "rev", metavar="revision", type=str, help="the revision", default="HEAD", nargs="?" -) +parser.add_argument("rev", metavar="revision", type=str, help="the revision", default="HEAD", nargs="?") args = parser.parse_args() authors: dict[str, Any] = dict() @@ -90,6 +87,4 @@ for author, stats in authors.items(): lines = stats["lines"] commits = len(stats["commits"]) files = len(stats["files"]) - print( - f"{author:{max_lenght_author}} {email:{max_lenght_email}} {lines:6} {commits:6} {files:6}" - ) + print(f"{author:{max_lenght_author}} {email:{max_lenght_email}} {lines:6} {commits:6} {files:6}") diff --git a/packages/git-broom/git-broom.py b/packages/git-broom/git-broom.py index b508357..27b97c6 100755 --- a/packages/git-broom/git-broom.py +++ b/packages/git-broom/git-broom.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 -import argparse import os import re -import subprocess import sys -from typing import List, Dict - import logging +import argparse +import subprocess +from typing import Dict, List logging.basicConfig(format="[%(asctime)s]%(levelname)s:%(message)s", level=logging.INFO) @@ -83,18 +82,14 @@ class GitConfig(object): self.primary_branch = m.group("branch") return - raise ValueError( - f"can't find the name of the remote branch for {self.remote_name}" - ) + raise ValueError(f"can't find the name of the remote branch for {self.remote_name}") def is_git_repository() -> bool: """Check if we are inside a git repository. Return True if we are, false otherwise.""" - res = subprocess.run( - ["git", "rev-parse", "--show-toplevel"], check=False, capture_output=True - ) + res = subprocess.run(["git", "rev-parse", "--show-toplevel"], check=False, capture_output=True) return not res.returncode @@ -105,9 +100,7 @@ def fetch(remote: str): def ref_sha(ref: str) -> str: """Get the sha from a ref.""" - res = subprocess.run( - ["git", "show-ref", ref], capture_output=True, check=True, encoding="utf-8" - ) + res = subprocess.run(["git", "show-ref", ref], capture_output=True, check=True, encoding="utf-8") return res.stdout.rstrip() @@ -137,9 +130,7 @@ def rebase_local_branches(config: GitConfig, local_rebase_tree_id: dict) -> None _rebase_local_branch(branch, config, local_rebase_tree_id) -def _rebase_local_branch( - branch: str, config: GitConfig, local_rebase_tree_id: dict -) -> None: +def _rebase_local_branch(branch: str, config: GitConfig, local_rebase_tree_id: dict) -> None: res = subprocess.run( [ "git", @@ -152,43 +143,29 @@ def _rebase_local_branch( capture_output=True, ) if res.returncode == 0: - logging.info( - f"local branch {branch} is already a descendant of {config.remote_ref}." - ) + logging.info(f"local branch {branch} is already a descendant of {config.remote_ref}.") local_rebase_tree_id[branch] = ref_tree(branch) return logging.info(f"local branch {branch} will be rebased on {config.remote_ref}.") - subprocess.run( - ["git", "checkout", "--force", branch], check=True, capture_output=True - ) - res = subprocess.run( - ["git", "rebase", config.remote_ref], check=True, capture_output=True - ) + subprocess.run(["git", "checkout", "--force", branch], check=True, capture_output=True) + res = subprocess.run(["git", "rebase", config.remote_ref], check=True, capture_output=True) if res.returncode == 0: logging.info(f"local branch {branch} has been rebased") local_rebase_tree_id[branch] = ref_tree(branch) else: logging.error(f"failed to rebase local branch {branch}.") subprocess.run(["git", "rebase", "--abort"], check=True) - subprocess.run( - ["git", "checkout", "--force", config.primary_branch], check=True - ) + subprocess.run(["git", "checkout", "--force", config.primary_branch], check=True) subprocess.run(["git", "reset", "--hard"], check=True) -def rebase_remote_branches( - config: GitConfig, local_rebase_tree_id: dict, main_sha: str -) -> None: - for branch in get_branches( - ["--list", "-r", f"{config.me}/*", "--no-merged", config.remote_ref] - ): +def rebase_remote_branches(config: GitConfig, local_rebase_tree_id: dict, main_sha: str) -> None: + for branch in get_branches(["--list", "-r", f"{config.me}/*", "--no-merged", config.remote_ref]): _rebase_remote_branches(branch, config, local_rebase_tree_id, main_sha) -def _rebase_remote_branches( - branch: str, config: GitConfig, local_rebase_tree_id: dict, main_sha: str -) -> None: +def _rebase_remote_branches(branch: str, config: GitConfig, local_rebase_tree_id: dict, main_sha: str) -> None: remote, head = branch.split("/") if head in immortal_ref: return @@ -199,9 +176,7 @@ def _rebase_remote_branches( capture_output=True, ) if res.returncode == 0: - logging.info( - f"local branch {branch} is already a descendant of {config.remote_ref}." - ) + logging.info(f"local branch {branch} is already a descendant of {config.remote_ref}.") return logging.info(f"remote branch {branch} will be rebased on {config.remote_ref}.") @@ -226,26 +201,18 @@ def _rebase_remote_branches( logging.info(f"remote branch {branch}, when rebased, same as local branch!") logging.info(f"would run `git push --force-with-lease {remote} {head}'") else: - logging.info( - f"remote branch {branch} has been rebased to create {short_sha}!" - ) - logging.info( - f"would run `git push --force-with-lease {remote} {new_sha}:{head}'" - ) + logging.info(f"remote branch {branch} has been rebased to create {short_sha}!") + logging.info(f"would run `git push --force-with-lease {remote} {new_sha}:{head}'") else: logging.error(f"failed to rebase remote branch {branch}.") subprocess.run(["git", "rebase", "--abort"], check=True) - subprocess.run( - ["git", "checkout", "--force", config.primary_branch], check=True - ) + subprocess.run(["git", "checkout", "--force", config.primary_branch], check=True) subprocess.run(["git", "reset", "--hard"], check=True) def destroy_remote_merged_branches(config: GitConfig, dry_run: bool) -> None: """Destroy remote branches that have been merged.""" - for branch in get_branches( - ["--list", "-r", f"{config.me}/*", "--merged", config.remote_ref] - ): + for branch in get_branches(["--list", "-r", f"{config.me}/*", "--merged", config.remote_ref]): remote, head = branch.split("/") if head in immortal_ref: continue @@ -253,9 +220,7 @@ def destroy_remote_merged_branches(config: GitConfig, dry_run: bool) -> None: if dry_run: logging.info(f"would have run git push {remote} :{head}") else: - subprocess.run( - ["git", "push", remote, f":{head}"], check=True, encoding="utf-8" - ) + subprocess.run(["git", "push", remote, f":{head}"], check=True, encoding="utf-8") def destroy_local_merged_branches(config: GitConfig, dry_run: bool) -> None: @@ -335,9 +300,7 @@ def main(dry_run: bool) -> bool: if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="delete local and remote branches that have been merged." - ) + parser = argparse.ArgumentParser(description="delete local and remote branches that have been merged.") parser.add_argument( "--dry-run", action=argparse.BooleanOptionalAction, diff --git a/src/cli/gha_billing.py b/src/cli/gha_billing.py index 00dd5e3..a501890 100644 --- a/src/cli/gha_billing.py +++ b/src/cli/gha_billing.py @@ -6,6 +6,7 @@ The API for this is documented [here](https://docs.github.com/en/rest/billing/bi For this you need a [token](https://github.com/settings/personal-access-tokens) with the following permissions: - [plan](https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens?apiVersion=2022-11-28#user-permissions-for-plan) """ + import sys import click diff --git a/src/cli/nomad_allocs.py b/src/cli/nomad_allocs.py index 868fea9..cc7e648 100755 --- a/src/cli/nomad_allocs.py +++ b/src/cli/nomad_allocs.py @@ -19,7 +19,7 @@ def cli(job, dc, token): url = f"https://{dc}-nomad.simulprod.com/v1/job/{job}/allocations" try: resp = requests.get(url, headers=headers) - resp.raise_for_status + resp.raise_for_status() except Exception as e: print("return {}".format(str(e))) diff --git a/src/term/link.py b/src/term/link.py index cd75b16..d545d05 100644 --- a/src/term/link.py +++ b/src/term/link.py @@ -6,4 +6,4 @@ def link(text: str, url: str) -> str: For more information on the escape sequence, refer to: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#the-escape-sequence """ - return f""\x1b]8;;{url}\x07{text}\x1b]8;;\x07\u001b[0m"" + return f"\x1b]8;;{url}\x07{text}\x1b]8;;\x07\u001b[0m" |