Skip to content

Commit 2da1ffd

Browse files
committed
Update docs
1 parent fbc6b3f commit 2da1ffd

File tree

7 files changed

+22
-37
lines changed

7 files changed

+22
-37
lines changed

docs/how-to/config-server-guide.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ You can then make a request through this client through its `get_file_contents`
1515
```python
1616
config_server.get_file_contents(FILE_PATH,reset_cached_result=True)
1717
```
18-
By default, this will return the file's raw string output - which includes things like linebreaks. It is up to you to format this output - using `splitlines()` will get you a list where each item is a line in the file. `get_file_contents` has a `desired_return_type` parameter where you can instead ask for a `dict` or `bytes`. The server will try and do the conversion, and respond with an HTTP error if the requested file is incompatible with that type.
18+
By default, this will return the file's raw string output - which includes things like linebreaks. It is up to you to format this output - using `splitlines()` will get you a list where each item is a line in the file. `get_file_contents` has a `desired_return_type` parameter where you can instead ask for a `dict`, `bytes` or a `pydantic model`. The server will try and do the conversion, and respond with an HTTP error if the requested file is incompatible with that type, or a pydantic validation error if the data cannot be converted to the pydantic model provided. Custom [file converters](#file-converters) can be used to specify how a file should be converted to a dict or pydantic model.
19+
20+
# File converters
21+
22+
Converters can be used to turn a file into a standard format server-side, reducing the complexity of reading config files client-side. Converters can convert config files to a `dict` or `pydantic model`, and the same `pydantic model` can be reconstructed client-side by the `get_file_contents` method. Available converters exist [here](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._converters.py) - see if there's a suitable converter you can use before adding your own. [This dictionary](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._file_converter_map.py) maps files to converters. Add the path of your config file and a suitable converter to this dictionary and it will automatically be used by the config server when a request for that file is made.
23+
24+
A request for `str` or `bytes` will fetch the raw file with no conversion.
1925

2026
# Adding files to the whitelist
2127

@@ -24,9 +30,3 @@ For [security reasons](../explanations/whitelist_info.md), only files existing o
2430
# Reading sensitive information
2531

2632
If you need to read a file which contains sensitive information, or `dls-dasc` doesn't have the permissions to read your file, you should encrypt this file as a [sealed secret](https://github.com/bitnami-labs/sealed-secrets) on your beamline cluster, and mount this in your BlueAPI service.
27-
28-
# File converters
29-
30-
Converters can be used to turn a file into a standard format server-side, reducing the complexity of reading config files client-side. Available converters exist [here](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._converters.py) - see if there's a suitable converter you can use before adding your own. [This dictionary](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._file_converter_map.py) maps files to converters. Add the path of your config file and a suitable converter to this dictionary and it will automatically be used by the config server when a request for that file is made.
31-
32-
A request for `str` or `bytes` will fetch the raw file with no conversion.

docs/reference/current_and_planned_features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- Periodically check the main branch's to update the whitelist.
77
- Provide a client module for users to easily communicate with the server, with caching.
88
- Have this service hosted on diamond's central argus cluster - with url `https://daq-config-server.diamond.ac.uk`
9-
- Provide server-side formatting for commonly used configuration files - eg `beamline_parameters.txt` should be returned as a dictionary.
9+
- Provide server-side json and pydantic model formatting for commonly used configuration files - eg `beamline_parameters.txt` should be returned as a dictionary.
1010

1111

1212
## Future features

src/daq_config_server/converters/_converter_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def parse_value(value: str, convert_to: type | None = None) -> Any:
2828

2929

3030
def parse_lut(contents: str, *params: tuple[str, type | None]) -> GenericLut:
31-
"""Converts a lookup table to a dict, containing the names of each column and
32-
the rows as a 2D list.
31+
"""Converts a lookup table to a pydantic model, containing the names of each column
32+
and the rows as a 2D list.
3333
3434
Any args after the contents provide the column names and optionally, python types
3535
for values in a column to be converted to. e.g: (energy_EV, float), (pixels, int).

src/daq_config_server/converters/_converters.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,7 @@ def beamline_parameters_to_dict(contents: str) -> dict[str, Any]:
3535
return dict(config_pairs)
3636

3737

38-
def display_config_to_dict(contents: str) -> DisplayConfig:
39-
"""Converts a display config file into a dict. Every zoom level entry in the
40-
configuration file forms a key in the dict, with value being another dict. This
41-
inner dict contains all the key value pairs of the rows following each zoom level.
42-
43-
Example input:
44-
45-
zoomLevel = 1.0
46-
crosshairX = 500
47-
crosshairY = 600
48-
zoomLevel = 2.0
49-
crosshairX = 700
50-
crosshairY = 800
51-
52-
Example output:
53-
"""
38+
def display_config_to_model(contents: str) -> DisplayConfig:
5439
lines = contents.splitlines()
5540
config_dict: dict[float, dict[str, int | float]] = {}
5641
zoom_level = None

