Skip to content

Commit 5e04cde

Browse files
authored
Merge branch 'main' into bes/xrd_insitu_block_pre_rebase
2 parents a4dc9eb + 18ee71c commit 5e04cde

File tree

31 files changed

+1478
-1050
lines changed

31 files changed

+1478
-1050
lines changed

.docker/server_dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# syntax=docker/dockerfile:1
1+
ARG UV_VERSION="0.8.4"
2+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_image
3+
24
FROM python:3.10 AS api
35
SHELL ["/bin/bash", "--login", "-c"]
46

@@ -12,7 +14,7 @@ RUN apt update && apt install -y gnupg curl tree mdbtools && apt clean
1214
WORKDIR /opt
1315
RUN wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.9.0.deb && apt install ./mongodb-database-tools-*-100.9.0.deb
1416

15-
COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /usr/local/bin/uv
17+
COPY --from=uv_image /uv /usr/local/bin/uv
1618
ENV UV_LINK_MODE=copy \
1719
UV_COMPILE_BYTECODE=1 \
1820
UV_PYTHON_DOWNLOADS=never \

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: CI tests
22
on:
33
pull_request:
4-
types: [ready_for_review, opened, synchronize, reopened]
54

65
push:
76
branches:
87
- main
98

109
env:
1110
FORCE_COLOR: true
11+
UV_VERSION: "0.8.4"
1212

1313
concurrency:
1414
group: ${{ github.head_ref || github.run_id }}
@@ -30,7 +30,7 @@ jobs:
3030
- name: Set up uv
3131
uses: astral-sh/setup-uv@v6
3232
with:
33-
version: "0.6.4"
33+
version: ${{ env.UV_VERSION }}
3434
enable-cache: true
3535

3636
- name: Install dependencies
@@ -78,7 +78,7 @@ jobs:
7878
- name: Set up uv
7979
uses: astral-sh/setup-uv@v6
8080
with:
81-
version: "0.6.4"
81+
version: ${{ env.UV_VERSION }}
8282
working-directory: "./pydatalab"
8383
enable-cache: true
8484

INSTALL.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ You will need Python 3.10 or higher to run *datalab*; we recommend using a tool
4747
##### Installation with `uv` or `venv`
4848

4949
We recommend using [`uv`](https://github.com/astral-sh/uv) (see the linked repository or https://docs.astral.sh/uv for installation instructions) for managing your *datalab* installation.
50-
This is still a fledgling tool that is supporting a wider subset of features each day; for now, we recommend using the version pinned in our `.docker/server_dockerfile`, otherwise you may need to regenerate the `uv.lock` file locally (please do not commit this file).
51-
5250

5351
You could also use the standard library `venv` module, but this will not allow you to install pinned dependencies as easily, and is significantly slower than `uv`.
5452

pydatalab/docs/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ nav:
55
- config.md
66
- schemas
77
- blocks
8+
- plugins.md
89
- CHANGELOG.md

pydatalab/docs/blocks/index.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Overview
2+
3+
*datalab*'s block system provides a modular approach to data processing and visualization.
4+
Each block type is a specialized component that handles specific kinds of data and operations, making it easy to extend the system's capabilities without modifying the core architecture.
5+
Typically, a given technique (e.g., XRD, NMR) will have its own block.
6+
Blocks can be implemented either in the main package, or as a plugin (see ["Plugins"](/plugins)).
7+
8+
Data blocks are modular components that:
9+
10+
1. Process specific file types and data formats for a technique or set of techniques,
11+
2. Generate visualizations and plots from this data to be shown in the UI,
12+
3. Store and manage their own state persistently in a database,
13+
4. Can be attached to individual items or collections in your data management system,
14+
5. Provide a mechanism for handling "events" through a decorator-based registration system,
15+
6. Expose a consistent API for creation, updating, and deletion.
16+
7. Handle logging, errors and warnings in a consistent way to show in the UI.
17+
18+
## Block Lifecycle
19+
20+
1. **Creation**: Blocks are instantiated with an item or collection ID
21+
2. **Initialization**: Initial state is set up, potentially including file data and defaults
22+
3. **Processing**: Data is processed, plots are generated, and state is updated
23+
4. **Serialization**: Block state is serialized for storage or transmission
24+
5. **Update**: Blocks can receive updates from the web interface
25+
6. **Deletion**: Blocks can be removed from items or collections
26+
27+
28+
## Web API
29+
30+
The block system exposes several API endpoints:
31+
32+
- `/add-data-block/`: Create and add a new block to an item
33+
- `/add-collection-data-block/`: Create and add a new block to a collection
34+
- `/update-block/`: Update an existing block's state
35+
- `/delete-block/`: Remove a block from an item
36+
- `/delete-collection-block/`: Remove a block from a collection
37+
38+
## Creating a new block
39+
40+
To create a new block type:
41+
42+
1. Create a class that inherits from `DataBlock`
43+
2. Define the accepted file extensions and block metadata (descriptions will be used to populate the UI documentation automatically)-
44+
3. Implement data processing and visualization methods, with e.g., JSON-serialized Bokeh plots stored in the `self.data["bokeh_plot_data"]` attribute
45+
4. Any data to be stored in the database can be defined in the `self.data` attribute
46+
5. Register any event handlers using the `@event` decorator
47+
5. Add the block type to the `BLOCK_TYPES` registry
48+
49+
By default, a generic UI component will be used in the *datalab* interface that
50+
will make use of titles, descriptions, accepted file extensions to render a
51+
simple user interface for the block.
52+
When the user loads the block in the UI, the block's `plot_functions` methods
53+
will be called in turn, which will either load from scratch, or load cached data
54+
for that block.
55+
If a JSON-serialized Bokeh plot is found in the block's data, this will be
56+
rendered in the UI.
57+
58+
## Event system
59+
60+
The event system allows external functions to be called by name, enabling clean interaction between the frontend and server-side block functionality.
61+
This is a new feature and this documentation will evolve alongside it.
62+
63+
Currently, the event system allows:
64+
65+
- Registration of event handlers in Python via the `@event` decorator
66+
- Access to available events at both class and instance levels
67+
- Runtime dispatch of events based on name
68+
- Support for event parameters passed as keyword arguments
69+
- Events can then be triggered by the front-end; for example, a Bokeh-based block can trigger an event in a Bokeh callback using the [`CustomEvent`](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent) API, for example:
70+
```javascript
71+
const event = new CustomEvent("block-event", {
72+
detail: {
73+
block_id: '<block_id>',
74+
event_name: '<event_name>',
75+
state_data: '<some data>',
76+
},
77+
bubbles: true
78+
});
79+
document.dispatchEvent(event);
80+
```
81+
The base data block (`DataBlockBase.vue`) will listen for such events registered as `'block-event'` and pass them to the appropriate server-side block.
82+
An example callback generator for an event consisting of a single parameter
83+
update can be found at [`generate_js_callback_single_float_parameter`][pydatalab.blocks.base.generate_js_callback_single_float_parameter].
84+
85+
## Future Directions
86+
87+
Future updates to the block system will focus on:
88+
89+
- Reducing boilerplate code required for new block types.
90+
- Enhanced automatic caching after block creation.
91+
- Improving the event system to enable richer UI interactions, e.g,. setting user parameters or controlling default plot styles.
92+
- Providing better support for custom user interfaces (i.e., allowing plugins to also specify custom Vue code).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: Reference
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)