-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from simonsobs/koopman/config-file
Create sorunlib yaml config file
- Loading branch information
Showing
7 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Configuration | ||
============= | ||
|
||
sorunlib tries to automatically determine as much about the OCS network as it | ||
can, however some things still require configuration. This page details the | ||
sorunlib configuration file. | ||
|
||
.. note:: | ||
This format is still under development and might change. Check back here if | ||
in doubt of formatting. | ||
|
||
Example | ||
------- | ||
|
||
A full configuration file example with comments is shown here: | ||
|
||
.. code-block:: yaml | ||
--- | ||
# sorunlib configuration | ||
# agents | ||
# sorunlib automatically detects unique agents on the OCS network, so only | ||
# non-unique agents need to be specified here. | ||
# ocs registry agent | ||
registry: 'registry' | ||
Configuration Selection | ||
----------------------- | ||
|
||
Select the configuration file to load by setting the ``SORUNLIB_CONFIG`` | ||
environment variable: | ||
|
||
.. code-block:: bash | ||
$ export SORUNLIB_CONFIG=/path/to/sorunlib/config.yaml | ||
In practice, sorunlib is typically run within a Docker container, so it's quite | ||
natural to set this in a compose file. The following example uses the | ||
``so-daq-sequencer`` image: | ||
|
||
.. code-block:: yaml | ||
sequencer-backend: | ||
image: ghcr.io/simonsobs/so-daq-sequencer:latest | ||
restart: always | ||
container_name: sequencer-backend | ||
environment: | ||
- OCS_CONFIG_DIR=/path/to/ocs/config/ | ||
- SORUNLIB_CONFIG=/path/to/sorunlib/config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ platform. | |
:caption: Documentation | ||
|
||
design | ||
configuration | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
import yaml | ||
|
||
|
||
def load_config(filename=None): | ||
"""Load sorunlib config file, using SORUNLIB_CONFIG by default. | ||
Args: | ||
filename (str): Path to sorunlib config file | ||
Returns: | ||
dict | ||
""" | ||
if filename is None: | ||
assert (os.getenv('SORUNLIB_CONFIG') is not None) | ||
filename = os.getenv('SORUNLIB_CONFIG') | ||
|
||
with open(filename, 'rb') as f: | ||
return yaml.safe_load(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
registry: 'registry' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
os.environ["OCS_CONFIG_DIR"] = "./test_util/" | ||
os.environ["SORUNLIB_CONFIG"] = "./data/example_config.yaml" | ||
|
||
from sorunlib.config import load_config | ||
|
||
|
||
def test_load_config(): | ||
cfg = load_config("./data/example_config.yaml") | ||
assert cfg == {'registry': 'registry'} | ||
|
||
|
||
def test_load_config_from_env(): | ||
cfg = load_config() | ||
assert cfg == {'registry': 'registry'} |