src/daq_config_server/converters/_file_converter_map.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
beamline_pitch_lut,
99
beamline_roll_lut,
1010
detector_xy_lut,
11-
display_config_to_dict,
11+
display_config_to_model,
1212
undulator_energy_gap_lut,
1313
xml_to_dict,
1414
)
1515

1616
FILE_TO_CONVERTER_MAP: dict[str, Callable[[str], BaseModel | dict[str, Any]]] = { # type: ignore
1717
"/tests/test_data/test_good_lut.txt": undulator_energy_gap_lut, # For system tests # noqa
18-
"/dls_sw/i23/software/aithre/aithre_display.configuration": display_config_to_dict,
19-
"/dls_sw/i03/software/gda_versions/var/display.configuration": display_config_to_dict, # noqa
20-
"/dls_sw/i04/software/bluesky/scratch/display.configuration": display_config_to_dict, # noqa
21-
"/dls_sw/i19-1/software/daq_configuration/domain/display.configuration": display_config_to_dict, # noqa
22-
"/dls_sw/i24/software/gda_versions/var/display.configuration": display_config_to_dict, # noqa
18+
"/dls_sw/i23/software/aithre/aithre_display.configuration": display_config_to_model,
19+
"/dls_sw/i03/software/gda_versions/var/display.configuration": display_config_to_model, # noqa
20+
"/dls_sw/i04/software/bluesky/scratch/display.configuration": display_config_to_model, # noqa
21+
"/dls_sw/i19-1/software/daq_configuration/domain/display.configuration": display_config_to_model, # noqa
22+
"/dls_sw/i24/software/gda_versions/var/display.configuration": display_config_to_model, # noqa
2323
"/dls_sw/i03/software/gda/configurations/i03-config/xml/jCameraManZoomLevels.xml": xml_to_dict, # noqa
2424
"/dls_sw/i04/software/bluesky/scratch/jCameraManZoomLevels.xml": xml_to_dict,
2525
"/dls_sw/i19-1/software/gda_versions/gda/config/xml/jCameraManZoomLevels.xml": xml_to_dict, # noqa

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from daq_config_server.converters._converters import (
88
beamline_parameters_to_dict,
9-
display_config_to_dict,
9+
display_config_to_model,
1010
undulator_energy_gap_lut,
1111
xml_to_dict,
1212
)
@@ -23,7 +23,7 @@ def mock_file_converter_map() -> Generator[dict[str, Callable[[str], Any]], None
2323
TestDataPaths.TEST_BEAMLINE_PARAMETERS_PATH
2424
): beamline_parameters_to_dict,
2525
str(TestDataPaths.TEST_GOOD_LUT_PATH): undulator_energy_gap_lut,
26-
str(TestDataPaths.TEST_GOOD_DISPLAY_CONFIG_PATH): display_config_to_dict,
26+
str(TestDataPaths.TEST_GOOD_DISPLAY_CONFIG_PATH): display_config_to_model,
2727
str(ServerFilePaths.GOOD_LUT): undulator_energy_gap_lut,
2828
},
2929
) as mock_map:

tests/unit_tests/test_converters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
beamline_pitch_lut,
1717
beamline_roll_lut,
1818
detector_xy_lut,
19-
display_config_to_dict,
19+
display_config_to_model,
2020
undulator_energy_gap_lut,
2121
xml_to_dict,
2222
)
@@ -87,7 +87,7 @@ def test_lut_with_different_number_of_row_items_to_column_names_causes_error():
8787
GenericLut(column_names=["column1", "column2"], rows=[[1, 2], [1, 2, 3]])
8888

8989

90-
def test_display_config_to_dict_gives_expected_result_and_can_be_jsonified():
90+
def test_display_config_to_model_gives_expected_result_and_can_be_jsonified():
9191
with open(TestDataPaths.TEST_GOOD_DISPLAY_CONFIG_PATH) as f:
9292
contents = f.read()
9393
expected = DisplayConfig(
@@ -110,7 +110,7 @@ def test_display_config_to_dict_gives_expected_result_and_can_be_jsonified():
110110
),
111111
}
112112
)
113-
result = display_config_to_dict(contents)
113+
result = display_config_to_model(contents)
114114
assert result == expected
115115
json.dumps(result.model_dump())
116116

0 commit comments

Comments
 (0)