Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for argocd #160

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .github/workflows/_sys_test.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ jobs:
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

system:
needs: check
if: needs.check.outputs.branch-pr == ''
strategy:
matrix:
runs-on: ["ubuntu-latest"]
python-version: ["3.12"]
fail-fast: false
uses: ./.github/workflows/_sys_test.yml
with:
runs-on: ${{ matrix.runs-on }}
python-version: ${{ matrix.python-version }}

dist:
needs: check
if: needs.check.outputs.branch-pr == ''
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"requests",
"ruamel.yaml",
"jinja2",
"polars",
"polars-lts-cpu",
"textual",
]

Expand Down
10 changes: 10 additions & 0 deletions src/edge_containers_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import polars

from ._version import __version__

__all__ = ["__version__"]

# Set formatting of polars tables
polars.Config.set_tbl_hide_column_data_types(True)
polars.Config.set_tbl_hide_dataframe_shape(True)
polars.Config.set_tbl_rows(-1)
polars.Config.set_tbl_cols(-1)
polars.Config.set_fmt_str_lengths(82)
polars.Config.set_tbl_formatting("ASCII_MARKDOWN")
95 changes: 74 additions & 21 deletions src/edge_containers_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import typer

import edge_containers_cli.globals as globals
from edge_containers_cli.cmds.cli import cli
from edge_containers_cli.cli import cli
from edge_containers_cli.definitions import ENV, ECBackends, ECContext, ECLogLevels

from . import __version__
from .backend import backend as ec_backend
from .backend import init_backend
from .logging import init_logging
from .shell import init_shell
from .utils import init_cleanup

__all__ = ["main"]

Expand All @@ -17,6 +21,20 @@ def version_callback(value: bool):
raise typer.Exit()


def backend_callback(ctx: typer.Context, backend: ECBackends):
init_backend(backend)
# Dynamically drop any method not implemented
not_implemented = [
mthd.replace("_", "-") for mthd in ec_backend.get_notimplemented()
]
for command in not_implemented:
typer_commands = ctx.command.commands # type: ignore
if command in typer_commands:
typer_commands.pop(command)

return backend.value


@cli.callback()
def main(
ctx: typer.Context,
Expand All @@ -28,39 +46,74 @@ def main(
help="Log the version of ec and exit",
),
repo: str = typer.Option(
"",
ECContext().repo,
"-r",
"--repo",
help="service/ioc instances repository",
help="Service instances repository",
envvar=ENV.repo.value,
),
namespace: str = typer.Option(
"", "-n", "--namespace", help="kubernetes namespace to use"
target: str = typer.Option(
ECContext().target,
"-t",
"--target",
help="K8S namespace or ARGOCD <project>/<root-app>",
envvar=ENV.target.value,
),
log_level: str = typer.Option(
"WARN", help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)"
backend: ECBackends = typer.Option(
ECBackends.ARGOCD,
"-b",
"--backend",
callback=backend_callback,
is_eager=True,
help="Backend to use",
envvar=ENV.backend.value,
expose_value=True,
),
verbose: bool = typer.Option(
globals.EC_VERBOSE, "-v", "--verbose", help="print the commands we run"
False,
"-v",
"--verbose",
help="Print the commands we run",
envvar=ENV.verbose.value,
show_default=True,
),
dryrun: bool = typer.Option(
False,
"--dryrun",
help="Print the commands we run without execution",
envvar=ENV.dryrun.value,
show_default=True,
),
debug: bool = typer.Option(
globals.EC_DEBUG,
False,
"-d",
"--debug",
help="Enable debug logging to console and retain temporary files",
help="Enable debug logging, retain temp files",
envvar=ENV.debug.value,
show_default=True,
),
log_level: ECLogLevels = typer.Option(
ECLogLevels.WARNING,
help="Log level",
envvar=ENV.log_level.value,
),
log_url: str = typer.Option(
ECContext().log_url,
help="Log url",
envvar=ENV.log_url.value,
),
):
"""Edge Containers assistant CLI"""
init_logging(ECLogLevels.DEBUG if debug else log_level)
init_shell(verbose, dryrun)
init_cleanup(debug)

globals.EC_VERBOSE, globals.EC_DEBUG = bool(verbose), bool(debug)

init_logging(log_level.upper())

# create a context dictionary to pass to all sub commands
repo = repo or globals.EC_SERVICES_REPO
namespace = namespace or globals.EC_K8S_NAMESPACE
ctx.ensure_object(globals.Context)
context = globals.Context(namespace=namespace, beamline_repo=repo)
ctx.obj = context
context = ECContext(
repo=repo,
target=target,
log_url=log_url,
)
ec_backend.set_context(context)


# test with:
Expand Down
Loading
Loading