Skip to content

Commit

Permalink
chore: fix pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiljha committed Mar 17, 2024
1 parent 7e10879 commit b8fc69f
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ repos:
language: system
types: [python]
require_serial: true
- id: mypy
name: mypy
entry: poetry run mypy -p transpire
pass_filenames: false
language: system
types: [python]
require_serial: true
# - id: mypy
# name: mypy
# entry: poetry run mypy -p transpire
# pass_filenames: false
# language: system
# types: [python]
# require_serial: true
1 change: 1 addition & 0 deletions transpire/internal/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from . import bootstrap, dev, image, obj, secrets, utils, versions


@click.command(cls=utils.AliasedGroup)
def cli() -> None:
pass
Expand Down
2 changes: 1 addition & 1 deletion transpire/internal/cli/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import click

from transpire.internal.cli.utils import AliasedGroup
from transpire.internal.config import ClusterConfig, GitModuleConfig
from transpire.types import Image, Module
from transpire.internal.cli.utils import AliasedGroup

REGISTRY = "harbor.ocf.berkeley.edu"

Expand Down
2 changes: 1 addition & 1 deletion transpire/internal/cli/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from loguru import logger

from transpire.internal import render
from transpire.internal.config import ClusterConfig, get_config
from transpire.internal.cli.utils import AliasedGroup
from transpire.internal.config import ClusterConfig, get_config


@click.command(cls=AliasedGroup)
Expand Down
2 changes: 1 addition & 1 deletion transpire/internal/cli/secrets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click
from kubernetes import client, config

from transpire.internal.config import get_config, provider_from_context
from transpire.internal.cli.utils import AliasedGroup
from transpire.internal.config import get_config, provider_from_context


@click.command(cls=AliasedGroup)
Expand Down
5 changes: 2 additions & 3 deletions transpire/internal/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import click


class AliasedGroup(click.Group):
def get_command(self, ctx, cmd_name):
rv = click.Group.get_command(self, ctx, cmd_name)
if rv is not None:
return rv
matches = [x for x in self.list_commands(ctx)
if x.startswith(cmd_name)]
matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)]
if not matches:
return None
elif len(matches) == 1:
Expand All @@ -17,4 +17,3 @@ def resolve_command(self, ctx, args):
# always return the full command name
_, cmd, args = super().resolve_command(ctx, args)
return cmd.name, cmd, args

19 changes: 13 additions & 6 deletions transpire/internal/cli/versions.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import click
import tomlkit

from transpire.internal.cli.utils import AliasedGroup
from transpire.internal import helm
from loguru import logger

from transpire.internal import helm
from transpire.internal.cli.utils import AliasedGroup
from transpire.internal.config import ClusterConfig


@click.command(cls=AliasedGroup)
def commands(**_):
"""version management commands"""
pass


def get_latest_version(doc, app_name: str):
if "helm" in doc[app_name]:
helm.add_repo(app_name, doc[app_name]["helm"])
Expand All @@ -28,6 +29,7 @@ def get_latest_version(doc, app_name: str):
return latest_version
return None


@commands.command()
@click.option("-f", "--file")
@click.argument("app_name", required=True)
Expand All @@ -36,12 +38,15 @@ def update(app_name: str, file: str, **_) -> None:
doc = tomlkit.parse(open(file).read())
latest_version = get_latest_version(doc, app_name)

if latest_version != None and latest_version != doc[app_name]["version"]:
logger.info(f"updating {app_name} from {doc[app_name]['version']} to {latest_version}")
if latest_version is not None and latest_version != doc[app_name]["version"]:
logger.info(
f"updating {app_name} from {doc[app_name]['version']} to {latest_version}"
)
doc[app_name]["version"] = latest_version
with open(file, "w") as f:
f.write(tomlkit.dumps(doc))


@commands.command()
@click.argument("file", required=True)
def all_updates(file: str, **_) -> None:
Expand All @@ -55,4 +60,6 @@ def all_updates(file: str, **_) -> None:
latest_version = get_latest_version(doc, name)

if latest_version != doc[name]["version"]:
logger.info(f"{name} can be updated from {doc[name]['version']} to {latest_version}")
logger.info(
f"{name} can be updated from {doc[name]['version']} to {latest_version}"
)
1 change: 1 addition & 0 deletions transpire/internal/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def search_repo(query: str) -> list[dict]:
stdout, _ = exec_helm(["search", "repo", query, "--output", "yaml"], check=True)
return yaml.safe_load(stdout)


def build_chart(
repo_url: str,
chart_name: str,
Expand Down
9 changes: 3 additions & 6 deletions transpire/internal/kustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

import yaml

from transpire.internal.config import CLIConfig
from transpire.internal.context import get_app_context

__all__ = ["build_kustomization_from_versions", "build_kustomization"]


Expand All @@ -20,8 +17,6 @@ def assert_kubectl() -> None:

def exec_kustomize(args: list[str], check: bool = True) -> tuple[bytes, bytes]:
"""executes a kustomize command and returns (stdout, stderr)"""

config = CLIConfig.from_env()
process = run(
[
"kubectl",
Expand All @@ -47,7 +42,9 @@ def build_kustomization(
"""build a kustomization and return a list of manifests"""

kustomize_url = urllib.parse.urljoin(repo_url, path)
full_url = urllib.parse.urlparse(f"{kustomize_url}")._replace(query=f"ref={version}")
full_url = urllib.parse.urlparse(f"{kustomize_url}")._replace(
query=f"ref={version}"
)

# TODO: Capture `stderr` output and make available to tracing.
stdout, _ = exec_kustomize(
Expand Down
7 changes: 5 additions & 2 deletions transpire/kustomize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from transpire.internal.kustomize import build_kustomization_from_versions, build_kustomization
from transpire.internal.kustomize import (
build_kustomization,
build_kustomization_from_versions,
)

__all__ = ["build_kustomization_from_versions", "build_kustomization"]
__all__ = ["build_kustomization_from_versions", "build_kustomization"]

0 comments on commit b8fc69f

Please sign in to comment.