Skip to content
Open
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
13 changes: 13 additions & 0 deletions src/_canary/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .select import Selector
from .testcase import TestCase
from .workspace import Session
from .workspace import Workspace


project_name = "canary"
Expand Down Expand Up @@ -129,6 +130,18 @@ def canary_configure(config: "CanaryConfig") -> None:
"""


@hookspec
def canary_initfinish(workspace: "Workspace") -> None:
"""Allow plugins to modify the newly initialized workspace without additional user commands/steps.

This hook is called by `canary init` just before exit.

Args:
workspace: The canary Workspace object.

"""


@hookspec
def canary_sessionstart(session: "Session") -> None: ...

Expand Down
17 changes: 16 additions & 1 deletion src/_canary/plugins/subcommands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
from typing import TYPE_CHECKING

from ... import config
from ...hookspec import hookimpl
from ...util import logging
from ...workspace import Workspace
Expand All @@ -23,6 +24,11 @@ def canary_addcommand(parser: "Parser") -> None:
parser.add_command(Init())


@hookimpl(trylast=True)
def canary_initfinish(workspace: Workspace) -> None:
logger.info(f"[bold]Finished[/] initializing canary workspace at {workspace.root.parent}")


class Init(CanarySubcommand):
name = "init"
description = "Initialize a Canary session"
Expand All @@ -35,7 +41,16 @@ def setup_parser(self, parser: "Parser"):
nargs="?",
help="Initialize session in this directory [default: %(default)s]",
)
parser.add_argument(
"-n,--no-post-actions",
action="store_false",
dest="post_actions",
help="Do not run post-initialization actions on the workspace",
)
parser.set_defaults(post_actions=True)

def execute(self, args: "argparse.Namespace") -> int:
Workspace.create(Path(args.path).absolute(), force=args.w)
ws = Workspace.create(Path(args.path).absolute(), force=args.w)
if args.post_actions:
config.pluginmanager.hook.canary_initfinish(workspace=ws)
return 0
Loading