From e8727e81d04c1d10bbec5a65e22d1ca388d94465 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 4 Jun 2024 12:53:27 +0100 Subject: [PATCH 1/2] separate app from main --- src/config_service/__main__.py | 45 ++++++---------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/src/config_service/__main__.py b/src/config_service/__main__.py index f61df3a..b8b6a52 100644 --- a/src/config_service/__main__.py +++ b/src/config_service/__main__.py @@ -1,47 +1,18 @@ from argparse import ArgumentParser -from fastapi import dependencies - from . import __version__ -from .constants import ENDPOINTS try: - import redis - import uvicorn - from dodal.beamlines.beamline_parameters import ( - BEAMLINE_PARAMETER_PATHS, - GDABeamlineParameters, - ) - from fastapi import FastAPI - - app = FastAPI() - valkey = redis.Redis(host="localhost", port=6379, decode_responses=True) + import redis # noqa + import uvicorn # noqa + from fastapi import FastAPI # noqa server_dependencies_exist = True except ImportError: server_dependencies_exist = False -__all__ = ["main"] - -BEAMLINE_PARAM_PATH = "" -BEAMLINE_PARAMS: GDABeamlineParameters | None = None - - -@app.get(ENDPOINTS.BL_PARAM + "{item_id}") -def beamlineparameter(item_id: str): - assert BEAMLINE_PARAMS is not None - return {item_id: BEAMLINE_PARAMS.params.get(item_id)} - -@app.post(ENDPOINTS.FEATURE + "{item_id}") -def set_featureflag(item_id: str, value: bool): - return {"success": valkey.set(item_id, int(value))} - - -@app.get(ENDPOINTS.FEATURE + "{item_id}") -def get_featureflag(item_id: str): - ret = int(valkey.get(item_id)) # type: ignore - return {item_id: bool(ret) if ret is not None else None, "raw": ret} +__all__ = ["main"] def main(): @@ -57,12 +28,10 @@ def main(): "importing the client, you must install this package with [server] " "optional dependencies" ) - if args.dev: - BEAMLINE_PARAM_PATH = "tests/test_data/beamline_parameters.txt" else: - BEAMLINE_PARAM_PATH = BEAMLINE_PARAMETER_PATHS["i03"] - BEAMLINE_PARAMS = GDABeamlineParameters.from_file(BEAMLINE_PARAM_PATH) - uvicorn.run(app="config_service.__main__:app", host="0.0.0.0", port=8555) + from .app import main + + main(args) # test with: python -m config_service From dfd132048ada89304bc3d1dfa11bd7691b78cfcb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:00:03 +0000 Subject: [PATCH 2/2] Bump dls-dodal from 1.25.0 to 1.26.0 in the dev-dependencies group Bumps the dev-dependencies group with 1 update: [dls-dodal](https://github.com/DiamondLightSource/dodal). Updates `dls-dodal` from 1.25.0 to 1.26.0 - [Release notes](https://github.com/DiamondLightSource/dodal/releases) - [Commits](https://github.com/DiamondLightSource/dodal/compare/1.25.0...1.26.0) --- updated-dependencies: - dependency-name: dls-dodal dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dev-dependencies ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9271124..1400e75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ readme = "README.md" requires-python = ">=3.7" [project.optional-dependencies] -server = ["fastapi", "redis", "hiredis", "dls-dodal==1.25.0"] +server = ["fastapi", "redis", "hiredis", "dls-dodal==1.26.0"] dev = [ "copier", "pipdeptree",