diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8da5185b5c..9a5245db03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: if: github.ref != 'refs/heads/main' uses: ./.github/workflows/_tox.yml with: - tox: pre-commit,type-checking + tox: pre-commit,type-checking,import-linter test: if: github.ref != 'refs/heads/main' diff --git a/README.md b/README.md index 32adc22ffa..c0803bca26 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Lightweight bluesky-as-a-service wrapper application. Also usable as a library. What | Where :---: | :---: Source | -PyPI | `pip install blueapi[server]` (server) / `pip install blueapi` (client only) +PyPI | `pip install blueapi[server]` (server) / `pip install blueapi[client]` (client) Docker | `docker run ghcr.io/diamondlightsource/blueapi:latest` Documentation | Releases | diff --git a/docs/reference/cli.md b/docs/reference/cli.md index e5a598c117..db803473c7 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -10,7 +10,7 @@ option to the `controller` subcommand to 'full', you would need to set the environment variable `BLUEAPI_CONTROLLER_OUTPUT=full`. ```{eval-rst} -.. click:: blueapi.cli:main +.. click:: blueapi.__main__:main :prog: blueapi :show-nested: ``` diff --git a/docs/tutorials/1. installation.md b/docs/tutorials/1. installation.md index 5313a3111c..f9409544cd 100644 --- a/docs/tutorials/1. installation.md +++ b/docs/tutorials/1. installation.md @@ -34,8 +34,10 @@ from GitHub: python3 -m pip install "blueapi[server] @ git+https://github.com/DiamondLightSource/blueapi.git" ``` -The `server` extra is only needed to run the worker (`blueapi serve`). For the client -and `blueapi controller` commands, `pip install blueapi` is enough. +The `server` extra is needed to run the worker (`blueapi serve`, `setup-scratch` +and `schema`). To only talk to a running worker (`blueapi controller`, `login`, +`logout` and `BlueapiClient`), `pip install blueapi[client]` is enough. Install +`blueapi[server,client]` for both. The library should now be installed and the commandline interface on your path. You can check the version that has been installed by typing: diff --git a/docs/tutorials/7. scripting-plans.md b/docs/tutorials/7. scripting-plans.md index 5a7b8fd889..ad79ad7511 100644 --- a/docs/tutorials/7. scripting-plans.md +++ b/docs/tutorials/7. scripting-plans.md @@ -160,7 +160,7 @@ This will be one of `WorkerEvent`, `ProgressEvent` or `DataEvent`. An example that prints data for each point could be something like ```python -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent def feedback(evt): match evt: diff --git a/pyproject.toml b/pyproject.toml index fe2f73838f..e202addf6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,23 +14,14 @@ classifiers = [ ] description = "Lightweight bluesky-as-a-service wrapper application. Also usable as a library." dependencies = [ - "bluesky[plotting]>=1.14.0", # plotting includes matplotlib, required for BestEffortCallback in run plans - "ophyd-async>=0.13.5", + "bluesky[plotting]>=1.14.0", # plotting includes matplotlib, required for BestEffortCallback in the CLI's run command "pydantic>=2.0", - "pydantic-settings", - "stomp-py", "PyYAML>=6.0.2", "click>=8.2.0", "requests", - "GitPython>=3.1.58", #security base min https://github.com/advisories/GHSA-4gmw-gg2m-w46p - used by the server's /python_environment endpoint and the CLI's scratch setup - "event-model==1.24.0", # https://github.com/DiamondLightSource/blueapi/issues/684 "bluesky-stomp>=0.1.6", - "opentelemetry-distro>=0.48b0", "observability-utils>=0.1.4", "pyjwt[crypto]", - "websockets", - "tqdm", - "packaging", ] dynamic = ["version"] license.file = "LICENSE" @@ -38,10 +29,16 @@ readme = "README.md" requires-python = ">=3.11" [project.optional-dependencies] +# Needed to talk to a running worker: `blueapi controller`, `login`, `logout` and BlueapiClient. +client = ["websockets", "tqdm", "packaging"] demo = ["dls-dodal>=3.0.2", "ophyd-async[sim]"] -# Only needed to run `blueapi serve` (the FastAPI worker service). +# Needed to run the worker service: `blueapi serve`, `setup-scratch` and `schema`. server = [ + "opentelemetry-distro>=0.48b0", + "ophyd-async>=0.13.5", + "event-model==1.24.0", # https://github.com/DiamondLightSource/blueapi/issues/684 + "GitPython>=3.1.58", #security base min https://github.com/advisories/GHSA-4gmw-gg2m-w46p - used by the /python_environment endpoint and scratch setup "fastapi>=0.112.0", "uvicorn>=0.52.1", "aiohttp>=3.13.5", @@ -54,9 +51,10 @@ server = [ [dependency-groups] dev = [ - "blueapi[server]", + "blueapi[server,client]", "ophyd_async[sim]", "copier", + "import-linter", "dls-dodal>=3.0.2", "myst-parser", "prek", @@ -97,7 +95,7 @@ client-system-test = [ ] [project.scripts] -blueapi = "blueapi.cli:main" +blueapi = "blueapi.__main__:main" [project.urls] GitHub = "https://github.com/DiamondLightSource/blueapi" @@ -113,6 +111,81 @@ required-version = ">=0.13.5" [tool.setuptools_scm] version_file = "src/blueapi/_version.py" +[tool.importlinter] +root_package = "blueapi" +include_external_packages = true +exclude_type_checking_imports = true + +[[tool.importlinter.contracts]] +name = "Client does not depend on the server or its dependencies" +type = "forbidden" +source_modules = ["blueapi.client", "blueapi.cli"] +forbidden_modules = [ + "blueapi.core", + "blueapi.worker", + "blueapi.tutorial", + "blueapi.utils.path_provider", + "blueapi.service.authentication", + "blueapi.service.authorization", + "blueapi.service.cli", + "blueapi.service.environment", + "blueapi.service.interface", + "blueapi.service.main", + "blueapi.service.middleware", + "blueapi.service.numtracker", + "blueapi.service.openapi", + "blueapi.service.runner", + "blueapi.service.scratch", + # server extra + "aioca", + "aiohttp", + "dodal", + "event_model", + "fastapi", + "git", + "graypy", + "httpx", + "ophyd", + "ophyd_async", + "starlette", + "tiled", + "uvicorn", +] +ignore_imports = [ + # DeviceModel.from_device is only called by the server + "blueapi.service.model -> blueapi.core.bluesky_types", + "blueapi.service.model -> blueapi.core.context", + # Optional: graylog handler is only imported if graylog is configured + "blueapi.log -> graypy", +] + +[[tool.importlinter.contracts]] +name = "Server does not depend on the client" +type = "forbidden" +source_modules = [ + "blueapi.config", + "blueapi.core", + "blueapi.log", + "blueapi.model", + "blueapi.service", + "blueapi.tutorial", + "blueapi.utils", + "blueapi.worker", +] +forbidden_modules = [ + "blueapi.client", + "blueapi.cli", + # client extra + "packaging", + "tqdm", + "websockets", +] +ignore_imports = [ + # Backwards compatible aliases, to be removed May 2027 + "blueapi.service -> blueapi.client.session", + "blueapi.service.authentication -> blueapi.client.session", +] + [tool.pyright] typeCheckingMode = "standard" reportMissingImports = false # Ignore missing stubs in imported modules @@ -136,7 +209,7 @@ source = ["src", "**/site-packages/"] [tool.tox] skipsdist = true # envs to runs automatically with tox -p -env_list = ["pre-commit", "type-checking", "tests", "docs"] +env_list = ["pre-commit", "type-checking", "import-linter", "tests", "docs"] [tool.tox.env_run_base] # Pass all environment variables to the test environments @@ -171,6 +244,10 @@ commands = [ ], ] +[tool.tox.env.import-linter] +description = "Check the client and server only import what they are allowed to" +commands = [["lint-imports"]] + [tool.tox.env.tests] description = "Run unit tests with coverage" commands = [ @@ -190,7 +267,7 @@ commands = [ ] [tool.tox.env.client-system-test] -description = "Run client system tests with blueapi only, no server dependencies" +description = "Run client system tests with blueapi[client] only, no server dependencies" commands = [ [ "uv", @@ -198,6 +275,8 @@ commands = [ "--isolated", # uv run leaves extra packages in place, so don't reuse the dev venv "--locked", "--no-default-groups", + "--extra", + "client", "--group", "client-system-test", "pytest", diff --git a/src/blueapi/__main__.py b/src/blueapi/__main__.py index ac15394750..75358b0e6d 100644 --- a/src/blueapi/__main__.py +++ b/src/blueapi/__main__.py @@ -1,4 +1,136 @@ -from .cli.cli import main +"""The blueapi command: shared options, plus the client and the server commands. + +Client and server do not import each other, this is the one place they are put together +""" + +import json +import os +import stat +import textwrap +from pathlib import Path + +import click +from click.exceptions import ClickException + +from blueapi import __version__, config +from blueapi.config import ApplicationConfig, ConfigLoader +from blueapi.log import set_up_logging +from blueapi.service.cli import SERVER_COMMANDS + + +@click.group( + invoke_without_command=True, context_settings={"auto_envvar_prefix": "BLUEAPI"} +) +@click.version_option(version=__version__, prog_name="blueapi") +@click.option( + "-h", + "--host", + type=str, + help=textwrap.dedent( + """ + Hostname for the blueapi instance to use + + Value should be the full URL including scheme (and port if non-default), + eg `--host http://localhost:8000` + """ + ), +) +@click.option( + "-c", "--config", type=Path, help="Path to configuration YAML file", multiple=True +) +@click.option( + "-v", + "--verbose", + "log_level", + flag_value="DEBUG", + help="Include DEBUG level logging output", +) +@click.option( + "-q", + "--quiet", + "log_level", + flag_value="ERROR", + help="Reduce logging noise to only show errors", +) +@click.pass_context +def main( + ctx: click.Context, + config: tuple[Path, ...], + host: str | None = None, + log_level: str | None = None, +) -> None: + # if no command is supplied, run with the options passed + + # Set umask to DLS standard + os.umask(stat.S_IWOTH) + + config_loader = ConfigLoader(ApplicationConfig) + try: + config_loader.use_values_from_yaml(*config) + except FileNotFoundError as fnfe: + raise ClickException(f"Config file not found: {fnfe.filename}") from fnfe + if host: + config_loader.use_values({"api": {"url": host}}) + if log_level: + config_loader.use_values({"logging": {"level": log_level}}) + + loaded_config: ApplicationConfig = config_loader.load() + + set_up_logging(loaded_config.logging) + + ctx.ensure_object(dict) + ctx.obj["config"] = loaded_config + + if ctx.invoked_subcommand is None: + print("Please invoke subcommand!") + + +@click.option( + "-o", "--output", type=Path, help="Path to file to save the config schema" +) +@click.option( + "-u", + "--update", + type=bool, + is_flag=True, + help="[Development only] update the config schema in the documentation", +) +@main.command(name="config-schema") +def config_schema(output: Path | None = None, update: bool = False) -> None: + from blueapi.config import generate_config_schema + + schema = generate_config_schema() + if update: + output = config.CONFIG_SCHEMA_LOCATION + if output is not None: + with output.open("w") as stream: + json.dump(schema, stream, indent=4) + stream.write("\n") + else: + print(json.dumps(schema)) + + +def _needs_client_extra(name: str, missing: str | None) -> click.Command: + @click.command(name, context_settings={"ignore_unknown_options": True}) + @click.argument("args", nargs=-1, type=click.UNPROCESSED) + def command(args: tuple[str, ...]) -> None: + raise ClickException( + f"{missing} is not installed, it is needed to run the client. " + "Install it with: pip install blueapi[client]" + ) + + return command + + +try: + from blueapi.cli.cli import CLIENT_COMMANDS +except ModuleNotFoundError as e: + CLIENT_COMMANDS = [ + _needs_client_extra(name, e.name) for name in ("controller", "login", "logout") + ] + +for command in [*CLIENT_COMMANDS, *SERVER_COMMANDS]: + main.add_command(command) # test with: python -m blueapi if __name__ == "__main__": diff --git a/src/blueapi/cli/__init__.py b/src/blueapi/cli/__init__.py index ed32c05eb7..e69de29bb2 100644 --- a/src/blueapi/cli/__init__.py +++ b/src/blueapi/cli/__init__.py @@ -1,3 +0,0 @@ -from .cli import main - -__all__ = ["main"] diff --git a/src/blueapi/cli/__main__.py b/src/blueapi/cli/__main__.py deleted file mode 100644 index bcc566b7a0..0000000000 --- a/src/blueapi/cli/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from blueapi.cli.cli import main - -if __name__ == "__main__": - main() diff --git a/src/blueapi/cli/cli.py b/src/blueapi/cli/cli.py index d78a88d012..870d7f3448 100644 --- a/src/blueapi/cli/cli.py +++ b/src/blueapi/cli/cli.py @@ -1,12 +1,9 @@ import json import logging -import os -import stat import sys import textwrap from collections.abc import Callable from functools import wraps -from pathlib import Path from pprint import pprint from typing import Any, ParamSpec, TypeGuard, TypeVar, cast @@ -19,7 +16,7 @@ from click.types import ParamType from observability_utils.tracing import setup_tracing -from blueapi import __version__, config +from blueapi import config from blueapi.cli.format import OutputFormat from blueapi.client import BlueapiClient from blueapi.client.event_bus import AnyEvent, BlueskyStreamingError, EventBusClient @@ -33,16 +30,18 @@ ) from blueapi.client.session import SessionCacheManager, SessionManager from blueapi.config import ( + OTLP_EXPORT_ENABLED, ApplicationConfig, - ConfigLoader, ) -from blueapi.core import OTLP_EXPORT_ENABLED, DataEvent -from blueapi.log import set_up_logging +from blueapi.model.event import ( + DataEvent, + ProgressEvent, + TaskError, + TaskResult, + WorkerEvent, +) from blueapi.service.model import DeviceResponse, PlanResponse, SourceInfo, TaskRequest -from blueapi.worker import ProgressEvent, WorkerEvent -from blueapi.worker.event import TaskError, TaskResult -from .scratch import setup_scratch from .updates import CliEventRenderer LOGGER = logging.getLogger(__name__) @@ -97,162 +96,7 @@ def is_str_dict(val: Any) -> TypeGuard[TaskParameters]: return isinstance(val, dict) and all(isinstance(k, str) for k in val) -@click.group( - invoke_without_command=True, context_settings={"auto_envvar_prefix": "BLUEAPI"} -) -@click.version_option(version=__version__, prog_name="blueapi") -@click.option( - "-h", - "--host", - type=str, - help=textwrap.dedent( - """ - Hostname for the blueapi instance to use - - Value should be the full URL including scheme (and port if non-default), - eg `--host http://localhost:8000` - """ - ), -) -@click.option( - "-c", "--config", type=Path, help="Path to configuration YAML file", multiple=True -) -@click.option( - "-v", - "--verbose", - "log_level", - flag_value="DEBUG", - help="Include DEBUG level logging output", -) -@click.option( - "-q", - "--quiet", - "log_level", - flag_value="ERROR", - help="Reduce logging noise to only show errors", -) -@click.pass_context -def main( - ctx: click.Context, - config: tuple[Path, ...], - host: str | None = None, - log_level: str | None = None, -) -> None: - # if no command is supplied, run with the options passed - - # Set umask to DLS standard - os.umask(stat.S_IWOTH) - - config_loader = ConfigLoader(ApplicationConfig) - try: - config_loader.use_values_from_yaml(*config) - except FileNotFoundError as fnfe: - raise ClickException(f"Config file not found: {fnfe.filename}") from fnfe - if host: - config_loader.use_values({"api": {"url": host}}) - if log_level: - config_loader.use_values({"logging": {"level": log_level}}) - - loaded_config: ApplicationConfig = config_loader.load() - - set_up_logging(loaded_config.logging) - - ctx.ensure_object(dict) - ctx.obj["config"] = loaded_config - - if ctx.invoked_subcommand is None: - print("Please invoke subcommand!") - - -def _missing_server_extra(e: ImportError) -> ClickException: - return ClickException( - f"{e.name} is not installed, it is needed to run the server. " - "Install it with: pip install blueapi[server]" - ) - - -@main.command(name="schema") -@click.option("-o", "--output", type=Path, help="Path to file to save the schema") -@click.option( - "-u", - "--update", - type=bool, - is_flag=True, - help="[Development only] update the schema in the documentation", -) -def schema(output: Path | None = None, update: bool = False) -> None: - """Only import the service functions when starting the service or generating - the schema, not the controller as a new FastAPI app will be started each time. - """ - try: - from blueapi.service.openapi import ( - DOCS_SCHEMA_LOCATION, - generate_schema, - print_schema_as_yaml, - write_schema_as_yaml, - ) - except ImportError as e: - raise _missing_server_extra(e) from e - - """Generate the schema for the REST API""" - schema = generate_schema() - - if update: - output = DOCS_SCHEMA_LOCATION - if output is not None: - write_schema_as_yaml(output, schema) - else: - print_schema_as_yaml(schema) - - -@click.option( - "-o", "--output", type=Path, help="Path to file to save the config schema" -) -@click.option( - "-u", - "--update", - type=bool, - is_flag=True, - help="[Development only] update the config schema in the documentation", -) -@main.command(name="config-schema") -def config_schema(output: Path | None = None, update: bool = False) -> None: - from blueapi.config import generate_config_schema - - schema = generate_config_schema() - if update: - output = config.CONFIG_SCHEMA_LOCATION - if output is not None: - with output.open("w") as stream: - json.dump(schema, stream, indent=4) - stream.write("\n") - else: - print(json.dumps(schema)) - - -@main.command(name="serve") -@click.pass_obj -def start_application(obj: dict): - """Run a worker that accepts plans to run""" - config: ApplicationConfig = obj["config"] - - """Only import the service functions when starting the service or generating - the schema, not the controller as a new FastAPI app will be started each time. - """ - try: - from blueapi.service.main import start - except ImportError as e: - raise _missing_server_extra(e) from e - - """ - Set up basic automated instrumentation for the FastAPI app, creating the - observability context. - """ - setup_tracing("BlueAPI", OTLP_EXPORT_ENABLED) - start(config) - - -@main.group() +@click.group() @click.option( "-o", "--output", @@ -573,16 +417,6 @@ def env( print(status) -@main.command(name="setup-scratch") -@click.pass_obj -def scratch(obj: dict) -> None: - config: ApplicationConfig = obj["config"] - if config.scratch is not None: - setup_scratch(config.scratch) - else: - raise KeyError("No scratch config supplied") - - @controller.command(name="get-python-env") @click.option("--name", type=str, help="Filter by the name of the installed package") @click.option("--source", type=SourceInfo, help="Filter by the source type") @@ -596,7 +430,7 @@ def get_python_env(obj: dict, name: str, source: SourceInfo) -> None: obj["fmt"].display(client.get_python_env(name=name, source=source)) -@main.command(name="login") +@click.command(name="login") @click.pass_obj @check_connection def login(obj: dict) -> None: @@ -623,7 +457,7 @@ def login(obj: dict) -> None: print(str(e)) -@main.command(name="logout") +@click.command(name="logout") @click.pass_obj def logout(obj: dict) -> None: """ @@ -642,3 +476,6 @@ def logout(obj: dict) -> None: ) from e except Exception as e: raise ClickException(f"Error logging out: {e}") from e + + +CLIENT_COMMANDS = [controller, login, logout] diff --git a/src/blueapi/cli/format.py b/src/blueapi/cli/format.py index 29ba01b732..6552772c07 100644 --- a/src/blueapi/cli/format.py +++ b/src/blueapi/cli/format.py @@ -10,7 +10,7 @@ from pydantic import BaseModel -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent, ProgressEvent, WorkerEvent from blueapi.service.model import ( DeviceModel, DeviceResponse, @@ -19,7 +19,6 @@ PythonEnvironmentResponse, SourceInfo, ) -from blueapi.worker.event import ProgressEvent, WorkerEvent FALLBACK = pprint NL = "\n" diff --git a/src/blueapi/cli/updates.py b/src/blueapi/cli/updates.py index c3d922c6bb..3826431805 100644 --- a/src/blueapi/cli/updates.py +++ b/src/blueapi/cli/updates.py @@ -3,7 +3,7 @@ from tqdm import tqdm -from blueapi.worker import ProgressEvent, StatusView, WorkerEvent +from blueapi.model.event import ProgressEvent, StatusView, WorkerEvent _BAR_FMT = "{desc}: |{bar}| {percentage:3.0f}% [{elapsed}/{remaining}]" diff --git a/src/blueapi/client/client.py b/src/blueapi/client/client.py index 2105ac64e3..56afcb66f2 100644 --- a/src/blueapi/client/client.py +++ b/src/blueapi/client/client.py @@ -20,7 +20,14 @@ MissingStompConfigurationError, RestConfig, ) -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import ( + DataEvent, + ProgressEvent, + TaskStatus, + WorkerEvent, + WorkerState, +) +from blueapi.model.task import TrackableTask from blueapi.service.model import ( DeviceModel, DeviceResponse, @@ -36,9 +43,6 @@ WorkerTask, ) from blueapi.utils import deprecated -from blueapi.worker import WorkerEvent, WorkerState -from blueapi.worker.event import ProgressEvent, TaskStatus -from blueapi.worker.task_worker import TrackableTask from .device_cache import DeviceCache from .event_bus import AnyEvent, EventBusClient, OnAnyEvent diff --git a/src/blueapi/client/event_bus.py b/src/blueapi/client/event_bus.py index cb807f24d1..a291a2d8b6 100644 --- a/src/blueapi/client/event_bus.py +++ b/src/blueapi/client/event_bus.py @@ -3,8 +3,7 @@ from bluesky_stomp.messaging import MessageContext, StompClient from bluesky_stomp.models import MessageTopic -from blueapi.core import DataEvent -from blueapi.worker import ProgressEvent, WorkerEvent +from blueapi.model.event import DataEvent, ProgressEvent, WorkerEvent class BlueskyStreamingError(Exception): diff --git a/src/blueapi/client/plan_cache.py b/src/blueapi/client/plan_cache.py index acf5b27ee8..17f074e5d5 100644 --- a/src/blueapi/client/plan_cache.py +++ b/src/blueapi/client/plan_cache.py @@ -2,8 +2,8 @@ from typing import Any from blueapi.client.rest import InvalidParametersError +from blueapi.model.event import TaskError, TaskResult, TaskStatus from blueapi.service.model import PlanModel, TaskRequest -from blueapi.worker.event import TaskError, TaskResult, TaskStatus from .protocols import ClientProtocol diff --git a/src/blueapi/client/protocols.py b/src/blueapi/client/protocols.py index dbb923af6c..aa5d895349 100644 --- a/src/blueapi/client/protocols.py +++ b/src/blueapi/client/protocols.py @@ -1,7 +1,7 @@ from typing import Protocol +from blueapi.model.event import TaskStatus from blueapi.service.model import DeviceModel, DeviceResponse, TaskRequest -from blueapi.worker.event import TaskStatus from .event_bus import OnAnyEvent diff --git a/src/blueapi/client/rest.py b/src/blueapi/client/rest.py index 7bd242a011..ae848a66be 100644 --- a/src/blueapi/client/rest.py +++ b/src/blueapi/client/rest.py @@ -19,7 +19,8 @@ from blueapi.client.protocols import ClientObjectRef from blueapi.client.session import JWTAuth, SessionManager from blueapi.config import RestConfig -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent, ProgressEvent, WorkerEvent, WorkerState +from blueapi.model.task import TrackableTask from blueapi.service.model import ( DeviceModel, DeviceResponse, @@ -43,8 +44,6 @@ Unauthorized, Update, ) -from blueapi.worker import TrackableTask, WorkerState -from blueapi.worker.event import ProgressEvent, WorkerEvent T = TypeVar("T") diff --git a/src/blueapi/config.py b/src/blueapi/config.py index f65dd65f0a..14a966591e 100644 --- a/src/blueapi/config.py +++ b/src/blueapi/config.py @@ -30,6 +30,8 @@ from blueapi.utils import BlueapiBaseModel, InvalidConfigError +OTLP_EXPORT_ENABLED = os.environ.get("OTLP_EXPORT_ENABLED") == "true" + LOGGER = logging.getLogger(__name__) LogLevel = Literal["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] diff --git a/src/blueapi/core/__init__.py b/src/blueapi/core/__init__.py index 192a72adf4..9b23b48553 100644 --- a/src/blueapi/core/__init__.py +++ b/src/blueapi/core/__init__.py @@ -1,4 +1,4 @@ -from os import environ +from blueapi.config import OTLP_EXPORT_ENABLED from .bluesky_event_loop import configure_bluesky_event_loop from .bluesky_types import ( @@ -17,9 +17,8 @@ from .event import EventPublisher, EventStream from .protocols import DeviceManager -OTLP_EXPORT_ENABLED = environ.get("OTLP_EXPORT_ENABLED") == "true" - __all__ = [ + "OTLP_EXPORT_ENABLED", "Plan", "PlanGenerator", "MsgGenerator", diff --git a/src/blueapi/core/bluesky_types.py b/src/blueapi/core/bluesky_types.py index 674c28e2a2..546360bfad 100644 --- a/src/blueapi/core/bluesky_types.py +++ b/src/blueapi/core/bluesky_types.py @@ -1,5 +1,5 @@ import inspect -from collections.abc import Callable, Generator, Mapping +from collections.abc import Callable, Generator from dataclasses import dataclass from typing import ( Any, @@ -28,7 +28,7 @@ from ophyd_async.core import Device as AsyncDevice from pydantic import BaseModel -from blueapi.utils import BlueapiBaseModel +from blueapi.model.event import DataEvent # noqa: F401 - re-exported PlanGenerator = Callable[..., MsgGenerator] @@ -94,17 +94,6 @@ class Plan: description: str | None = None -class DataEvent(BlueapiBaseModel): - """ - Event representing collection of some data. Conforms to the Bluesky event model: - https://github.com/bluesky/event-model - """ - - name: str - doc: Mapping[str, Any] - task_id: str - - @runtime_checkable class WatchableStatus(Status, Protocol): """ diff --git a/src/blueapi/model/__init__.py b/src/blueapi/model/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/blueapi/model/event.py b/src/blueapi/model/event.py new file mode 100644 index 0000000000..f3646b9e30 --- /dev/null +++ b/src/blueapi/model/event.py @@ -0,0 +1,185 @@ +from collections.abc import Mapping +from enum import StrEnum +from typing import Any, Literal, Self + +from pydantic import Field, PydanticSchemaGenerationError, TypeAdapter +from pydantic_core import PydanticSerializationError + +from blueapi.utils import BlueapiBaseModel + + +# NOTE this is interim until refactor +class TaskStatusEnum(StrEnum): + PENDING = "PENDING" + COMPLETE = "COMPLETE" + ERROR = "ERROR" + RUNNING = "RUNNING" + + +class WorkerState(StrEnum): + """ + The state of the Worker. + """ + + IDLE = "IDLE" + RUNNING = "RUNNING" + PAUSING = "PAUSING" + PAUSED = "PAUSED" + HALTING = "HALTING" + STOPPING = "STOPPING" + ABORTING = "ABORTING" + SUSPENDING = "SUSPENDING" + PANICKED = "PANICKED" + UNKNOWN = "UNKNOWN" + + @classmethod + def from_bluesky_state(cls, bluesky_state: Any) -> "WorkerState": + """Convert the state of a bluesky RunEngine + + Args: + bluesky_state: Bluesky RunEngine state + + Returns: + RunnerState: Mapped RunEngine state + """ + + # RunEngineStateMachine.States is an enum, the other forms are strings + return WorkerState(str(getattr(bluesky_state, "value", bluesky_state)).upper()) + + +class DataEvent(BlueapiBaseModel): + """ + Event representing collection of some data. Conforms to the Bluesky event model: + https://github.com/bluesky/event-model + """ + + name: str + doc: Mapping[str, Any] + task_id: str + + +class TaskResult(BlueapiBaseModel): + """ + Serializable wrapper around the result of a plan + + If the result is not serializable, the result will be None but the type + will be the name of the type. If the result is actually None, the type will + be 'NoneType'. + """ + + outcome: Literal["success"] = "success" + """Discriminant for serialization""" + result: Any = Field(None) + """The serialized result (or None if it is not serializable)""" + type: str + """The type of the result""" + + @classmethod + def from_result(cls, result: Any) -> Self: + type_str = type(result).__name__ + try: + value = TypeAdapter(type(result)).dump_python(result, mode="json") + except (PydanticSchemaGenerationError, PydanticSerializationError): + value = None + return cls(result=value, type=type_str) + + +class TaskError(BlueapiBaseModel): + """Wrapper around an exception raised by a plan""" + + outcome: Literal["error"] = "error" + """Discriminant for serialization""" + type: str + """The class of exception""" + message: str + """The message of the raised exception""" + + @classmethod + def from_exception(cls, err: Exception) -> Self: + return cls(type=type(err).__name__, message=str(err)) + + +class StatusView(BlueapiBaseModel): + """ + A snapshot of a Status of an operation, optionally representing progress + """ + + display_name: str = Field( + description="Human-readable name indicating what this status describes", + default="Unknown", + ) + current: float | None = Field( + description="Current value of operation progress, if known", default=None + ) + initial: float | None = Field( + description="Initial value of operation progress, if known", default=None + ) + target: float | None = Field( + description="Target value operation of progress, if known", default=None + ) + unit: str = Field(description="Units of progress", default="units") + precision: int | None = Field( + description="Sensible precision of progress to display", default=None + ) + done: bool = Field( + description="Whether the operation this status describes is complete", + default=False, + ) + percentage: float | None = Field( + description="Percentage of status completion, if known", default=None + ) + time_elapsed: float | None = Field( + description="Time elapsed since status operation beginning, if known", + default=None, + ) + time_remaining: float | None = Field( + description="Estimated time remaining until operation completion, if known", + default=None, + ) + + +class ProgressEvent(BlueapiBaseModel): + """ + Event describing the progress of processes within a running task, + such as moving motors and exposing detectors. + """ + + task_id: str + statuses: Mapping[str, StatusView] = Field(default_factory=dict) + + +class TaskStatus(BlueapiBaseModel): + """ + Status of a task the worker is running. + """ + + task_id: str + result: TaskResult | TaskError | None = Field(None, discriminator="outcome") + task_complete: bool + task_failed: bool + + +class WorkerEvent(BlueapiBaseModel): + """ + Event describing the state of the worker and any tasks it's running. + Includes error and warning information. + """ + + state: WorkerState + task_status: TaskStatus | None = None + errors: list[str] = Field(default_factory=list) + warnings: list[str] = Field(default_factory=list) + + def is_error(self) -> bool: + return (self.task_status is not None and self.task_status.task_failed) or bool( + self.errors + ) + + def is_complete(self) -> bool: + return self.task_status is not None and self.task_status.task_complete + + @property + def task_id(self) -> str | None: + if task := self.task_status: + return task.task_id + return None diff --git a/src/blueapi/model/task.py b/src/blueapi/model/task.py new file mode 100644 index 0000000000..07e2498112 --- /dev/null +++ b/src/blueapi/model/task.py @@ -0,0 +1,181 @@ +import logging +from collections.abc import Mapping +from inspect import Parameter, signature +from typing import TYPE_CHECKING, Any, Self, TypedDict + +from pydantic import Field, ValidationError +from pydantic.json_schema import SkipJsonSchema + +from blueapi.utils import BlueapiBaseModel + +from .event import TaskError, TaskResult + +if TYPE_CHECKING: + from blueapi.core.context import BlueskyContext + +LOGGER = logging.getLogger(__name__) + + +class Task(BlueapiBaseModel): + """ + Task that will run a plan + """ + + name: str = Field(description="Name of plan to run") + args: list[Any] = Field( + description="Positional arguments to plan", + default_factory=list, + exclude_if=lambda args: not args, + ) + params: Mapping[str, Any] = Field( + description="Keyword arguments to plan, if any", + default_factory=dict, + ) + metadata: dict[str, Any] = Field( + description="Any metadata to apply to all runs within this task", + default_factory=dict, + ) + + def prepare_params( + self, ctx: "BlueskyContext" + ) -> tuple[list[Any], Mapping[str, Any]]: + """ + Checks the configured plan parameters against context + + Args: + ctx: Context holding plans and devices + + Returns: + tuple[list[Any], Mapping[str, Any]]: The prepared *args and **kwargs + parameters for the plan. + """ + try: + return self._inner_prepare_params(ctx) + except ValidationError as ve: + raise TaskParameterError.from_validation_error(ve) from None + except TypeError as te: + raise TaskParameterError( + "Invalid arguments to plan", + [ + InvalidTaskParameter( + loc=(), msg=str(te), type="TypeError", input=None + ) + ], + ) from None + + def _inner_prepare_params( + self, ctx: "BlueskyContext" + ) -> tuple[list[Any], Mapping[str, Any]]: + """Prepare positional and keyword arguments for a plan invocation. + + Bind the task's supplied arguments to the plan's signature, then validate + them using the plan's Pydantic model. This also resolves injected device + names to the corresponding devices in the context and applies parameter + defaults defined by the model. + + Construct the positional and keyword arguments according to the plan's + parameter kinds, ensuring that positional-only, variadic, and + keyword-only parameters are handled correctly. + + Args: + ctx: The context containing the registered plan and its associated + parameter model. + + Returns: + A tuple containing the prepared positional and keyword arguments + to pass to the plan. + """ + plan = ctx.plans[self.name] + + sig = signature(plan.plan_function) + bound = sig.bind_partial(*self.args, **self.params) + + validated = plan.model.model_validate(bound.arguments) + + args: list[Any] = [] + kwargs: dict[str, Any] = {} + + for name, parameter in sig.parameters.items(): + value = getattr(validated, name) + + match parameter.kind: + case Parameter.POSITIONAL_ONLY: + args.append(value) + case Parameter.VAR_POSITIONAL: + args.extend(value) + case Parameter.VAR_KEYWORD: + kwargs.update(value) + case Parameter.POSITIONAL_OR_KEYWORD: + if name in bound.arguments and name not in self.params: + args.append(value) + else: + kwargs[name] = value + case Parameter.KEYWORD_ONLY: + kwargs[name] = value + + return args, kwargs + + def do_task(self, ctx: "BlueskyContext") -> None: + LOGGER.info( + f"Asked to run plan {self.name} with {self.params} and " + f"metadata {self.metadata} for all runs" + ) + plan = ctx.plans[self.name].plan_function + prepared_args, prepared_kwargs = self.prepare_params(ctx) + ctx.run_engine.md.update(self.metadata) + result = ctx.run_engine(plan(*prepared_args, **prepared_kwargs)) + if isinstance(result, tuple): # pragma: no cover + # this is never true if the run_engine is configured correctly + return None + return result.plan_result + + +class TrackableTask(BlueapiBaseModel): + """ + A representation of a task that the worker recognizes + """ + + task_id: str + task: Task + request_id: str | SkipJsonSchema[None] = None + is_complete: bool = False + is_pending: bool = True + errors: list[str] = Field(default_factory=list) + outcome: TaskResult | TaskError | None = None + + def set_result(self, result: Any): + self.outcome = TaskResult.from_result(result) + + def set_exception(self, err: Exception): + self.outcome = TaskError.from_exception(err) + + +class InvalidTaskParameter(TypedDict): + loc: tuple[str | int, ...] + msg: str | None + type: str | None + input: Any | None + + +class TaskParameterError(ValueError): + errors: list[InvalidTaskParameter] + + def __init__(self, message: str, errors: list[InvalidTaskParameter]): + super().__init__(message) + self.errors = errors + + @classmethod + def from_validation_error(cls, error: ValidationError) -> Self: + errors = [ + InvalidTaskParameter( + loc=e.get("loc", []), + msg=e.get("msg", None), + type=e.get("type", None), + input=e.get("input", None), + ) + for e in error.errors() + ] + return cls(str(error), errors) + + def __reduce__(self): + return (self.__class__, (*self.args, self.errors)) diff --git a/src/blueapi/service/cli.py b/src/blueapi/service/cli.py new file mode 100644 index 0000000000..4abea25085 --- /dev/null +++ b/src/blueapi/service/cli.py @@ -0,0 +1,81 @@ +"""Server commands of the blueapi CLI, they need the server extra to run""" + +from pathlib import Path + +import click +from click.exceptions import ClickException +from observability_utils.tracing import setup_tracing + +from blueapi.config import OTLP_EXPORT_ENABLED, ApplicationConfig + + +class _ServerCommand(click.Command): + def invoke(self, ctx: click.Context): + try: + return super().invoke(ctx) + except ModuleNotFoundError as e: + raise ClickException( + f"{e.name} is not installed, it is needed to run the server. " + "Install it with: pip install blueapi[server]" + ) from e + + +@click.command(name="schema", cls=_ServerCommand) +@click.option("-o", "--output", type=Path, help="Path to file to save the schema") +@click.option( + "-u", + "--update", + type=bool, + is_flag=True, + help="[Development only] update the schema in the documentation", +) +def schema(output: Path | None = None, update: bool = False) -> None: + """Generate the schema for the REST API""" + # Only import the service functions when starting the service or generating + # the schema, not the controller as a new FastAPI app will be started each time. + from blueapi.service.openapi import ( + DOCS_SCHEMA_LOCATION, + generate_schema, + print_schema_as_yaml, + write_schema_as_yaml, + ) + + schema = generate_schema() + + if update: + output = DOCS_SCHEMA_LOCATION + if output is not None: + write_schema_as_yaml(output, schema) + else: + print_schema_as_yaml(schema) + + +@click.command(name="serve", cls=_ServerCommand) +@click.pass_obj +def start_application(obj: dict): + """Run a worker that accepts plans to run""" + config: ApplicationConfig = obj["config"] + + # Only import the service functions when starting the service or generating + # the schema, not the controller as a new FastAPI app will be started each time. + from blueapi.service.main import start + + # Set up basic automated instrumentation for the FastAPI app, creating the + # observability context. + setup_tracing("BlueAPI", OTLP_EXPORT_ENABLED) + start(config) + + +@click.command(name="setup-scratch", cls=_ServerCommand) +@click.pass_obj +def scratch(obj: dict) -> None: + from blueapi.service.scratch import setup_scratch + + config: ApplicationConfig = obj["config"] + if config.scratch is not None: + setup_scratch(config.scratch) + else: + raise KeyError("No scratch config supplied") + + +SERVER_COMMANDS = [schema, start_application, scratch] diff --git a/src/blueapi/service/interface.py b/src/blueapi/service/interface.py index 3c67a8dd4f..ca1d39889e 100644 --- a/src/blueapi/service/interface.py +++ b/src/blueapi/service/interface.py @@ -14,10 +14,17 @@ from tiled.client.utils import ClientError from blueapi.config import ApplicationConfig, OIDCConfig, ServiceAccount, StompConfig -from blueapi.core.bluesky_types import DataEvent from blueapi.core.context import BlueskyContext from blueapi.core.event import EventStream from blueapi.log import set_up_logging +from blueapi.model.event import ( + DataEvent, + ProgressEvent, + TaskStatusEnum, + WorkerEvent, + WorkerState, +) +from blueapi.model.task import Task from blueapi.service.authentication import TiledAuth from blueapi.service.environment import get_python_environment from blueapi.service.model import ( @@ -30,8 +37,6 @@ ) from blueapi.service.numtracker import NumtrackerClient from blueapi.utils.serialization import access_blob -from blueapi.worker.event import ProgressEvent, TaskStatusEnum, WorkerEvent, WorkerState -from blueapi.worker.task import Task from blueapi.worker.task_worker import TaskWorker, TrackableTask """This module provides interface between web application and underlying Bluesky diff --git a/src/blueapi/service/main.py b/src/blueapi/service/main.py index bbdadfa97f..ae86cb4742 100644 --- a/src/blueapi/service/main.py +++ b/src/blueapi/service/main.py @@ -35,7 +35,8 @@ from starlette.status import WS_1007_INVALID_FRAME_PAYLOAD_DATA, WS_1013_TRY_AGAIN_LATER from blueapi.config import ApplicationConfig, OIDCConfig, Tag -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent, ProgressEvent, TaskStatusEnum, WorkerEvent +from blueapi.model.task import TaskParameterError from blueapi.service import interface, protocol from blueapi.service.authentication import ( Fedid, @@ -56,8 +57,6 @@ Update, ) from blueapi.worker import TrackableTask, WorkerState -from blueapi.worker.event import ProgressEvent, TaskStatusEnum, WorkerEvent -from blueapi.worker.task import TaskParameterError from blueapi.worker.worker_errors import WorkerBusyError from .authorization import ( diff --git a/src/blueapi/service/model.py b/src/blueapi/service/model.py index 1b690d5c04..c219d72943 100644 --- a/src/blueapi/service/model.py +++ b/src/blueapi/service/model.py @@ -1,20 +1,19 @@ import uuid -from collections.abc import Iterable, Mapping +from collections.abc import Mapping from enum import StrEnum -from typing import Annotated, Any +from typing import TYPE_CHECKING, Annotated, Any -from bluesky.protocols import HasName from pydantic import Field from pydantic.json_schema import SkipJsonSchema from blueapi.config import OIDCConfig -from blueapi.core import BLUESKY_PROTOCOLS, Device, Plan -from blueapi.core.context import generic_bounds +from blueapi.model.event import WorkerState +from blueapi.model.task import TrackableTask from blueapi.utils import BlueapiBaseModel -from blueapi.worker import WorkerState -from blueapi.worker.task_worker import TaskWorker, TrackableTask -_UNKNOWN_NAME = "UNKNOWN" +if TYPE_CHECKING: + from blueapi.core.bluesky_types import Device, Plan + from blueapi.worker.task_worker import TaskWorker class ProtocolInfo(BlueapiBaseModel): @@ -36,18 +35,24 @@ class DeviceModel(BlueapiBaseModel): ) @classmethod - def from_device(cls, device: Device) -> "DeviceModel": - name = device.name if isinstance(device, HasName) else _UNKNOWN_NAME - return cls(name=name, protocols=list(_protocol_info(device))) + def from_device(cls, device: "Device") -> "DeviceModel": + # Server only: imported here as the client has no ophyd-async + from bluesky.protocols import HasName + from blueapi.core.bluesky_types import BLUESKY_PROTOCOLS + from blueapi.core.context import generic_bounds -def _protocol_info(device: Device) -> Iterable[ProtocolInfo]: - for protocol in BLUESKY_PROTOCOLS: - if isinstance(device, protocol): - yield ProtocolInfo( - name=protocol.__name__, - types=[arg.__name__ for arg in generic_bounds(device, protocol)], - ) + return cls( + name=device.name if isinstance(device, HasName) else "UNKNOWN", + protocols=[ + ProtocolInfo( + name=protocol.__name__, + types=[arg.__name__ for arg in generic_bounds(device, protocol)], + ) + for protocol in BLUESKY_PROTOCOLS + if isinstance(device, protocol) + ], + ) class TasksListResponse(BlueapiBaseModel): @@ -109,7 +114,7 @@ class PlanModel(BlueapiBaseModel): ) @classmethod - def from_plan(cls, plan: Plan) -> "PlanModel": + def from_plan(cls, plan: "Plan") -> "PlanModel": return cls( name=plan.name, schema=plan.model.model_json_schema(), @@ -151,7 +156,7 @@ class WorkerTask(BlueapiBaseModel): ) @classmethod - def of_worker(cls, worker: TaskWorker) -> "WorkerTask": + def of_worker(cls, worker: "TaskWorker") -> "WorkerTask": active = worker.get_active_task() if active is not None: return WorkerTask(task_id=active.task_id) diff --git a/src/blueapi/service/protocol.py b/src/blueapi/service/protocol.py index e1b923c72d..79dff58e08 100644 --- a/src/blueapi/service/protocol.py +++ b/src/blueapi/service/protocol.py @@ -19,10 +19,9 @@ from pydantic import BaseModel, Field, TypeAdapter -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent, ProgressEvent, WorkerEvent +from blueapi.model.task import TaskParameterError from blueapi.service.model import TaskRequest -from blueapi.worker.event import ProgressEvent, WorkerEvent -from blueapi.worker.task import TaskParameterError UNKNOWN_PLAN = 4001 INVALID_ARGS = 4002 diff --git a/src/blueapi/service/runner.py b/src/blueapi/service/runner.py index 9aa4bfb0c5..b93f8eda72 100644 --- a/src/blueapi/service/runner.py +++ b/src/blueapi/service/runner.py @@ -20,11 +20,10 @@ from pydantic import TypeAdapter from blueapi.config import ApplicationConfig -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent, ProgressEvent, WorkerEvent from blueapi.service import interface from blueapi.service.interface import SubHandles, setup, teardown from blueapi.service.model import EnvironmentResponse -from blueapi.worker.event import ProgressEvent, WorkerEvent # The default multiprocessing start method is fork set_start_method("spawn", force=True) diff --git a/src/blueapi/cli/scratch.py b/src/blueapi/service/scratch.py similarity index 100% rename from src/blueapi/cli/scratch.py rename to src/blueapi/service/scratch.py diff --git a/src/blueapi/worker/event.py b/src/blueapi/worker/event.py index 25aae20f96..ef336aeaa0 100644 --- a/src/blueapi/worker/event.py +++ b/src/blueapi/worker/event.py @@ -1,181 +1,2 @@ -from collections.abc import Mapping -from enum import StrEnum -from typing import Any, Literal, Self - -from bluesky._vendor.super_state_machine.extras import PropertyMachine, ProxyString -from bluesky.run_engine import RunEngineStateMachine -from pydantic import Field, PydanticSchemaGenerationError, TypeAdapter -from pydantic_core import PydanticSerializationError - -from blueapi.utils import BlueapiBaseModel - -# The RunEngine can return any of these three types as its state -# RawRunEngineState = type[PropertyMachine | ProxyString | str] -RawRunEngineState = PropertyMachine | ProxyString | str - - -# NOTE this is interim until refactor -class TaskStatusEnum(StrEnum): - PENDING = "PENDING" - COMPLETE = "COMPLETE" - ERROR = "ERROR" - RUNNING = "RUNNING" - - -class WorkerState(StrEnum): - """ - The state of the Worker. - """ - - IDLE = "IDLE" - RUNNING = "RUNNING" - PAUSING = "PAUSING" - PAUSED = "PAUSED" - HALTING = "HALTING" - STOPPING = "STOPPING" - ABORTING = "ABORTING" - SUSPENDING = "SUSPENDING" - PANICKED = "PANICKED" - UNKNOWN = "UNKNOWN" - - @classmethod - def from_bluesky_state(cls, bluesky_state: RawRunEngineState) -> "WorkerState": - """Convert the state of a bluesky RunEngine - - Args: - bluesky_state: Bluesky RunEngine state - - Returns: - RunnerState: Mapped RunEngine state - """ - - if isinstance(bluesky_state, RunEngineStateMachine.States): - return cls.from_bluesky_state(bluesky_state.value) - return WorkerState(str(bluesky_state).upper()) - - -class TaskResult(BlueapiBaseModel): - """ - Serializable wrapper around the result of a plan - - If the result is not serializable, the result will be None but the type - will be the name of the type. If the result is actually None, the type will - be 'NoneType'. - """ - - outcome: Literal["success"] = "success" - """Discriminant for serialization""" - result: Any = Field(None) - """The serialized result (or None if it is not serializable)""" - type: str - """The type of the result""" - - @classmethod - def from_result(cls, result: Any) -> Self: - type_str = type(result).__name__ - try: - value = TypeAdapter(type(result)).dump_python(result, mode="json") - except (PydanticSchemaGenerationError, PydanticSerializationError): - value = None - return cls(result=value, type=type_str) - - -class TaskError(BlueapiBaseModel): - """Wrapper around an exception raised by a plan""" - - outcome: Literal["error"] = "error" - """Discriminant for serialization""" - type: str - """The class of exception""" - message: str - """The message of the raised exception""" - - @classmethod - def from_exception(cls, err: Exception) -> Self: - return cls(type=type(err).__name__, message=str(err)) - - -class StatusView(BlueapiBaseModel): - """ - A snapshot of a Status of an operation, optionally representing progress - """ - - display_name: str = Field( - description="Human-readable name indicating what this status describes", - default="Unknown", - ) - current: float | None = Field( - description="Current value of operation progress, if known", default=None - ) - initial: float | None = Field( - description="Initial value of operation progress, if known", default=None - ) - target: float | None = Field( - description="Target value operation of progress, if known", default=None - ) - unit: str = Field(description="Units of progress", default="units") - precision: int | None = Field( - description="Sensible precision of progress to display", default=None - ) - done: bool = Field( - description="Whether the operation this status describes is complete", - default=False, - ) - percentage: float | None = Field( - description="Percentage of status completion, if known", default=None - ) - time_elapsed: float | None = Field( - description="Time elapsed since status operation beginning, if known", - default=None, - ) - time_remaining: float | None = Field( - description="Estimated time remaining until operation completion, if known", - default=None, - ) - - -class ProgressEvent(BlueapiBaseModel): - """ - Event describing the progress of processes within a running task, - such as moving motors and exposing detectors. - """ - - task_id: str - statuses: Mapping[str, StatusView] = Field(default_factory=dict) - - -class TaskStatus(BlueapiBaseModel): - """ - Status of a task the worker is running. - """ - - task_id: str - result: TaskResult | TaskError | None = Field(None, discriminator="outcome") - task_complete: bool - task_failed: bool - - -class WorkerEvent(BlueapiBaseModel): - """ - Event describing the state of the worker and any tasks it's running. - Includes error and warning information. - """ - - state: WorkerState - task_status: TaskStatus | None = None - errors: list[str] = Field(default_factory=list) - warnings: list[str] = Field(default_factory=list) - - def is_error(self) -> bool: - return (self.task_status is not None and self.task_status.task_failed) or bool( - self.errors - ) - - def is_complete(self) -> bool: - return self.task_status is not None and self.task_status.task_complete - - @property - def task_id(self) -> str | None: - if task := self.task_status: - return task.task_id - return None +# Kept for backwards compatibility, these now live in blueapi.model.event +from blueapi.model.event import * # noqa: F403 diff --git a/src/blueapi/worker/task.py b/src/blueapi/worker/task.py index 3f034e65eb..f92b3ab63d 100644 --- a/src/blueapi/worker/task.py +++ b/src/blueapi/worker/task.py @@ -1,156 +1,2 @@ -import logging -from collections.abc import Mapping -from inspect import Parameter, signature -from typing import Any, Self, TypedDict - -from pydantic import Field, ValidationError - -from blueapi.core import BlueskyContext -from blueapi.utils import BlueapiBaseModel - -LOGGER = logging.getLogger(__name__) - - -class Task(BlueapiBaseModel): - """ - Task that will run a plan - """ - - name: str = Field(description="Name of plan to run") - args: list[Any] = Field( - description="Positional arguments to plan", - default_factory=list, - exclude_if=lambda args: not args, - ) - params: Mapping[str, Any] = Field( - description="Keyword arguments to plan, if any", - default_factory=dict, - ) - metadata: dict[str, Any] = Field( - description="Any metadata to apply to all runs within this task", - default_factory=dict, - ) - - def prepare_params( - self, ctx: BlueskyContext - ) -> tuple[list[Any], Mapping[str, Any]]: - """ - Checks the configured plan parameters against context - - Args: - ctx: Context holding plans and devices - - Returns: - tuple[list[Any], Mapping[str, Any]]: The prepared *args and **kwargs - parameters for the plan. - """ - try: - return self._inner_prepare_params(ctx) - except ValidationError as ve: - raise TaskParameterError.from_validation_error(ve) from None - except TypeError as te: - raise TaskParameterError( - "Invalid arguments to plan", - [ - InvalidTaskParameter( - loc=(), msg=str(te), type="TypeError", input=None - ) - ], - ) from None - - def _inner_prepare_params( - self, ctx: BlueskyContext - ) -> tuple[list[Any], Mapping[str, Any]]: - """Prepare positional and keyword arguments for a plan invocation. - - Bind the task's supplied arguments to the plan's signature, then validate - them using the plan's Pydantic model. This also resolves injected device - names to the corresponding devices in the context and applies parameter - defaults defined by the model. - - Construct the positional and keyword arguments according to the plan's - parameter kinds, ensuring that positional-only, variadic, and - keyword-only parameters are handled correctly. - - Args: - ctx: The context containing the registered plan and its associated - parameter model. - - Returns: - A tuple containing the prepared positional and keyword arguments - to pass to the plan. - """ - plan = ctx.plans[self.name] - - sig = signature(plan.plan_function) - bound = sig.bind_partial(*self.args, **self.params) - - validated = plan.model.model_validate(bound.arguments) - - args: list[Any] = [] - kwargs: dict[str, Any] = {} - - for name, parameter in sig.parameters.items(): - value = getattr(validated, name) - - match parameter.kind: - case Parameter.POSITIONAL_ONLY: - args.append(value) - case Parameter.VAR_POSITIONAL: - args.extend(value) - case Parameter.VAR_KEYWORD: - kwargs.update(value) - case Parameter.POSITIONAL_OR_KEYWORD: - if name in bound.arguments and name not in self.params: - args.append(value) - else: - kwargs[name] = value - case Parameter.KEYWORD_ONLY: - kwargs[name] = value - - return args, kwargs - - def do_task(self, ctx: BlueskyContext) -> None: - LOGGER.info( - f"Asked to run plan {self.name} with {self.params} and " - f"metadata {self.metadata} for all runs" - ) - plan = ctx.plans[self.name].plan_function - prepared_args, prepared_kwargs = self.prepare_params(ctx) - ctx.run_engine.md.update(self.metadata) - result = ctx.run_engine(plan(*prepared_args, **prepared_kwargs)) - if isinstance(result, tuple): # pragma: no cover - # this is never true if the run_engine is configured correctly - return None - return result.plan_result - - -class InvalidTaskParameter(TypedDict): - loc: tuple[str | int, ...] - msg: str | None - type: str | None - input: Any | None - - -class TaskParameterError(ValueError): - errors: list[InvalidTaskParameter] - - def __init__(self, message: str, errors: list[InvalidTaskParameter]): - super().__init__(message) - self.errors = errors - - @classmethod - def from_validation_error(cls, error: ValidationError) -> Self: - errors = [ - InvalidTaskParameter( - loc=e.get("loc", []), - msg=e.get("msg", None), - type=e.get("type", None), - input=e.get("input", None), - ) - for e in error.errors() - ] - return cls(str(error), errors) - - def __reduce__(self): - return (self.__class__, (*self.args, self.errors)) +# Kept for backwards compatibility, these now live in blueapi.model.task +from blueapi.model.task import * # noqa: F403 diff --git a/src/blueapi/worker/task_worker.py b/src/blueapi/worker/task_worker.py index 219a1c1caa..d590f526b1 100644 --- a/src/blueapi/worker/task_worker.py +++ b/src/blueapi/worker/task_worker.py @@ -9,6 +9,7 @@ from typing import Any, TypeVar from bluesky._vendor.super_state_machine.errors import TransitionError +from bluesky._vendor.super_state_machine.extras import PropertyMachine, ProxyString from bluesky.protocols import Status from observability_utils.tracing import ( add_span_attributes, @@ -19,8 +20,6 @@ from opentelemetry.baggage import get_baggage from opentelemetry.context import Context, get_current from opentelemetry.trace import SpanKind -from pydantic import Field -from pydantic.json_schema import SkipJsonSchema from blueapi.core import ( OTLP_EXPORT_ENABLED, @@ -32,21 +31,17 @@ ) from blueapi.core.bluesky_event_loop import configure_bluesky_event_loop from blueapi.log import plan_tag_filter_context -from blueapi.utils.base_model import BlueapiBaseModel -from blueapi.utils.thread_exception import handle_all_exceptions - -from .event import ( +from blueapi.model.event import ( ProgressEvent, - RawRunEngineState, StatusView, - TaskError, - TaskResult, TaskStatus, TaskStatusEnum, WorkerEvent, WorkerState, ) -from .task import Task +from blueapi.model.task import Task, TrackableTask +from blueapi.utils.thread_exception import handle_all_exceptions + from .worker_errors import WorkerAlreadyStartedError, WorkerBusyError LOGGER = logging.getLogger(__name__) @@ -59,25 +54,8 @@ T = TypeVar("T") - -class TrackableTask(BlueapiBaseModel): - """ - A representation of a task that the worker recognizes - """ - - task_id: str - task: Task - request_id: str | SkipJsonSchema[None] = None - is_complete: bool = False - is_pending: bool = True - errors: list[str] = Field(default_factory=list) - outcome: TaskResult | TaskError | None = None - - def set_result(self, result: Any): - self.outcome = TaskResult.from_result(result) - - def set_exception(self, err: Exception): - self.outcome = TaskError.from_exception(err) +# The RunEngine can return any of these three types as its state +RawRunEngineState = PropertyMachine | ProxyString | str class TaskWorker: diff --git a/tests/system_tests/test_blueapi_client.py b/tests/system_tests/test_blueapi_client.py index 32bbe484ac..914b4a71b2 100644 --- a/tests/system_tests/test_blueapi_client.py +++ b/tests/system_tests/test_blueapi_client.py @@ -20,9 +20,8 @@ from blueapi.client.plan_cache import Plan from blueapi.client.rest import ServiceUnavailableError, UnauthorisedAccessError from blueapi.config import ApplicationConfig -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent, WorkerEvent, WorkerState from blueapi.service.model import TaskRequest -from blueapi.worker.event import WorkerEvent, WorkerState # Tests for the BlueapiClient as a user would drive it: built from a config # file, logged in through the OIDC device flow, plans run as methods. diff --git a/tests/system_tests/test_blueapi_system.py b/tests/system_tests/test_blueapi_system.py index f393c7ab8c..d3332edc05 100644 --- a/tests/system_tests/test_blueapi_system.py +++ b/tests/system_tests/test_blueapi_system.py @@ -30,7 +30,14 @@ ConfigLoader, OIDCConfig, ) -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import ( + DataEvent, + TaskResult, + TaskStatus, + WorkerEvent, + WorkerState, +) +from blueapi.model.task import TrackableTask from blueapi.service.model import ( DeviceResponse, PlanResponse, @@ -39,13 +46,6 @@ WorkerTask, ) from blueapi.utils import INSTRUMENT_SESSION_RE -from blueapi.worker.event import ( - TaskResult, - TaskStatus, - WorkerEvent, - WorkerState, -) -from blueapi.worker.task_worker import TrackableTask class User(StrEnum): diff --git a/tests/unit_tests/cli/test_cli.py b/tests/unit_tests/cli/test_cli.py index f858e6ac0f..2820b48f70 100644 --- a/tests/unit_tests/cli/test_cli.py +++ b/tests/unit_tests/cli/test_cli.py @@ -24,7 +24,8 @@ from stomp.connect import StompConnection11 as Connection from blueapi import __version__ -from blueapi.cli.cli import ParametersType, PositionalArgType, main +from blueapi.__main__ import main +from blueapi.cli.cli import ParametersType, PositionalArgType from blueapi.cli.format import OutputFormat, fmt_dict from blueapi.client.event_bus import BlueskyStreamingError from blueapi.client.rest import ( @@ -40,7 +41,15 @@ ScratchRepository, generate_config_schema, ) -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import ( + DataEvent, + ProgressEvent, + TaskError, + TaskResult, + TaskStatus, + WorkerEvent, + WorkerState, +) from blueapi.service.model import ( DeviceModel, DeviceResponse, @@ -51,14 +60,6 @@ TaskRequest, TaskResponse, ) -from blueapi.worker.event import ( - ProgressEvent, - TaskError, - TaskResult, - TaskStatus, - WorkerEvent, - WorkerState, -) @pytest.fixture @@ -90,8 +91,8 @@ def test_main_no_params(): @patch("blueapi.service.main.start") -@patch("blueapi.cli.scratch.setup_scratch") -@patch("blueapi.cli.cli.os.umask") +@patch("blueapi.service.scratch.setup_scratch") +@patch("blueapi.__main__.os.umask") @pytest.mark.parametrize("subcommand", ["serve", "setup-scratch"]) def test_runs_with_umask_002( mock_umask: Mock, @@ -1055,7 +1056,7 @@ def test_generic_base_model_formatting(): ) -@patch("blueapi.cli.cli.setup_scratch") +@patch("blueapi.service.scratch.setup_scratch") def test_init_scratch_calls_setup_scratch(mock_setup_scratch: Mock, runner: CliRunner): expected_config = ScratchConfig( root=Path("/tmp"), @@ -1387,7 +1388,7 @@ def test_python_env_output_formatting(): @pytest.mark.parametrize("output_flag", [True, False]) @pytest.mark.parametrize("update", [True, False]) -@patch("blueapi.cli.cli.config.CONFIG_SCHEMA_LOCATION") +@patch("blueapi.__main__.config.CONFIG_SCHEMA_LOCATION") def test_config_schema( config_schema_location_mock: Mock, runner: CliRunner, diff --git a/tests/unit_tests/client/constants.py b/tests/unit_tests/client/constants.py index fad6057c6f..18d8b237c2 100644 --- a/tests/unit_tests/client/constants.py +++ b/tests/unit_tests/client/constants.py @@ -1,5 +1,6 @@ import uuid +from blueapi.model.event import TaskError, TaskResult, TaskStatus from blueapi.service.model import ( DeviceModel, DeviceResponse, @@ -10,7 +11,6 @@ WorkerTask, ) from blueapi.worker import Task, TrackableTask, WorkerEvent, WorkerState -from blueapi.worker.event import TaskError, TaskResult, TaskStatus PLANS = PlanResponse( plans=[ diff --git a/tests/unit_tests/client/test_client.py b/tests/unit_tests/client/test_client.py index e7e31f9302..501df63372 100644 --- a/tests/unit_tests/client/test_client.py +++ b/tests/unit_tests/client/test_client.py @@ -29,6 +29,7 @@ ) from blueapi.config import MissingStompConfigurationError, RestConfig from blueapi.core import DataEvent +from blueapi.model.event import TaskError, TaskResult, TaskStatus from blueapi.service.model import ( DeviceModel, DeviceResponse, @@ -41,7 +42,6 @@ WorkerTask, ) from blueapi.worker import ProgressEvent, WorkerEvent, WorkerState -from blueapi.worker.event import TaskError, TaskResult, TaskStatus @pytest.fixture diff --git a/tests/unit_tests/client/test_rest.py b/tests/unit_tests/client/test_rest.py index a36ee71a3f..7a1a2685e3 100644 --- a/tests/unit_tests/client/test_rest.py +++ b/tests/unit_tests/client/test_rest.py @@ -30,6 +30,8 @@ ) from blueapi.client.session import SessionCacheManager, SessionManager from blueapi.config import OIDCConfig +from blueapi.model.event import WorkerState +from blueapi.model.task import Task, TrackableTask from blueapi.service.model import ( DeviceModel, EnvironmentResponse, @@ -39,9 +41,6 @@ TasksListResponse, WorkerTask, ) -from blueapi.worker.event import WorkerState -from blueapi.worker.task import Task -from blueapi.worker.task_worker import TrackableTask TASK_REQUEST = TaskRequest( name="foo", params={"one": "two"}, instrument_session="cm12345-1" diff --git a/tests/unit_tests/service/test_interface.py b/tests/unit_tests/service/test_interface.py index e56e98c2e5..611ac3ae25 100644 --- a/tests/unit_tests/service/test_interface.py +++ b/tests/unit_tests/service/test_interface.py @@ -29,6 +29,14 @@ TiledConfig, ) from blueapi.core.context import BlueskyContext +from blueapi.model.event import ( + TaskResult, + TaskStatus, + TaskStatusEnum, + WorkerEvent, + WorkerState, +) +from blueapi.model.task import Task, TrackableTask from blueapi.service import interface from blueapi.service.authentication import TiledAuth from blueapi.service.model import ( @@ -43,15 +51,6 @@ ) from blueapi.service.numtracker import NumtrackerClient from blueapi.utils.invalid_config_error import InvalidConfigError -from blueapi.worker.event import ( - TaskResult, - TaskStatus, - TaskStatusEnum, - WorkerEvent, - WorkerState, -) -from blueapi.worker.task import Task -from blueapi.worker.task_worker import TrackableTask FAKE_INSTRUMENT_SESSION = "cm12345-1" diff --git a/tests/unit_tests/service/test_protocol.py b/tests/unit_tests/service/test_protocol.py index be583f956b..03826accf8 100644 --- a/tests/unit_tests/service/test_protocol.py +++ b/tests/unit_tests/service/test_protocol.py @@ -2,6 +2,7 @@ import pytest +from blueapi.model.task import InvalidTaskParameter, TaskParameterError from blueapi.service.model import TaskRequest from blueapi.service.protocol import ( Abort, @@ -13,7 +14,6 @@ Resume, Submit, ) -from blueapi.worker.task import InvalidTaskParameter, TaskParameterError @pytest.mark.parametrize( diff --git a/tests/unit_tests/service/test_rest_api.py b/tests/unit_tests/service/test_rest_api.py index 4315eecf61..667d9733b3 100644 --- a/tests/unit_tests/service/test_rest_api.py +++ b/tests/unit_tests/service/test_rest_api.py @@ -22,6 +22,13 @@ OIDCConfig, RestConfig, ) +from blueapi.model.event import TaskStatus, WorkerEvent, WorkerState +from blueapi.model.task import ( + InvalidTaskParameter, + Task, + TaskParameterError, + TrackableTask, +) from blueapi.service import interface, main from blueapi.service.authorization import OpaUserClient, opa from blueapi.service.interface import ( @@ -44,9 +51,6 @@ WorkerTask, ) from blueapi.service.runner import WorkerDispatcher -from blueapi.worker.event import TaskStatus, WorkerEvent, WorkerState -from blueapi.worker.task import InvalidTaskParameter, Task, TaskParameterError -from blueapi.worker.task_worker import TrackableTask class MockCountModel(BaseModel): ... diff --git a/tests/unit_tests/service/test_runner.py b/tests/unit_tests/service/test_runner.py index 8380784e05..668ff6a143 100644 --- a/tests/unit_tests/service/test_runner.py +++ b/tests/unit_tests/service/test_runner.py @@ -13,6 +13,7 @@ ) from pydantic import BaseModel, ValidationError +from blueapi.model.event import TaskStatus, WorkerEvent, WorkerState from blueapi.service import interface from blueapi.service.model import EnvironmentResponse from blueapi.service.runner import ( @@ -23,7 +24,6 @@ _safe_exception_message, import_and_run_function, ) -from blueapi.worker.event import TaskStatus, WorkerEvent, WorkerState @pytest.fixture diff --git a/tests/unit_tests/cli/test_scratch.py b/tests/unit_tests/service/test_scratch.py similarity index 93% rename from tests/unit_tests/cli/test_scratch.py rename to tests/unit_tests/service/test_scratch.py index a7df496186..99b59e869f 100644 --- a/tests/unit_tests/cli/test_scratch.py +++ b/tests/unit_tests/service/test_scratch.py @@ -8,8 +8,8 @@ import pytest from git import Repo -from blueapi.cli.scratch import ensure_repo, scratch_install, setup_scratch from blueapi.config import ScratchConfig, ScratchRepository +from blueapi.service.scratch import ensure_repo, scratch_install, setup_scratch from blueapi.utils import get_owner_gid @@ -38,7 +38,7 @@ def nonexistant_path(directory_path_with_sgid: Path) -> Path: return file_path -@patch("blueapi.cli.scratch.Popen") +@patch("blueapi.service.scratch.Popen") def test_scratch_install_installs_path( mock_popen: Mock, directory_path_with_sgid: Path, @@ -64,7 +64,7 @@ def test_scratch_install_fails_on_nonexistant_path(nonexistant_path: Path): scratch_install(nonexistant_path, timeout=1.0) -@patch("blueapi.cli.scratch.Popen") +@patch("blueapi.service.scratch.Popen") @pytest.mark.parametrize("code", [1, 2, 65536]) def test_scratch_install_fails_on_non_zero_exit_code( mock_popen: Mock, @@ -79,7 +79,7 @@ def test_scratch_install_fails_on_non_zero_exit_code( scratch_install(directory_path_with_sgid, timeout=1.0) -@patch("blueapi.cli.scratch.Repo") +@patch("blueapi.service.scratch.Repo") def test_repo_not_cloned_and_validated_if_found_locally( mock_repo: Mock, directory_path_with_sgid: Path, @@ -94,7 +94,7 @@ def test_repo_not_cloned_and_validated_if_found_locally( mock_repo.clone_from.assert_not_called() -@patch("blueapi.cli.scratch.Repo") +@patch("blueapi.service.scratch.Repo") def test_repo_cloned_if_not_found_locally( mock_repo: Mock, nonexistant_path: Path, @@ -114,7 +114,7 @@ def test_repo_cloned_if_not_found_locally( ) -@patch("blueapi.cli.scratch.Repo") +@patch("blueapi.service.scratch.Repo") def test_repo_cloned_with_correct_umask( mock_repo: Mock, directory_path_with_sgid: Path, @@ -143,7 +143,7 @@ def test_repo_discovery_errors_if_file_found_with_repo_name(file_path: Path): ensure_repo("http://example.com/foo.git", file_path) -@patch("blueapi.cli.scratch.Repo") +@patch("blueapi.service.scratch.Repo") def test_cloned_repo_changes_to_new_branch(mock_repo, tmp_path: Path): repo = MagicMock(name="ClonedRepo", spec=Repo) repo.heads.demo = None @@ -159,7 +159,7 @@ def test_cloned_repo_changes_to_new_branch(mock_repo, tmp_path: Path): ) -@patch("blueapi.cli.scratch.Repo") +@patch("blueapi.service.scratch.Repo") def test_existing_repo_not_changed_to_existing_branch(mock_repo, tmp_path: Path): (tmp_path / "demo_branch").mkdir() @@ -169,7 +169,7 @@ def test_existing_repo_not_changed_to_existing_branch(mock_repo, tmp_path: Path) mock_repo.clone_from.assert_not_called() -@patch("blueapi.cli.scratch.Repo") +@patch("blueapi.service.scratch.Repo") def test_existing_repo_not_changed_to_new_branch(mock_repo, tmp_path: Path): (tmp_path / "demo_branch").mkdir() repo = MagicMock(name="ExistingRepo", spec=Repo) @@ -182,8 +182,8 @@ def test_existing_repo_not_changed_to_new_branch(mock_repo, tmp_path: Path): repo.create_head.assert_not_called() -@patch("blueapi.cli.scratch.Repo") -@patch("blueapi.cli.scratch.LOGGER") +@patch("blueapi.service.scratch.Repo") +@patch("blueapi.service.scratch.LOGGER") def test_existing_repo_state_checked( mock_logger: MagicMock, mock_repo: MagicMock, tmp_path: Path ): @@ -201,8 +201,8 @@ def test_existing_repo_state_checked( ) -@patch("blueapi.cli.scratch.Repo") -@patch("blueapi.cli.scratch.LOGGER") +@patch("blueapi.service.scratch.Repo") +@patch("blueapi.service.scratch.LOGGER") def test_existing_repo_unknown_revision( mock_logger: MagicMock, mock_repo: MagicMock, tmp_path: Path ): @@ -306,8 +306,8 @@ def test_setup_scratch_succeeds_on_required_gid( setup_scratch(config) -@patch("blueapi.cli.scratch.ensure_repo") -@patch("blueapi.cli.scratch.scratch_install") +@patch("blueapi.service.scratch.ensure_repo") +@patch("blueapi.service.scratch.scratch_install") def test_setup_scratch_iterates_repos( mock_scratch_install: Mock, mock_ensure_repo: Mock, @@ -346,8 +346,8 @@ def test_setup_scratch_iterates_repos( ) -@patch("blueapi.cli.scratch.ensure_repo") -@patch("blueapi.cli.scratch.scratch_install") +@patch("blueapi.service.scratch.ensure_repo") +@patch("blueapi.service.scratch.scratch_install") def test_setup_scratch_continues_after_failure( mock_scratch_install: Mock, mock_ensure_repo: Mock, diff --git a/tests/unit_tests/test_extras.py b/tests/unit_tests/test_extras.py new file mode 100644 index 0000000000..d97c3a1178 --- /dev/null +++ b/tests/unit_tests/test_extras.py @@ -0,0 +1,26 @@ +import subprocess +import sys + +SERVER_ONLY = ["ophyd_async", "git", "tiled", "aioca", "dodal", "graypy"] + + +def _run(blocked: list[str], code: str) -> subprocess.CompletedProcess[str]: + # A None entry in sys.modules makes the import fail as if it was not installed + setup = f"import sys; sys.modules.update(dict.fromkeys({blocked}));" + return subprocess.run( + [sys.executable, "-c", setup + code], capture_output=True, text=True + ) + + +def test_client_imports_without_server_dependencies(): + result = _run(SERVER_ONLY, "import blueapi.__main__, blueapi.client") + assert result.returncode == 0, result.stderr + + +def test_client_commands_ask_for_client_extra(): + result = _run( + ["websockets"], + "from blueapi.__main__ import main; main(['controller', 'plans'])", + ) + assert result.returncode != 0 + assert "pip install blueapi[client]" in result.stderr diff --git a/tests/unit_tests/worker/test_task_worker.py b/tests/unit_tests/worker/test_task_worker.py index 044668d93e..c4a93e348d 100644 --- a/tests/unit_tests/worker/test_task_worker.py +++ b/tests/unit_tests/worker/test_task_worker.py @@ -20,7 +20,8 @@ from blueapi.config import DeviceManagerSource, EnvironmentConfig, PlanSource from blueapi.core import BlueskyContext, EventStream -from blueapi.core.bluesky_types import DataEvent +from blueapi.model.event import DataEvent, TaskResult, TaskStatusEnum +from blueapi.model.task import TaskParameterError from blueapi.service.model import PlanModel from blueapi.utils.base_model import BlueapiBaseModel from blueapi.worker import ( @@ -33,8 +34,6 @@ WorkerEvent, WorkerState, ) -from blueapi.worker.event import TaskResult, TaskStatusEnum -from blueapi.worker.task import TaskParameterError _SIMPLE_TASK = Task(name="sleep", params={"time": 0.0}) _LONG_TASK = Task(name="sleep", params={"time": 1.0}) diff --git a/uv.lock b/uv.lock index 6ddebe63f6..255c879d9b 100644 --- a/uv.lock +++ b/uv.lock @@ -484,23 +484,19 @@ dependencies = [ { name = "bluesky", extra = ["plotting"] }, { name = "bluesky-stomp" }, { name = "click" }, - { name = "event-model" }, - { name = "gitpython" }, { name = "observability-utils" }, - { name = "opentelemetry-distro" }, - { name = "ophyd-async" }, - { name = "packaging" }, { name = "pydantic" }, - { name = "pydantic-settings" }, { name = "pyjwt", extra = ["crypto"] }, { name = "pyyaml" }, { name = "requests" }, - { name = "stomp-py" }, - { name = "tqdm" }, - { name = "websockets" }, ] [package.optional-dependencies] +client = [ + { name = "packaging" }, + { name = "tqdm" }, + { name = "websockets" }, +] demo = [ { name = "dls-dodal" }, { name = "ophyd-async", extra = ["sim"] }, @@ -508,10 +504,14 @@ demo = [ server = [ { name = "aioca" }, { name = "aiohttp" }, + { name = "event-model" }, { name = "fastapi" }, + { name = "gitpython" }, { name = "graypy" }, { name = "httpx" }, + { name = "opentelemetry-distro" }, { name = "opentelemetry-instrumentation-fastapi" }, + { name = "ophyd-async" }, { name = "tiled", extra = ["client"] }, { name = "uvicorn" }, ] @@ -525,11 +525,12 @@ client-system-test = [ { name = "responses" }, ] dev = [ - { name = "blueapi", extra = ["server"] }, + { name = "blueapi", extra = ["client", "server"] }, { name = "copier" }, { name = "deepdiff" }, { name = "dls-dodal" }, { name = "httpx2" }, + { name = "import-linter" }, { name = "jwcrypto" }, { name = "mock" }, { name = "myst-parser" }, @@ -567,29 +568,27 @@ requires-dist = [ { name = "bluesky-stomp", specifier = ">=0.1.6" }, { name = "click", specifier = ">=8.2.0" }, { name = "dls-dodal", marker = "extra == 'demo'", specifier = ">=3.0.2" }, - { name = "event-model", specifier = "==1.24.0" }, + { name = "event-model", marker = "extra == 'server'", specifier = "==1.24.0" }, { name = "fastapi", marker = "extra == 'server'", specifier = ">=0.112.0" }, - { name = "gitpython", specifier = ">=3.1.58" }, + { name = "gitpython", marker = "extra == 'server'", specifier = ">=3.1.58" }, { name = "graypy", marker = "extra == 'server'", specifier = ">=2.1.0" }, { name = "httpx", marker = "extra == 'server'", specifier = ">=0.28.1" }, { name = "observability-utils", specifier = ">=0.1.4" }, - { name = "opentelemetry-distro", specifier = ">=0.48b0" }, + { name = "opentelemetry-distro", marker = "extra == 'server'", specifier = ">=0.48b0" }, { name = "opentelemetry-instrumentation-fastapi", marker = "extra == 'server'", specifier = ">=0.48b0" }, - { name = "ophyd-async", specifier = ">=0.13.5" }, + { name = "ophyd-async", marker = "extra == 'server'", specifier = ">=0.13.5" }, { name = "ophyd-async", extras = ["sim"], marker = "extra == 'demo'" }, - { name = "packaging" }, + { name = "packaging", marker = "extra == 'client'" }, { name = "pydantic", specifier = ">=2.0" }, - { name = "pydantic-settings" }, { name = "pyjwt", extras = ["crypto"] }, { name = "pyyaml", specifier = ">=6.0.2" }, { name = "requests" }, - { name = "stomp-py" }, { name = "tiled", extras = ["client"], marker = "extra == 'server'", specifier = "==0.2.18" }, - { name = "tqdm" }, + { name = "tqdm", marker = "extra == 'client'" }, { name = "uvicorn", marker = "extra == 'server'", specifier = ">=0.52.1" }, - { name = "websockets" }, + { name = "websockets", marker = "extra == 'client'" }, ] -provides-extras = ["demo", "server"] +provides-extras = ["client", "demo", "server"] [package.metadata.requires-dev] client-system-test = [ @@ -600,11 +599,12 @@ client-system-test = [ { name = "responses" }, ] dev = [ - { name = "blueapi", extras = ["server"] }, + { name = "blueapi", extras = ["server", "client"] }, { name = "copier" }, { name = "deepdiff" }, { name = "dls-dodal", specifier = ">=3.0.2" }, { name = "httpx2", specifier = ">=2.5.0" }, + { name = "import-linter" }, { name = "jwcrypto" }, { name = "mock" }, { name = "myst-parser" }, @@ -2296,6 +2296,105 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/30/cf/697c051fd534e223461fb8b523890e21a24eeca229cd50624cff6f02fabd/greenlet-3.5.6-cp315-cp315t-win_arm64.whl", hash = "sha256:f9fe868463ec7e1363733af77e38a5fda3e9b63940337048c945d69e0c80ff24", size = 315070, upload-time = "2026-09-14T14:22:21.476Z" }, ] +[[package]] +name = "grimp" +version = "3.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f2/83/0513ead3a84244b62f75e144aeacc6a5121ca676ff6cffe8f20015dbc5fa/grimp-3.20.tar.gz", hash = "sha256:f6e3052d9ce85af2d930ad5285d2ed5311ead2af1542add9f72e587ef679c25b", size = 836347, upload-time = "2026-11-13T20:25:12.481Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ad/91/91c50c56a56a4d477108e44614fc4483db0fd4b90dcf22f672336fcbc3f5/grimp-3.20-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:6426a6529a771a11d8c4d1e8af982f35709de2ce506d2d4acaff9d5b38ed4998", size = 2156456, upload-time = "2026-11-13T20:22:43.505Z" }, + { url = "https://files.pythonhosted.org/packages/44/e2/b4d4c6a8d22af6545ffedc2e66b26bb81f4c89883f01c44282a0725a636c/grimp-3.20-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:32620f0f41b73fbaa1b2f63ea483a5ffbb32bdb8c2092781ad6e529dd3c8d647", size = 2114900, upload-time = "2026-11-13T20:22:45.476Z" }, + { url = "https://files.pythonhosted.org/packages/e6/cf/bc07fcf07b365b5e524524939f68b4f13c896174115832b337db562d5e42/grimp-3.20-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:876171ff6fc72602897cd8829c3da7d5b74d60f13a661ba4ce8ce400d059d036", size = 2292686, upload-time = "2026-11-13T20:22:47.077Z" }, + { url = "https://files.pythonhosted.org/packages/ab/98/ac14de2664debe18581d6d47528999b88927c252a65d21abb1d0152d1d68/grimp-3.20-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:0d571ab89b485d066eb828f0c1c375beea11ed6af1b7b531f53c85f6763595e7", size = 2236561, upload-time = "2026-11-13T20:22:48.669Z" }, + { url = "https://files.pythonhosted.org/packages/72/2e/88730efb179d70c8e2980dc83f26d94b50162b24de73ce87733d1be05c20/grimp-3.20-cp311-cp311-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:02f226dd2958d456ae3cd04265fdaa0bd0d64aaea9a23cbefba343c431054871", size = 2384240, upload-time = "2026-11-13T20:22:50.387Z" }, + { url = "https://files.pythonhosted.org/packages/54/31/b539746da16a16164baa01db36730f1f84171ee45043f0f543b9b99632a6/grimp-3.20-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:84dffe49951a68d9dae83a5fc17f24efb7f83f609e7c84a4d9ace05588283d99", size = 2646041, upload-time = "2026-11-13T20:22:51.857Z" }, + { url = "https://files.pythonhosted.org/packages/fc/c2/f5357ce8e4f53cba78e29452d48a21c25094a753a3d029e893842c9739d5/grimp-3.20-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:e33a8a9c7442ea8f88a2483e048100c1c9f573fc6ecd0f81fb8a8488bf8c1031", size = 2374442, upload-time = "2026-11-13T20:22:53.529Z" }, + { url = "https://files.pythonhosted.org/packages/8d/21/69a6c1177faaa9d1a55fb2040a443f9ae8ef8b939e1f6736399b3409ff3b/grimp-3.20-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:9638048d94b826b5fb9d960e3f72586bb0e51b2a79923f6d687160fef2263930", size = 2301932, upload-time = "2026-11-13T20:22:55.19Z" }, + { url = "https://files.pythonhosted.org/packages/01/e5/d765c094b43343cb203ac27b5cc2a65922f9e91fa9e8da902f9c13486f69/grimp-3.20-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:2cbd95c0dd3758b8d2e2c20bfc601cbcdf86da3cbd30cc8a63e0fdf7d16f51d9", size = 2473546, upload-time = "2026-11-13T20:22:56.615Z" }, + { url = "https://files.pythonhosted.org/packages/41/6e/874c135606f380ff48fca8ab1eed0b40367bb159b87900b21036f796ac25/grimp-3.20-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:d330cc8826aa29aec2bf8d983102d2223de9b4146ee4374f9737c55511f9ae62", size = 2509709, upload-time = "2026-11-13T20:22:58.084Z" }, + { url = "https://files.pythonhosted.org/packages/e0/74/c609532a699e6be4c91b07e0af94eb9978a8f3dbd0d82f87220b245034ff/grimp-3.20-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:2afe63230aa7195815bc903e4c0fa1db6f52212f934380f1145e9aaeb08a16d3", size = 2544442, upload-time = "2026-11-13T20:22:59.644Z" }, + { url = "https://files.pythonhosted.org/packages/19/90/76a67c54ef223fb7e27df44726303c20953fdf52c574485187ee92b90b1b/grimp-3.20-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:96d6362df53ce4c7f92f99b283f154ba6b28fd64b0cd10df8c290875be2ae4c1", size = 2560120, upload-time = "2026-11-13T20:23:01.331Z" }, + { url = "https://files.pythonhosted.org/packages/7b/b6/9dd75aa48644a1e6443ac8b517187a21c7e7d6be448816f71f017fbf2d2a/grimp-3.20-cp311-cp311-win32.whl", hash = "sha256:bb69a725f0bf99034be2d5ed8474f1c9075d67f2e20dd0a66f1895f3bf9a997b", size = 1885287, upload-time = "2026-11-13T20:23:03.273Z" }, + { url = "https://files.pythonhosted.org/packages/52/51/a0a745e089a933266e02e2b524a93c2e153d12bd5dcdcfa7e18efe9363cb/grimp-3.20-cp311-cp311-win_amd64.whl", hash = "sha256:6660cf5620bdcd7d44cad4cd53d77e28156a6dbdf8572a30776245a7d02bea27", size = 2013928, upload-time = "2026-11-13T20:23:04.871Z" }, + { url = "https://files.pythonhosted.org/packages/b6/b9/84eef2beaeb47d06a4a8754baa02d35c2bdf133a05b6dbc135fe09bbd40d/grimp-3.20-cp311-cp311-win_arm64.whl", hash = "sha256:1a5cf0609112ccc59f4f3aee3fb149393bac80848b9a4dc365acfd2667fd0b70", size = 1935700, upload-time = "2026-11-13T20:23:06.297Z" }, + { url = "https://files.pythonhosted.org/packages/81/7d/bf0c78f9845ee2be41228f8b772a6d3648e2e0332c18233864d6174a6560/grimp-3.20-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:96cfad40261de49394fcd4cea3aaf3100a2b1b74eadc42ec22937fb0b209a655", size = 2160618, upload-time = "2026-11-13T20:23:07.792Z" }, + { url = "https://files.pythonhosted.org/packages/00/ad/44d8354c345f5d1158b53ed4a12335331df36c55eb5cbc35bcbd37355a08/grimp-3.20-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e8721f396c9e853b2807abd1e5a5757944d981829dddce8e4def94b116c7e6f3", size = 2105195, upload-time = "2026-11-13T20:23:09.235Z" }, + { url = "https://files.pythonhosted.org/packages/b5/85/90fafa8dea17ad7e4dce844b8d631f7f10a6245eac0ffdbcb2026a0c01a3/grimp-3.20-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:5ed8fddaa9db627e57d9f3cc9cb694854712cd3b8988b420eac8db3845f7dee5", size = 2286290, upload-time = "2026-11-13T20:23:10.958Z" }, + { url = "https://files.pythonhosted.org/packages/7c/3d/5f6bd85ace4d1f61ba0723e3819a63cb20689dd987f835c2331ecc17ec20/grimp-3.20-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:4ba157d97ea39e0d60c9cd7c417448f94ce9988d2f3024bc193beea25d769352", size = 2232284, upload-time = "2026-11-13T20:23:12.622Z" }, + { url = "https://files.pythonhosted.org/packages/e0/34/3bf982502ede9bb51ff5fbcc927904f5b5653deaba0be36cb9fa6235d4c1/grimp-3.20-cp312-cp312-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:8b2d7944997473e52f91a4540fd094e6b9327f72840fb84cd72c9c7116d15687", size = 2376983, upload-time = "2026-11-13T20:23:14.371Z" }, + { url = "https://files.pythonhosted.org/packages/07/2d/d0587fb4a5975b4309705e1e87161e0abe8e8fb5e86946eae7a5f105c2fa/grimp-3.20-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:d7009ae88882afd89f66bf800f184d8fce4ee362a30768a2046a007d047e13c7", size = 2640023, upload-time = "2026-11-13T20:23:15.899Z" }, + { url = "https://files.pythonhosted.org/packages/c5/19/f390ec17df19ae6216bb6fd2cec9bfd9e2d4887de97feddcc8fe43d36b30/grimp-3.20-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:5d0a36f0315efd095a3562261ad0f1bb9cec25104f1d258f636fcad4b1035112", size = 2371894, upload-time = "2026-11-13T20:23:17.399Z" }, + { url = "https://files.pythonhosted.org/packages/d7/e8/12e168379a1cca54e6292f733a661c61d273651017f6cbe465e8ae1c3478/grimp-3.20-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:b1a288f453839f93747864c4cab5e09dfb00f162e45294a8fc5c3634756b35c5", size = 2293784, upload-time = "2026-11-13T20:23:19.493Z" }, + { url = "https://files.pythonhosted.org/packages/b4/7f/7107ec9d4e9e1c827f82bc79681ef9753cc7ff2d0ec9aa1ce850f124d01a/grimp-3.20-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:a34103f253057ba4d052ddb7cf0bb5ec4c254cb68355c0a6a41fa735434c5233", size = 2465012, upload-time = "2026-11-13T20:23:21.029Z" }, + { url = "https://files.pythonhosted.org/packages/9b/77/e9513e61cf16f1f02b6da27b07b5a5c34c9c3e0dd41c06a26d8ceea82ae8/grimp-3.20-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:e8e8124315e7640ecbf8c43596bedbe9bd2e98fb0657024af300700cfb41b243", size = 2504887, upload-time = "2026-11-13T20:23:22.732Z" }, + { url = "https://files.pythonhosted.org/packages/a5/9c/ce3901ab2bd3c1a4e9558b7c611bcf41b7dea4b7fed32e3d5aa6d004b056/grimp-3.20-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:3584cd868cebb77d7993b2539575477bee4e156d7e8b9840644ccc491731a3c5", size = 2537592, upload-time = "2026-11-13T20:23:24.485Z" }, + { url = "https://files.pythonhosted.org/packages/28/ea/90444e82702c8bb4e288f32ea8723061a5a44733e736b33e42cfebccf15d/grimp-3.20-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:a309cdb1ef2f840305e3214e88ecb08da3651867a747d01f20fb93096d1f6f40", size = 2552569, upload-time = "2026-11-13T20:23:26.741Z" }, + { url = "https://files.pythonhosted.org/packages/cd/3a/e742e5ae94cb734173da018dd2afa537a38050f8b1c8a9a80805c2b110d7/grimp-3.20-cp312-cp312-win32.whl", hash = "sha256:978a6cbddfa1c289988cf0dea19a831adf80b6b330911e8a3bb1b72d3401539b", size = 1882969, upload-time = "2026-11-13T20:23:28.787Z" }, + { url = "https://files.pythonhosted.org/packages/29/9f/8260e92dfc0bace8df8646961e155cab31a5637eb97bb3adc3c19428f640/grimp-3.20-cp312-cp312-win_amd64.whl", hash = "sha256:ab528f0b33485df38c12ff0906f6a7d719eb6e6027859f464cfd08abbd430b7f", size = 2010526, upload-time = "2026-11-13T20:23:30.183Z" }, + { url = "https://files.pythonhosted.org/packages/b1/0c/c68e2bec80e342036cbb890ece2748078291892d4011247127054b0cd425/grimp-3.20-cp312-cp312-win_arm64.whl", hash = "sha256:8d47c1e1d8a5659b1c35c9e3a43d0ccec6802ae5581924dc466f421314bb59b4", size = 1931659, upload-time = "2026-11-13T20:23:31.799Z" }, + { url = "https://files.pythonhosted.org/packages/2f/cc/916d444d13987babaea358f179efb093e41b0c0f732c82d08108245062ba/grimp-3.20-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:a5ad98fe1421c1007508a6bce595630385920340fbc2b43588c80ad73cefcb92", size = 2158835, upload-time = "2026-11-13T20:23:33.279Z" }, + { url = "https://files.pythonhosted.org/packages/4b/f4/7d59b62774acdd71b147f21fd434bb22f105d2fce44db79f35d23fda0920/grimp-3.20-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:7da53af57d8f8789655e513f57332ab7604cd89b6c80c6e9ad4d8caa5f7ac630", size = 2105002, upload-time = "2026-11-13T20:23:34.786Z" }, + { url = "https://files.pythonhosted.org/packages/e1/73/85186e02e9cb21aab18e19b975fcc718597cada80fafcb4a8a4f873b7d8b/grimp-3.20-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:b0f23e00bdbb0eed99c6696037fae5c62feec1f5af4ce041fbc575ed448d4ee0", size = 2285700, upload-time = "2026-11-13T20:23:36.221Z" }, + { url = "https://files.pythonhosted.org/packages/3a/26/cce4b69c4817522849ea4fcec8a328b72cfb67604a6c4e3be20d611e2b8f/grimp-3.20-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:6df4a0e4b2749f0eb66550d91107548ef9dfe7a3a9f03a3f925f25ebdb358187", size = 2231508, upload-time = "2026-11-13T20:23:38.099Z" }, + { url = "https://files.pythonhosted.org/packages/7e/de/16a677b9a83ad3057bb8b6a9e3b1ed06dc76477e6600a7f984241dbb4500/grimp-3.20-cp313-cp313-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:082e69ababe4a63904aba4e234faa51e2861bfb627d2459fd4dee86954ca0141", size = 2376890, upload-time = "2026-11-13T20:23:40.083Z" }, + { url = "https://files.pythonhosted.org/packages/25/55/d3781fc1979f30175d0c26db0261e6a4c284db2362750eec7e834ef2cc37/grimp-3.20-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:fc03b7acba0c9eb273a0b2165046caf20576e26bf022a88dd458b6e1cfcb6a7f", size = 2640004, upload-time = "2026-11-13T20:23:41.789Z" }, + { url = "https://files.pythonhosted.org/packages/6e/4d/b90461c91fd08b7a97612ae6bae62b2b53940ae6290022961df51fc115db/grimp-3.20-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:633cca13858b41998dfa94e0208eb504ed5e956e0b5fcd1e8a4c9e47c5c76162", size = 2371817, upload-time = "2026-11-13T20:23:43.422Z" }, + { url = "https://files.pythonhosted.org/packages/bd/ec/aa3d6d8bf63f039fed85f6c633129e5f056f49205393d7f8227c91598d7b/grimp-3.20-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:bb11c66536376d607bf166a475f24ba5f9462c8ed22958a5cd03816a1a83bd4f", size = 2295091, upload-time = "2026-11-13T20:23:44.914Z" }, + { url = "https://files.pythonhosted.org/packages/b0/00/36e1f43f9f67c82d94d4a48e2efbc9e9e7de57fe2f5b1f165139ab835cd4/grimp-3.20-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ab94d8cacb6243d7c611f39cb41085e3d2649c017d6972b1decfce01ae532777", size = 2463744, upload-time = "2026-11-13T20:23:46.369Z" }, + { url = "https://files.pythonhosted.org/packages/59/e6/2bf0c27c177be03852777c432a2f1c1f20cf04c6062d0bd16746241441c0/grimp-3.20-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:e56041d766bebec55f57556768f15e3d19b41feb1c48d4ce44ff8d4dff8179f7", size = 2504405, upload-time = "2026-11-13T20:23:48.265Z" }, + { url = "https://files.pythonhosted.org/packages/41/92/344881264ca3a9d688121801c78a621119c5a1f946d41add75cb2b4cfe2f/grimp-3.20-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:8f965437ee431b8d9365ad1afe6ad2daf9840de828996fcd866324ba2a8dc532", size = 2538023, upload-time = "2026-11-13T20:23:49.982Z" }, + { url = "https://files.pythonhosted.org/packages/5d/54/3079761a018fd9b7aa24d78a86825dd2b04ead3b549375b3aaf29e845966/grimp-3.20-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:7845cc11960e8c554d7861df28b494e851794943b7ebdde90d5ec61a3fbc79b8", size = 2553095, upload-time = "2026-11-13T20:23:51.586Z" }, + { url = "https://files.pythonhosted.org/packages/9a/6e/144cf005682195a6143615292905f92d93b1795cd7ec434f594ecf41ae49/grimp-3.20-cp313-cp313-win32.whl", hash = "sha256:14cffc84e41381bd7e1fd4a6081e269ea5fa14fd74f6e7341d3dbfac0afdf72a", size = 1881226, upload-time = "2026-11-13T20:23:53.095Z" }, + { url = "https://files.pythonhosted.org/packages/c3/7d/cb93bfbc2d26c554db386db71ac1e3e2470952f03d75e9295148c1f6b1ad/grimp-3.20-cp313-cp313-win_amd64.whl", hash = "sha256:85f83e6a030c183693fbe29f40783743b2f1a57606859a262d6696ee6fd154ec", size = 2010252, upload-time = "2026-11-13T20:23:54.616Z" }, + { url = "https://files.pythonhosted.org/packages/96/56/87caa795c8dca67193e18d04e05efa38199d19727aac1cd3a71d5d78ba16/grimp-3.20-cp313-cp313-win_arm64.whl", hash = "sha256:525245aa57a5bc841bd3af154b4bd20c3f290386b4e03cc103da9d655ac58289", size = 1930488, upload-time = "2026-11-13T20:23:56.178Z" }, + { url = "https://files.pythonhosted.org/packages/df/50/4db7bc552a857a1e7667aa6f053791cb84a7a503d04c2afa697717858255/grimp-3.20-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:e6fac8ce1ee39208a23047695ca8d058eb70df563640ee15de68f2afaafa6fab", size = 2161700, upload-time = "2026-11-13T20:23:57.925Z" }, + { url = "https://files.pythonhosted.org/packages/08/9c/95775978b6b0d2c00be62614a6d718eca98366ee30a873e7a71bbdfb87c5/grimp-3.20-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:27dcc731204b9cdababe698676536e313499e8683ff72cf66e133c5e4813d759", size = 2105273, upload-time = "2026-11-13T20:23:59.368Z" }, + { url = "https://files.pythonhosted.org/packages/40/65/9875f637b413ea26ed0c042f0b7528bf1fc7b5abb6cb895581c2f5b5e162/grimp-3.20-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:4f4cf78fb13cfc4c47eb1985ba90c166613a55d6430de39b7eae0f16f822a7af", size = 2287147, upload-time = "2026-11-13T20:24:00.986Z" }, + { url = "https://files.pythonhosted.org/packages/e5/27/4c0943b12361987b814c48add1fcaa00b747d3c96365e88430c31baeb111/grimp-3.20-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:07f3874502d559a45bf4885e741bff26c82d386273b7adfd9e80634fec5aa0b0", size = 2230987, upload-time = "2026-11-13T20:24:02.702Z" }, + { url = "https://files.pythonhosted.org/packages/71/43/f552c0d2cbc98dba3792f581799c519f9ca253ed9749c00b46e8eeba65ab/grimp-3.20-cp314-cp314-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:b482ff3c5ffa1d00a116d8943446e68ecb1b71d9ce4d9769e305d41cd9eee0d5", size = 2377536, upload-time = "2026-11-13T20:24:04.159Z" }, + { url = "https://files.pythonhosted.org/packages/47/62/7444297e93044c2d45420ce903a37f130edd9e85f652b94dcc40295a92df/grimp-3.20-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:b73181b538286336b1225a13ffd5440f4c0a2eb3a05fb8b7d35b9b874ecf3ff7", size = 2639368, upload-time = "2026-11-13T20:24:05.707Z" }, + { url = "https://files.pythonhosted.org/packages/78/5a/1e457ac1b79f0d961c277b30fc8683c8bf04e2b8aa9bbbb2425481ac3527/grimp-3.20-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:eedaccc6933402a8b0f85a68e608f946899f514b33f1ca7ac066b712358f5d47", size = 2371154, upload-time = "2026-11-13T20:24:07.719Z" }, + { url = "https://files.pythonhosted.org/packages/78/0e/bd28e0ab5fd3d356617a9d30aafbb872838be3865299f3af4be3244d51e2/grimp-3.20-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:5bd013cbb5c145cdb7759f28b73b39bc9ba75aa293bfe12e674c8c62f3311b91", size = 2296608, upload-time = "2026-11-13T20:24:09.398Z" }, + { url = "https://files.pythonhosted.org/packages/0b/b6/38626f89261e6f119f9dd54b611803486727703ce256050b1226e193e28d/grimp-3.20-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:29985c6e118019bfd0e0da16e7b27792a0b44fb44ce97af75b36949456935ade", size = 2467041, upload-time = "2026-11-13T20:24:11.049Z" }, + { url = "https://files.pythonhosted.org/packages/3d/91/ee86b6648791eb77237b78475dc4c2007959933328daa207e8a2ef2a151c/grimp-3.20-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:1021f210bdf83e59bb4a9aa08ff9cfb9210f9b099f730ed1511dc3302e5904d5", size = 2504672, upload-time = "2026-11-13T20:24:12.554Z" }, + { url = "https://files.pythonhosted.org/packages/5b/e0/4fa8587a7676f70725d4a15088a9e63832aed55c62f56afd893d49be3f9f/grimp-3.20-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:bcc793720b606e767d72e47a0c84b6c1e1a7e90d8200ad96b6c1eadafcd7bfb9", size = 2539178, upload-time = "2026-11-13T20:24:14.147Z" }, + { url = "https://files.pythonhosted.org/packages/dd/61/9a7d47408136d4fde6dbca8f64f9b90839e3208597c6563e3b381e93d480/grimp-3.20-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:965e0a162b6a8f99a3cbf3089d5975e5e82c47e59821b17609c16f24ee3b62bb", size = 2555307, upload-time = "2026-11-13T20:24:15.969Z" }, + { url = "https://files.pythonhosted.org/packages/25/fb/54d09f20711fc6e8d6f8bf61705e497a20ee46c702a54b973a132737c491/grimp-3.20-cp314-cp314-win32.whl", hash = "sha256:dd287407ea542e3f467b8673fd2bfe31b41a3f6e5cc31f8e0b4017c997f0839a", size = 1882557, upload-time = "2026-11-13T20:24:17.679Z" }, + { url = "https://files.pythonhosted.org/packages/01/e8/99774711264db04512af7b5bdb70c8a700a6bf1d97797acaa8b36739d109/grimp-3.20-cp314-cp314-win_amd64.whl", hash = "sha256:df3b26d591417f305be9463e93f27fcc5b17e8c17529ef292886bc0bfe21f216", size = 2011502, upload-time = "2026-11-13T20:24:19.102Z" }, + { url = "https://files.pythonhosted.org/packages/57/8d/58a79b82b935e7732abbbe2cb91734b2abf5c486390dc617ae3cdd8665cb/grimp-3.20-cp314-cp314-win_arm64.whl", hash = "sha256:bb07b50279b08d29ec91469f6b39930eee597a0690dccf911239ed5083a641e8", size = 1932301, upload-time = "2026-11-13T20:24:20.675Z" }, + { url = "https://files.pythonhosted.org/packages/eb/d3/173000d4d07ed9fe151c3136da46f44e28966bd1997fe91b4c232fb33b84/grimp-3.20-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:1a2fcfb6db4cdb386e7df8b097f7c9566c36f90bb7cbcfff4950fd035f13191c", size = 2161589, upload-time = "2026-11-13T20:24:22.616Z" }, + { url = "https://files.pythonhosted.org/packages/2e/3d/190bff0cdaf6abeb1ed7931c22135761360d2743dc1f6f6c7c7c3a10c859/grimp-3.20-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:fc2f1836d001ac0ca7244c282e2e0a8114b31bfd2ef9ffec43cc3c3858543cb4", size = 2103825, upload-time = "2026-11-13T20:24:24.093Z" }, + { url = "https://files.pythonhosted.org/packages/cf/b4/2cb90ae40aaa6ac8d4b387313dbf7f897ac2276c4817f6315f189681462e/grimp-3.20-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:2fe5719edd628ca50c1c28332749da6e81fea163d7dec42d304ff93397b9a2db", size = 2286676, upload-time = "2026-11-13T20:24:25.756Z" }, + { url = "https://files.pythonhosted.org/packages/a3/b0/36fe3c3cc2fd6c614fe44df489ea03dbeb5e3256eab897ee01aa259d64fd/grimp-3.20-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:a47db007d8eed48071250af906d762ea41ae3e65673ae03cbc5aaae8aded3b12", size = 2230527, upload-time = "2026-11-13T20:24:27.363Z" }, + { url = "https://files.pythonhosted.org/packages/55/98/5bee73ea62260386333a80e74503e232b9cbc6417e86c2cffc218e6b81a7/grimp-3.20-cp314-cp314t-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:c9bf4965bf2f880ff722a635f027fa413aa226406d10b64b2da6a4f68c632f25", size = 2375341, upload-time = "2026-11-13T20:24:29.014Z" }, + { url = "https://files.pythonhosted.org/packages/8b/00/8bdb21da32c95d9bb59e0454d20468aed0aa4d3dc547b76a18348dc0ce99/grimp-3.20-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:1eb0945be387d9c597d18f35b386b64cda1b732c542ab1cc39f962d43c2c4518", size = 2639697, upload-time = "2026-11-13T20:24:30.95Z" }, + { url = "https://files.pythonhosted.org/packages/9b/a9/c9917c88033f4322b313071d716f2e074ac4f26b2f6730fb4583c77e4271/grimp-3.20-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:f494a4f10ceeb9de17d953b8df472e6a3f9db6d69b762c366fd48158257cb5ab", size = 2373845, upload-time = "2026-11-13T20:24:32.453Z" }, + { url = "https://files.pythonhosted.org/packages/0b/0e/97b6c022248dd26f05a20bf5562d4c1cadc16cec3b3eb783e53081b615c2/grimp-3.20-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c8b0ad7e7842456a33188e4684d73083467f3399ea2b88b7ba06a0bed9a16139", size = 2298670, upload-time = "2026-11-13T20:24:33.868Z" }, + { url = "https://files.pythonhosted.org/packages/8f/a6/755d01b67fec0ad42cf08f1211de5e5d1e93ba95c1409a1a9c331724c45a/grimp-3.20-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:bb9d6a147b8cba2105ce3c62fc487980e160bd48f875c59661cb6502c4f1d2d8", size = 2465692, upload-time = "2026-11-13T20:24:35.649Z" }, + { url = "https://files.pythonhosted.org/packages/b4/66/4a791902fd2d6696fcfa6228ee3a902e49496d27d72144d0d6d02a435cd5/grimp-3.20-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:e159609e79adc28303b170940fc6377609ef2d477877616a3f66dbbe81531b00", size = 2503457, upload-time = "2026-11-13T20:24:37.391Z" }, + { url = "https://files.pythonhosted.org/packages/44/db/7f7a90d897a510a07e7d46a2b04ce4ef92fe90246df47becb9a50514b8ae/grimp-3.20-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:e4f13e5138bc0cbe538075dc3df4883900386f87e1d17c251d1aa83c2504bab3", size = 2536733, upload-time = "2026-11-13T20:24:39.105Z" }, + { url = "https://files.pythonhosted.org/packages/d9/cd/1599c012a57c08a522f595939d84caff100c01130a3559f2170526256863/grimp-3.20-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:23423a85da1db067ca84c5b9393bff005478954043df65966cbe98d8b1e27289", size = 2555691, upload-time = "2026-11-13T20:24:40.58Z" }, + { url = "https://files.pythonhosted.org/packages/a7/2d/0884033273fc244a680eeda6763f3b512919cf308f7be278daa96e793699/grimp-3.20-cp314-cp314t-win32.whl", hash = "sha256:1a40343cb35b683bdd3f54f4597863a4647faa4cafcfa5e6b832b66af22c3897", size = 1879277, upload-time = "2026-11-13T20:24:42.149Z" }, + { url = "https://files.pythonhosted.org/packages/86/84/8d54c71dd4f5f6c63e6fcfa0dd6f3e050466a4951e65fd384c98abb3da7d/grimp-3.20-cp314-cp314t-win_amd64.whl", hash = "sha256:db9cb40b4e1943f645982d8a6d697837d6b00b25d55b1781a2578ce9a1ae2c49", size = 2010621, upload-time = "2026-11-13T20:24:43.772Z" }, + { url = "https://files.pythonhosted.org/packages/3f/b9/79d41d59c7be5dd47e8dc56ab09c3c5f2cfe89119d8ccf48032cfba352f8/grimp-3.20-cp314-cp314t-win_arm64.whl", hash = "sha256:00b7421cfd0307e8ff6749a30fdd89502b74916c55c5c38c0e16f512a1b661eb", size = 1931638, upload-time = "2026-11-13T20:24:45.527Z" }, + { url = "https://files.pythonhosted.org/packages/fe/89/68252fed67806c1655c63762b7f764325d043cf3e3dff51cf0302144ae63/grimp-3.20-cp315-cp315-macosx_10_12_x86_64.whl", hash = "sha256:4a1248b328a9c47cd1cb193ff042f3de87c19f751f95280f82db5676d861ebfb", size = 2161899, upload-time = "2026-11-13T20:24:47.011Z" }, + { url = "https://files.pythonhosted.org/packages/63/ba/c47dbcf18ba77488553327cab9893c1b43069af69dfa004dc04287a88c7d/grimp-3.20-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:c704da65e15e805f0aaf49b6edf68587bf1941dfc53f873cf159c4097c263cd1", size = 2105484, upload-time = "2026-11-13T20:24:48.846Z" }, + { url = "https://files.pythonhosted.org/packages/7a/4c/163a28c21d6ceae41991c4f92b55d1e009e2f68b288a19f31887d610662b/grimp-3.20-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:9bf3bfb6d19b5203f44bbd4dea60b708fb2e282caf19914862eff955a6ab0a44", size = 2287617, upload-time = "2026-11-13T20:24:50.38Z" }, + { url = "https://files.pythonhosted.org/packages/ea/3c/6ffa2d9ca81da5d93eb37ac71de936e3a47c214222aa037a0ffc06f64425/grimp-3.20-cp315-cp315-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:41b85c0169ab65e3fe3ed6bc291732d21d1ef192a3eafc40c34b1095dba7d814", size = 2377558, upload-time = "2026-11-13T20:24:51.922Z" }, + { url = "https://files.pythonhosted.org/packages/cd/d1/8ecb14569644dd7d6f419a410d03484ef0cc98ae51f4b39ffe19767b5fdc/grimp-3.20-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:05441560b358a5456225d2e3aafc581001d748146372297153adf4ed49721307", size = 2298121, upload-time = "2026-11-13T20:24:53.362Z" }, + { url = "https://files.pythonhosted.org/packages/13/7b/d8f1e4699b1bc0f7ff81227418bdb1c1ab1438f68fed56baa22153707d0a/grimp-3.20-cp315-cp315-win32.whl", hash = "sha256:50d8a07e0072dd7a65c5641080b2245920369eea1292a68c22ab9d67fb4e4045", size = 1883214, upload-time = "2026-11-13T20:24:54.953Z" }, + { url = "https://files.pythonhosted.org/packages/9e/57/4a5da0798e2991cf4c072a1c12f67107027305d9069f5596e8c615de10e4/grimp-3.20-cp315-cp315-win_amd64.whl", hash = "sha256:82563791b748df48d7f80b3ef65d9c25c24b7acff7507fcbd97f028e7fcc6cdb", size = 2011523, upload-time = "2026-11-13T20:24:56.63Z" }, + { url = "https://files.pythonhosted.org/packages/47/7a/5b3a42198e47b4cf7b64254ae2b76445997c8b9bb64460efabb9a39d3d17/grimp-3.20-cp315-cp315-win_arm64.whl", hash = "sha256:7d185ac1ed79b7fa5ddd7152b4a51c939b5ada823c0a160fea263b33c871d84e", size = 1932832, upload-time = "2026-11-13T20:24:58.052Z" }, + { url = "https://files.pythonhosted.org/packages/22/87/b06306d3148e180f8957761d9518c4e8a85ee958d5c77832ff7542c0483a/grimp-3.20-cp315-cp315t-macosx_10_12_x86_64.whl", hash = "sha256:05fd41fdc55cb6b4067ca3d7f102ccc561af3324662dea2ef8266f2b246c9a7f", size = 2161870, upload-time = "2026-11-13T20:24:59.514Z" }, + { url = "https://files.pythonhosted.org/packages/9e/cf/78245cb2a48b1b2508047b092e3d862ac661ea1da966a79c9f5f20c91942/grimp-3.20-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:d05617879a3e92bd0be3ffdd909a4b45682fb4ca9c414b8b42b79ad35297db25", size = 2104110, upload-time = "2026-11-13T20:25:01.178Z" }, + { url = "https://files.pythonhosted.org/packages/b3/97/c66017e5c99feef43194785c7b1ba9d68502c5375e1af3558743ac75d3d4/grimp-3.20-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:9db891fd3fa21b9a809db1d8f7cd053998ab3e57d21518bd806e47d07f4383f9", size = 2287528, upload-time = "2026-11-13T20:25:03.212Z" }, + { url = "https://files.pythonhosted.org/packages/40/50/66519758f06fc0af69f97d43525b8570332e20bb4731f65a7e1359999370/grimp-3.20-cp315-cp315t-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:2b11f90e86240ded60795668acc130e6a6bb9d4292d7cca260ecb65c2e278f5b", size = 2378368, upload-time = "2026-11-13T20:25:04.934Z" }, + { url = "https://files.pythonhosted.org/packages/5b/da/7445c9e6cef3a17bf8a49d788dd6f4e8df149dc9f5f11faa415243ad3438/grimp-3.20-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c208c8636f13063c31af8b9262decf70266b7d85f63e6205c1df7acf38fe129a", size = 2299333, upload-time = "2026-11-13T20:25:06.424Z" }, + { url = "https://files.pythonhosted.org/packages/a9/b3/529f696cc85229dfddafeddc1e73d2124175dfed26be3ba62d198fcb1cf5/grimp-3.20-cp315-cp315t-win32.whl", hash = "sha256:24f6a94fb4846c0e472f017d1cec1f37bac7b3d901a49a3773ec70c1eebeb5a8", size = 1879498, upload-time = "2026-11-13T20:25:07.893Z" }, + { url = "https://files.pythonhosted.org/packages/ab/fa/d32fd66750f5cedf6b8e03f95248d5e370d66fca294365de8b9f5b47f00c/grimp-3.20-cp315-cp315t-win_amd64.whl", hash = "sha256:efecc5733468189a0a71cd4f1b2c54d9c3b5dcffd1b7630824bbcd7fdc696814", size = 2010658, upload-time = "2026-11-13T20:25:09.386Z" }, + { url = "https://files.pythonhosted.org/packages/13/56/b0d6f23a8a876f31055bb69384ae022564f4704cfa951e6b51a526c2c3c6/grimp-3.20-cp315-cp315t-win_arm64.whl", hash = "sha256:c56f80fdc44ff40a0b3d8bbebe5fbe47a345b237189c108d33d95444df19623a", size = 1931579, upload-time = "2026-11-13T20:25:10.762Z" }, +] + [[package]] name = "grpcio" version = "1.85.0" @@ -2753,6 +2852,20 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/01/f9/575c8d760eae1fc99651b7cc5efd96ad5379ca4d6b53750b0fb4fe983f34/imagesize-2.0.1-py3-none-any.whl", hash = "sha256:ea0c9a0384df69ed86a943a15cde37d0360b82491b3910dc2215e202e62b5b02", size = 14794, upload-time = "2026-08-24T12:35:12.548Z" }, ] +[[package]] +name = "import-linter" +version = "2.16" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "grimp" }, + { name = "rich" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f0/70/ac97afe41a04239a60c9d92fbe593294bf6501309d728af4a400e569d786/import_linter-2.16.tar.gz", hash = "sha256:c5bd0d38bdef46c7251120266b3bf72662bc8cd989a8fe461499936e12e8c6fa", size = 1405978, upload-time = "2026-11-06T13:48:21.617Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e1/f9/0f8a5a9a95c2b3b7e87e7406a2941a5620aeaacc4207155d5010263dabb6/import_linter-2.16-py3-none-any.whl", hash = "sha256:e775602e9214ab3933fc7d2162278ea1f11dd9229c914735c1bda43b94619565", size = 644477, upload-time = "2026-11-06T13:48:20.099Z" }, +] + [[package]] name = "importlib-metadata" version = "10.1.0"