Skip to content

Commit 3ac7467

Browse files
committed
Set data transfer and data processing to False by default; set rsync basepath to / by default; added Config class to MachineConfig model
1 parent 4e77371 commit 3ac7467

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/murfey/util/config.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@
88

99
import yaml
1010
from backports.entry_points_selectable import entry_points
11-
from pydantic import BaseModel, BaseSettings, Extra, Field, root_validator, validator
11+
from pydantic import (
12+
BaseConfig,
13+
BaseModel,
14+
BaseSettings,
15+
Extra,
16+
Field,
17+
root_validator,
18+
validator,
19+
)
1220
from pydantic.errors import NoneIsNotAllowedError
1321

1422

15-
class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
23+
class MachineConfig(BaseModel):
1624
"""
1725
General information about the instrument being supported
1826
"""
@@ -167,19 +175,18 @@ class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
167175
"""
168176
# rsync-related settings (only if rsync is used)
169177
data_transfer_enabled: bool = Field(
170-
default=True,
178+
default=False,
171179
description=("Toggle whether to enable data transfer via rsync."),
172180
# NOTE: Only request input for this code block if data transfer is enabled
173181
)
174-
allow_removal: bool = Field(
175-
default=False, description="Allow original files to be removed after rsync."
176-
)
177-
rsync_basepath: Optional[Path] = Field(
178-
default=None,
182+
rsync_basepath: Path = Field(
183+
default=Path("/"),
179184
description=(
180185
"Full path on the storage server that the rsync daemon will append the "
181186
"relative paths of the transferred files to."
182187
),
188+
# If rsync is disabled, rsync_basepath works out to be "/".
189+
# Must always be set.
183190
)
184191
rsync_module: Optional[str] = Field(
185192
default=None,
@@ -191,6 +198,9 @@ class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
191198
"different sub-folders to save the data to."
192199
),
193200
)
201+
allow_removal: bool = Field(
202+
default=False, description="Allow original files to be removed after rsync."
203+
)
194204

195205
# Related visits and data
196206
upstream_data_directories: list[Path] = Field(
@@ -223,7 +233,7 @@ class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
223233
"""
224234
# Processing-related keys
225235
processing_enabled: bool = Field(
226-
default=True,
236+
default=False,
227237
description="Toggle whether to enable data processing.",
228238
# NOTE: Only request input for this code block if processing is enabled
229239
)
@@ -389,8 +399,16 @@ class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
389399
),
390400
)
391401

402+
class Config(BaseConfig):
403+
"""
404+
Additional settings for how this Pydantic model behaves
405+
"""
406+
407+
extra = Extra.allow
408+
json_encoders = {Path: str}
409+
392410
@validator("camera", always=True, pre=True)
393-
def _validate_camera_model(cls, value: str):
411+
def __validate_camera_model__(cls, value: str):
394412
# Let non-strings fail validation naturally
395413
if not isinstance(value, str):
396414
return value
@@ -411,7 +429,7 @@ def _validate_camera_model(cls, value: str):
411429
)
412430

413431
@root_validator(pre=False)
414-
def _validate_superres(cls, model: dict):
432+
def __validate_superres__(cls, model: dict):
415433
camera: str = model.get("camera", "")
416434
model["superres"] = True if camera.startswith("K3") else False
417435
return model
@@ -420,6 +438,9 @@ def _validate_superres(cls, model: dict):
420438
def __validate_rsync_basepath_if_transfer_enabled__(
421439
cls, v: Optional[str], values: Mapping[str, Any]
422440
) -> Any:
441+
"""
442+
If data transfer is enabled, an rsync basepath must be provided.
443+
"""
423444
if values.get("data_transfer_enabled"):
424445
if v is None:
425446
raise NoneIsNotAllowedError
@@ -429,6 +450,9 @@ def __validate_rsync_basepath_if_transfer_enabled__(
429450
def __validate_default_model_if_processing_enabled_and_spa_possible__(
430451
cls, v: Optional[str], values: Mapping[str, Any]
431452
) -> Any:
453+
"""
454+
If data processing is enabled, a machine learning model must be provided.
455+
"""
432456
if values.get("processing_enabled") and "epu" in values.get(
433457
"acquisition_software", []
434458
):

0 commit comments

Comments
 (0)