Skip to content
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
1 change: 0 additions & 1 deletion .import_linter_config
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ ignore_imports =
# To reduce the effort in using nox sessions (i.e. having to pass the config path
# in each CLI usage), we allow the noxconfig to be imported within these modules.
exasol.toolbox.nox.* -> noxconfig
exasol.toolbox.tools.template -> noxconfig
5 changes: 3 additions & 2 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
## Refactoring

* #731: Reduced costly `test-python-environment.yml` to run when triggered on `main` or when the files related to the action are altered
* #785: Remove nox session `project:report` and metrics-schema, as superseded by Sonar usage
* #763: Parse and Manipulate Changes Files
* #785: Removed nox session `project:report` and metrics-schema, as superseded by Sonar usage
* #763: Parsed and manipulated Changes Files
* #788: Removed tbx workflow CLI commands, as superseded by nox session `workflow:generate`
18 changes: 0 additions & 18 deletions doc/user_guide/features/github_workflows/create_and_update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,3 @@ Add all Workflows to Your Project
.. warning::
Some workflows depend on other workflows. Please ensure you have all
the required workflows if you do not install all of them.

.. note::

The commands:

* ``tbx workflow install all`` - used to install workflows
* ``tbx workflow update all`` - used to update workflows

are considered historic variants of this command.

**Deprecation Notice:**
These ``tbx`` endpoints are marked as **deprecated** and are scheduled for removal
by **April 22nd, 2026**.

Please note that these legacy commands do not allow users to use their specified
``.workflow-patcher.yml`` file to further customise or patch workflows. Users
should transition to the ``nox``-based command to leverage full customisation
features.
2 changes: 0 additions & 2 deletions doc/user_guide/features/github_workflows/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ workflows from the templates.
In most cases, we recommend using _all_ workflows without change to ensure
consistent interdependencies. For more details, see :ref:`ci_actions`.

The deprecated alternate is to use the CLI provided by
``poetry run -- tbx workflow --help``. This will be removed by April 22nd, 2026.

Workflows
---------
Expand Down
17 changes: 6 additions & 11 deletions exasol/toolbox/tools/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

CLI = typer.Typer()
PKG = "exasol.toolbox.templates.github.ISSUE_TEMPLATE"
TEMPLATE_TYPE = "issue"
LEXER = "markdown"


Expand All @@ -25,9 +24,7 @@ def show_issue(
issue: str = typer.Argument(..., help="issue which shall be shown."),
) -> None:
"""Shows a specific issue."""
template.show_templates(
template=issue, pkg=PKG, template_type=TEMPLATE_TYPE, lexer=LEXER
)
template.show_templates(template=issue, pkg=PKG, lexer=LEXER)


@CLI.command(name="diff")
Expand All @@ -40,7 +37,9 @@ def diff_issue(
) -> None:
"""Diff a specific issue against the installed one."""
template.diff_template(
template=issue, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE
template=issue,
dest=dest,
pkg=PKG,
)


