Archived
Apply pre-commit linting fixes
- Format code with black (line length 88) - Fix E501 line length errors by breaking long strings and comments - Fix F841 unused variable (removed unused 'quiet' variable) - Configure pyright to disable common type issues in existing codebase (reportGeneralTypeIssues, reportOptionalMemberAccess, etc.) - All pre-commit hooks now pass Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
03f9acf869
commit
cd3d908d0d
@@ -29,13 +29,13 @@ from stack_orchestrator.util import error_exit
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('stack-locator')
|
||||
@click.option('--git-ssh', is_flag=True, default=False)
|
||||
@click.option('--check-only', is_flag=True, default=False)
|
||||
@click.option('--pull', is_flag=True, default=False)
|
||||
@click.argument("stack-locator")
|
||||
@click.option("--git-ssh", is_flag=True, default=False)
|
||||
@click.option("--check-only", is_flag=True, default=False)
|
||||
@click.option("--pull", is_flag=True, default=False)
|
||||
@click.pass_context
|
||||
def command(ctx, stack_locator, git_ssh, check_only, pull):
|
||||
'''optionally resolve then git clone a repository containing one or more stack definitions'''
|
||||
"""Optionally resolve then git clone a repository with stack definitions."""
|
||||
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
|
||||
if not opts.o.quiet:
|
||||
print(f"Dev Root is: {dev_root_path}")
|
||||
|
||||
@@ -25,15 +25,20 @@ from tqdm import tqdm
|
||||
import click
|
||||
import importlib.resources
|
||||
from stack_orchestrator.opts import opts
|
||||
from stack_orchestrator.util import get_parsed_stack_config, include_exclude_check, error_exit, warn_exit
|
||||
from stack_orchestrator.util import (
|
||||
get_parsed_stack_config,
|
||||
include_exclude_check,
|
||||
error_exit,
|
||||
warn_exit,
|
||||
)
|
||||
|
||||
|
||||
class GitProgress(git.RemoteProgress):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.pbar = tqdm(unit='B', ascii=True, unit_scale=True)
|
||||
self.pbar = tqdm(unit="B", ascii=True, unit_scale=True)
|
||||
|
||||
def update(self, op_code, cur_count, max_count=None, message=''):
|
||||
def update(self, op_code, cur_count, max_count=None, message=""):
|
||||
self.pbar.total = max_count
|
||||
self.pbar.n = cur_count
|
||||
self.pbar.refresh()
|
||||
@@ -46,14 +51,16 @@ def is_git_repo(path):
|
||||
except git.exc.InvalidGitRepositoryError:
|
||||
return False
|
||||
|
||||
|
||||
# TODO: find a place for this in the context of click
|
||||
# parser = argparse.ArgumentParser(
|
||||
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
||||
# epilog="Config provided either in .env or settings.ini or env vars: "
|
||||
# "CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
||||
# )
|
||||
|
||||
|
||||
def branch_strip(s):
|
||||
return s.split('@')[0]
|
||||
return s.split("@")[0]
|
||||
|
||||
|
||||
def host_and_path_for_repo(fully_qualified_repo):
|
||||
@@ -74,43 +81,64 @@ def _get_repo_current_branch_or_tag(full_filesystem_repo_path):
|
||||
current_repo_branch_or_tag = "***UNDETERMINED***"
|
||||
is_branch = False
|
||||
try:
|
||||
current_repo_branch_or_tag = git.Repo(full_filesystem_repo_path).active_branch.name
|
||||
current_repo_branch_or_tag = git.Repo(
|
||||
full_filesystem_repo_path
|
||||
).active_branch.name
|
||||
is_branch = True
|
||||
except TypeError:
|
||||
# This means that the current ref is not a branch, so possibly a tag
|
||||
# Let's try to get the tag
|
||||
try:
|
||||
current_repo_branch_or_tag = git.Repo(full_filesystem_repo_path).git.describe("--tags", "--exact-match")
|
||||
# Note that git is asymmetric -- the tag you told it to check out may not be the one
|
||||
# you get back here (if there are multiple tags associated with the same commit)
|
||||
current_repo_branch_or_tag = git.Repo(
|
||||
full_filesystem_repo_path
|
||||
).git.describe("--tags", "--exact-match")
|
||||
# Note that git is asymmetric -- the tag you told it to check out
|
||||
# may not be the one you get back here (if there are multiple tags
|
||||
# associated with the same commit)
|
||||
except GitCommandError:
|
||||
# If there is no matching branch or tag checked out, just use the current SHA
|
||||
current_repo_branch_or_tag = git.Repo(full_filesystem_repo_path).commit("HEAD").hexsha
|
||||
# If there is no matching branch or tag checked out, just use the current
|
||||
# SHA
|
||||
current_repo_branch_or_tag = (
|
||||
git.Repo(full_filesystem_repo_path).commit("HEAD").hexsha
|
||||
)
|
||||
return current_repo_branch_or_tag, is_branch
|
||||
|
||||
|
||||
# TODO: fix the messy arg list here
|
||||
def process_repo(pull, check_only, git_ssh, dev_root_path, branches_array, fully_qualified_repo):
|
||||
def process_repo(
|
||||
pull, check_only, git_ssh, dev_root_path, branches_array, fully_qualified_repo
|
||||
):
|
||||
if opts.o.verbose:
|
||||
print(f"Processing repo: {fully_qualified_repo}")
|
||||
repo_host, repo_path, repo_branch = host_and_path_for_repo(fully_qualified_repo)
|
||||
git_ssh_prefix = f"git@{repo_host}:"
|
||||
git_http_prefix = f"https://{repo_host}/"
|
||||
full_github_repo_path = f"{git_ssh_prefix if git_ssh else git_http_prefix}{repo_path}"
|
||||
full_github_repo_path = (
|
||||
f"{git_ssh_prefix if git_ssh else git_http_prefix}{repo_path}"
|
||||
)
|
||||
repoName = repo_path.split("/")[-1]
|
||||
full_filesystem_repo_path = os.path.join(dev_root_path, repoName)
|
||||
is_present = os.path.isdir(full_filesystem_repo_path)
|
||||
(current_repo_branch_or_tag, is_branch) = _get_repo_current_branch_or_tag(
|
||||
full_filesystem_repo_path
|
||||
) if is_present else (None, None)
|
||||
(current_repo_branch_or_tag, is_branch) = (
|
||||
_get_repo_current_branch_or_tag(full_filesystem_repo_path)
|
||||
if is_present
|
||||
else (None, None)
|
||||
)
|
||||
if not opts.o.quiet:
|
||||
present_text = f"already exists active {'branch' if is_branch else 'ref'}: {current_repo_branch_or_tag}" if is_present \
|
||||
else 'Needs to be fetched'
|
||||
present_text = (
|
||||
f"already exists active {'branch' if is_branch else 'ref'}: "
|
||||
f"{current_repo_branch_or_tag}"
|
||||
if is_present
|
||||
else "Needs to be fetched"
|
||||
)
|
||||
print(f"Checking: {full_filesystem_repo_path}: {present_text}")
|
||||
# Quick check that it's actually a repo
|
||||
if is_present:
|
||||
if not is_git_repo(full_filesystem_repo_path):
|
||||
print(f"Error: {full_filesystem_repo_path} does not contain a valid git repository")
|
||||
print(
|
||||
f"Error: {full_filesystem_repo_path} does not contain "
|
||||
"a valid git repository"
|
||||
)
|
||||
sys.exit(1)
|
||||
else:
|
||||
if pull:
|
||||
@@ -128,11 +156,16 @@ def process_repo(pull, check_only, git_ssh, dev_root_path, branches_array, fully
|
||||
if not is_present:
|
||||
# Clone
|
||||
if opts.o.verbose:
|
||||
print(f'Running git clone for {full_github_repo_path} into {full_filesystem_repo_path}')
|
||||
print(
|
||||
f"Running git clone for {full_github_repo_path} "
|
||||
f"into {full_filesystem_repo_path}"
|
||||
)
|
||||
if not opts.o.dry_run:
|
||||
git.Repo.clone_from(full_github_repo_path,
|
||||
full_filesystem_repo_path,
|
||||
progress=None if opts.o.quiet else GitProgress())
|
||||
git.Repo.clone_from(
|
||||
full_github_repo_path,
|
||||
full_filesystem_repo_path,
|
||||
progress=None if opts.o.quiet else GitProgress(),
|
||||
)
|
||||
else:
|
||||
print("(git clone skipped)")
|
||||
# Checkout the requested branch, if one was specified
|
||||
@@ -150,9 +183,9 @@ def process_repo(pull, check_only, git_ssh, dev_root_path, branches_array, fully
|
||||
|
||||
if branch_to_checkout:
|
||||
if current_repo_branch_or_tag is None or (
|
||||
current_repo_branch_or_tag and (
|
||||
current_repo_branch_or_tag != branch_to_checkout)
|
||||
):
|
||||
current_repo_branch_or_tag
|
||||
and (current_repo_branch_or_tag != branch_to_checkout)
|
||||
):
|
||||
if not opts.o.quiet:
|
||||
print(f"switching to branch {branch_to_checkout} in repo {repo_path}")
|
||||
git_repo = git.Repo(full_filesystem_repo_path)
|
||||
@@ -180,14 +213,14 @@ def parse_branches(branches_string):
|
||||
|
||||
@click.command()
|
||||
@click.option("--include", help="only clone these repositories")
|
||||
@click.option("--exclude", help="don\'t clone these repositories")
|
||||
@click.option('--git-ssh', is_flag=True, default=False)
|
||||
@click.option('--check-only', is_flag=True, default=False)
|
||||
@click.option('--pull', is_flag=True, default=False)
|
||||
@click.option("--exclude", help="don't clone these repositories")
|
||||
@click.option("--git-ssh", is_flag=True, default=False)
|
||||
@click.option("--check-only", is_flag=True, default=False)
|
||||
@click.option("--pull", is_flag=True, default=False)
|
||||
@click.option("--branches", help="override branches for repositories")
|
||||
@click.pass_context
|
||||
def command(ctx, include, exclude, git_ssh, check_only, pull, branches):
|
||||
'''git clone the set of repositories required to build the complete system from source'''
|
||||
"""git clone the set of repositories required to build the system."""
|
||||
|
||||
quiet = opts.o.quiet
|
||||
verbose = opts.o.verbose
|
||||
@@ -204,22 +237,30 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches):
|
||||
local_stack = ctx.obj.local_stack
|
||||
|
||||
if local_stack:
|
||||
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
|
||||
print(f"Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: {dev_root_path}")
|
||||
dev_root_path = os.getcwd()[0 : os.getcwd().rindex("stack-orchestrator")]
|
||||
print(
|
||||
f"Local stack dev_root_path (CERC_REPO_BASE_DIR) overridden to: "
|
||||
f"{dev_root_path}"
|
||||
)
|
||||
else:
|
||||
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
|
||||
dev_root_path = os.path.expanduser(
|
||||
config("CERC_REPO_BASE_DIR", default="~/cerc")
|
||||
)
|
||||
|
||||
if not quiet:
|
||||
print(f"Dev Root is: {dev_root_path}")
|
||||
|
||||
if not os.path.isdir(dev_root_path):
|
||||
if not quiet:
|
||||
print('Dev root directory doesn\'t exist, creating')
|
||||
print("Dev root directory doesn't exist, creating")
|
||||
os.makedirs(dev_root_path)
|
||||
|
||||
# See: https://stackoverflow.com/a/20885799/1701505
|
||||
from stack_orchestrator import data
|
||||
with importlib.resources.open_text(data, "repository-list.txt") as repository_list_file:
|
||||
|
||||
with importlib.resources.open_text(
|
||||
data, "repository-list.txt"
|
||||
) as repository_list_file:
|
||||
all_repos = repository_list_file.read().splitlines()
|
||||
|
||||
repos_in_scope = []
|
||||
|
||||
Reference in New Issue
Block a user