From 42afdd7e96b41500d7e88d0c44c9861547bebe80 Mon Sep 17 00:00:00 2001 From: Peter Chang Date: Thu, 3 Sep 2026 11:12:12 +0100 Subject: [PATCH] Minor fixes Use ruff import sorting and clean up code Update to python 3.11, pydantic 2.11.0, and httpx2. Update some workflow actions. Fix setting selections, fix package exports, set line width to 1 if undefined otherwise line is not visible, allow connected plots to have no toolbar and tight axes, use json argument in request for stricter content type in FastAPI that broke benchmark script, update from populate_by_name, use auto enums in benchmarks, update react-draggable and remove workarounds, make example client a functional component, add restrictions in component README Finally update davidia packages version --- .github/workflows/python-package.yml | 4 +- client/component/README.md | 4 + client/component/package.json | 10 +- client/component/src/AspectConfigModal.tsx | 2 +- client/component/src/ConnectedPlot.tsx | 21 +- client/component/src/LinePlot.tsx | 2 +- client/component/src/Modal.tsx | 1 - client/component/src/Modeless.tsx | 1 - .../src/PlotCustomizationContext.tsx | 4 +- client/example/package.json | 2 +- client/example/src/App.tsx | 451 ++++++++---------- client/example/vite.config.ts | 1 - environment.yml | 5 +- package.json | 2 +- pnpm-lock.yaml | 11 +- server/davidia/__init__.py | 2 +- server/davidia/main.py | 10 +- server/davidia/models/messages.py | 8 +- server/davidia/models/parameters.py | 17 +- server/davidia/models/selections.py | 10 +- server/davidia/plot.py | 68 +-- server/davidia/server/benchmarks.py | 65 +-- server/davidia/server/fastapi_utils.py | 27 +- server/davidia/server/plotserver.py | 56 ++- server/davidia/tests/test_api.py | 278 +++++------ server/davidia/tests/test_messages.py | 8 +- server/davidia/tests/test_plotserver.py | 18 +- server/davidia/tests/test_selections.py | 3 +- server/demos/benchmark.py | 7 +- server/demos/simple.py | 10 +- server/example-client/pyproject.toml | 8 +- server/pyproject.toml | 8 +- 32 files changed, 575 insertions(+), 549 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 1dc588d3..eaac77b0 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -67,7 +67,7 @@ jobs: pipx run build server pipx run build server/example-client --outdir server/dist - name: Upload sdist and wheel as artifacts - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@v7 with: name: dist path: server/dist @@ -88,7 +88,7 @@ jobs: steps: # Download sdist and wheel from dist job - - uses: actions/download-artifact@v7 + - uses: actions/download-artifact@v8 with: path: dist # Publish to PyPI using trusted publishing diff --git a/client/component/README.md b/client/component/README.md index 9badcd71..28c35ef6 100644 --- a/client/component/README.md +++ b/client/component/README.md @@ -4,10 +4,14 @@ View the frontend Typescript documentation [here](https://diamondlightsource.git ## Installation +Currently, only React 18 is supported. + ### `pnpm add @diamondlightsource/davidia` ## Vite configuration +Use `vite < 8` in your devDependencies. + Some davidia dependencies require a global object to be defined when used in Vite applications. Add the following to your vite.config.ts: ```js diff --git a/client/component/package.json b/client/component/package.json index e2c95ac8..39d79788 100644 --- a/client/component/package.json +++ b/client/component/package.json @@ -6,7 +6,7 @@ "url": "git+https://github.com/DiamondLightSource/davidia.git" }, "private": false, - "version": "1.1.0", + "version": "1.2.0", "type": "module", "scripts": { "build": "tsc && vite build", @@ -23,8 +23,10 @@ }, "publishConfig": { "exports": { - ".": "./dist/index.js", - "types": "./dist/index.d.ts", + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, "./index.css": "./dist/index.css" } }, @@ -43,7 +45,7 @@ "ndarray-tile": "^1.0.3", "ndarray-unsqueeze": "^1.0.3", "react-colorful": "^5.8.0", - "react-draggable": "^4.7.0", + "react-draggable": "^4.7.1", "react-icons": "^5.7.0", "react-select": "^5.10.2", "react-use-websocket": "^4.13.0", diff --git a/client/component/src/AspectConfigModal.tsx b/client/component/src/AspectConfigModal.tsx index 9063c445..a82ab453 100644 --- a/client/component/src/AspectConfigModal.tsx +++ b/client/component/src/AspectConfigModal.tsx @@ -33,8 +33,8 @@ function AspectConfigModal(props: PropsWithChildren) { const [aspectRatio, setAspectRatio] = useState(2.0); const initType = getAspectType(initAspect); - console.log('Set initial type', props); if (initType != aspectType) { + console.log('Set initial type', props); setAspectType(initType); if (initType === 'number') { setAspectRatio(initAspect as number); diff --git a/client/component/src/ConnectedPlot.tsx b/client/component/src/ConnectedPlot.tsx index 8c5c8d17..2e1afc0a 100644 --- a/client/component/src/ConnectedPlot.tsx +++ b/client/component/src/ConnectedPlot.tsx @@ -226,6 +226,16 @@ interface ConnectedPlotProps { port?: string; /** The universally unique identifier */ uuid: string; + /** + * If enabled, forces the plot to shrink or expand to keep the image flush with the axes. + * Has no effect if the aspect is not equal. + */ + tightAxes?: boolean; + /** + * Children to customize the toolbar. If undefined then use default toolbar, if null, disable toolbar, + * otherwise use given children + */ + customToolbarChildren?: React.ReactNode; } /** @@ -239,6 +249,8 @@ function ConnectedPlot({ hostname = '127.0.0.1', port = '80', uuid, + tightAxes = false, + customToolbarChildren = undefined, }: ConnectedPlotProps) { const [plotProps, setPlotProps] = useState(); const [lineData, setLineData] = useState([]); @@ -648,7 +660,14 @@ function ConnectedPlot({ let currentProps = plotProps; if (currentProps) { - currentProps = { ...currentProps, batonProps, updateSelection, selections }; + currentProps = { + ...currentProps, + batonProps, + updateSelection, + selections, + tightAxes, + customToolbarChildren, + }; } if (currentProps) { diff --git a/client/component/src/LinePlot.tsx b/client/component/src/LinePlot.tsx index 66ebf263..249d8fba 100644 --- a/client/component/src/LinePlot.tsx +++ b/client/component/src/LinePlot.tsx @@ -120,7 +120,7 @@ function createDataCurve( curveType={curveType} glyphType={p.glyphType ?? GlyphType.Circle} glyphSize={p.pointSize} - width={p.width} + width={p.width ?? 1} visible={visible} /> ); diff --git a/client/component/src/Modal.tsx b/client/component/src/Modal.tsx index 969d199c..9d2fe3cc 100644 --- a/client/component/src/Modal.tsx +++ b/client/component/src/Modal.tsx @@ -67,7 +67,6 @@ function Modal(props: PropsWithChildren) { {!toggleHidden && toggle} {showModal && props.children && ( - /* @ts-expect-error see https://github.com/react-grid-layout/react-draggable/issues/807, fix post 4.7.0 */