Expand All @@ -57,9 +56,7 @@ def install_issue(

Attention: If there is an existing issue with the same name it will be overwritten!
"""
template.install_template(
template=issue, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE
)
template.install_template(template=issue, dest=dest, pkg=PKG)


@CLI.command(name="update")
Expand All @@ -74,9 +71,7 @@ def update_issue(
),
) -> None:
"""Similar to install but checks for existing issues and shows diff"""
template.update_template(
template=issue, dest=dest, confirm=confirm, pkg=PKG, template_type=TEMPLATE_TYPE
)
template.update_template(template=issue, dest=dest, confirm=confirm, pkg=PKG)


if __name__ == "__main__":
Expand Down
2 changes: 0 additions & 2 deletions exasol/toolbox/tools/tbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
issue,
lint,
security,
workflow,
)

CLI = typer.Typer()
CLI.add_typer(workflow.CLI, name="workflow", help="Manage github workflows")
CLI.add_typer(security.CLI, name="security", help="Security related helpers")
CLI.add_typer(issue.CLI, name="issue", help="Manage issue templates")
CLI.add_typer(lint.CLI, name="lint", help="linting related helpers")
Expand Down
80 changes: 27 additions & 53 deletions exasol/toolbox/tools/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
from rich.console import Console
from rich.syntax import Syntax

from exasol.toolbox.util.workflows.workflow import Workflow
from noxconfig import PROJECT_CONFIG

stdout = Console()
stderr = Console(stderr=True)

Expand Down Expand Up @@ -49,13 +46,12 @@ def __rich__(self) -> str:
def show_templates(
template: str,
pkg: str,
template_type: str,
lexer: str,
) -> None:
"""Shows a specific template."""
templates = _templates(pkg)
if template not in templates:
stdout.print(f"Unknown {template_type} <{template}>.", style="red")
stdout.print(f"Unknown <{template}>.", style="red")
raise typer.Exit(code=1)

template = templates[template]
Expand All @@ -64,22 +60,11 @@ def show_templates(
) # type: ignore


def _render_template(
src: str | Path,
) -> str:
src_path = Path(src)
github_template_dict = PROJECT_CONFIG.github_template_dict
workflow = Workflow.load_from_template(
file_path=src_path, github_template_dict=github_template_dict
)
return workflow.content + "\n"


def diff_template(template: str, dest: Path, pkg: str, template_type: str) -> None:
def diff_template(template: str, dest: Path, pkg: str) -> None:
"""Diff a specific template against the installed one."""
templates = _templates(pkg)
if template not in templates:
stdout.print(f"Unknown {template_type} <{template}>.", style="red")
stdout.print(f"Unknown <{template}>.", style="red")
raise typer.Exit(code=1)

# Use Any type to enable reuse of the variable/binding name
Expand All @@ -91,46 +76,34 @@ def diff_template(template: str, dest: Path, pkg: str, template_type: str) -> No
old = stack.enter_context(
open(old, encoding="utf-8") if old.exists() else io.StringIO("")
)
if template_type == "issue":
new = stack.enter_context(open(new, encoding="utf-8"))
old = old.read().split("\n")
new = new.read().split("\n")
elif template_type == "workflow":
new = _render_template(src=new)
old = old.read().split("\n")
new = new.split("\n")
new = stack.enter_context(open(new, encoding="utf-8"))
old = old.read().split("\n")
new = new.read().split("\n")

diff = difflib.unified_diff(old, new, fromfile="old", tofile="new")
stdout.print(Syntax("\n".join(diff), "diff"))


def _install_template(
template_type: str,
src: str | Path,
dest: str | Path,
exists_ok: bool = False,
) -> None:
src, dest = Path(src), Path(dest)

if dest.exists() and not exists_ok:
raise FileExistsError(f"{template_type} already exists")
raise FileExistsError(f"{dest} already exists")

with ExitStack() as stack:
if template_type == "issue":
input_file = stack.enter_context(open(src, "rb"))
output_file = stack.enter_context(open(dest, "wb"))
output_file.write(input_file.read())
return

input_file = stack.enter_context(open(src, "rb"))
output_file = stack.enter_context(open(dest, "wb"))
rendered_string = _render_template(src=src)
output_file.write(rendered_string.encode("utf-8"))
output_file.write(input_file.read())


def _select_templates(template: str, pkg: str, template_type: str) -> Mapping[str, Any]:
def _select_templates(template: str, pkg: str) -> Mapping[str, Any]:
templates = _templates(pkg)
if template != "all" and template not in templates:
raise Exception(f"{template_type} <{template}> is unknown")
raise FileNotFoundError(f"<{template}> is unknown")
templates = (
templates
if template == "all"
Expand All @@ -139,7 +112,7 @@ def _select_templates(template: str, pkg: str, template_type: str) -> Mapping[st
return templates


def install_template(template: str, dest: Path, pkg: str, template_type: str) -> None:
def install_template(template: str, dest: Path, pkg: str) -> None:
"""
Installs the requested template into the target directory.

Expand All @@ -149,49 +122,50 @@ def install_template(template: str, dest: Path, pkg: str, template_type: str) ->
dest.mkdir(parents=True)

try:
templates = _select_templates(template, pkg, template_type)
except Exception as ex:
templates = _select_templates(template, pkg)
except FileNotFoundError as ex:
stderr.print(f"[red]{ex}[/red]")
raise typer.Exit(-1)

for name, path in templates.items():
destination = dest / f"{name}{path.suffix}"
_install_template(template_type, path, destination, exists_ok=True)
_install_template(path, destination, exists_ok=True)
stderr.print(f"Installed {name} in {destination}")


def update_template(
template: str, dest: Path, confirm: bool, pkg: str, template_type: str
template: str,
dest: Path,
confirm: bool,
pkg: str,
) -> None:
"""Similar to install but checks for existing templates and shows diff"""
if not dest.exists():
dest.mkdir(parents=True)

try:
templates = _select_templates(template, pkg, template_type)
except Exception as ex:
templates = _select_templates(template, pkg)
except FileNotFoundError as ex:
stderr.print(f"[red]{ex}[/red]")
raise typer.Exit(-1)

if confirm:
install_template(template, dest, pkg, template_type)
install_template(template, dest, pkg)
raise typer.Exit(0)

for name, path in templates.items():
destination = dest / f"{name}{path.suffix}"
try:
_install_template(template_type, path, destination, exists_ok=False)
_install_template(path, destination, exists_ok=False)
stderr.print(f"Updated {name} in {destination}")
except FileExistsError:
show_diff = typer.confirm(
f"{template_type} <{name}> already exists, show diff?"
)
show_diff = typer.confirm(f"<{name}> already exists, show diff?")
if show_diff:
diff_template(name, dest, pkg, template_type)
diff_template(name, dest, pkg)

overwrite = typer.confirm(f"Overwrite existing {template_type}?")
overwrite = typer.confirm(f"Overwrite existing {template}?")
if overwrite:
_install_template(template_type, path, destination, exists_ok=True)
_install_template(path, destination, exists_ok=True)
stderr.print(f"Updated {name} in {destination}")


Expand Down
111 changes: 0 additions & 111 deletions exasol/toolbox/tools/workflow.py

This file was deleted.

Loading