Skip to content

Commit a3bd84b

Browse files
committed
Rename 'name templates' to 'validation templates'.
1 parent aebbb5c commit a3bd84b

19 files changed

+196
-181
lines changed

datashuttle/configs/canonical_configs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ def get_tui_config_defaults() -> Dict:
306306
return settings
307307

308308

309-
def get_name_templates_defaults() -> Dict:
310-
"""Return the default values for name_templates."""
311-
return {"name_templates": {"on": False, "sub": None, "ses": None}}
309+
def get_validation_templates_defaults() -> Dict:
310+
"""Return the default values for validation_templates."""
311+
return {"validation_templates": {"on": False, "sub": None, "ses": None}}
312312

313313

314314
def get_persistent_settings_defaults() -> Dict:
@@ -320,7 +320,7 @@ def get_persistent_settings_defaults() -> Dict:
320320
"""
321321
settings = {}
322322
settings.update(get_tui_config_defaults())
323-
settings.update(get_name_templates_defaults())
323+
settings.update(get_validation_templates_defaults())
324324

325325
return settings
326326

datashuttle/datashuttle_class.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ def create_folders(
209209
utils.log("\nFormatting Names...")
210210
ds_logger.log_names(["sub_names", "ses_names"], [sub_names, ses_names])
211211

212-
name_templates = self.get_name_templates()
212+
validation_templates = self.get_validation_templates()
213213

214214
format_sub, format_ses = self._format_and_validate_names(
215215
top_level_folder,
216216
sub_names,
217217
ses_names,
218-
name_templates,
218+
validation_templates,
219219
bypass_validation,
220220
log=True,
221221
)
@@ -251,18 +251,18 @@ def _format_and_validate_names(
251251
top_level_folder: TopLevelFolder,
252252
sub_names: Union[str, List[str]],
253253
ses_names: Optional[Union[str, List[str]]],
254-
name_templates: Dict,
254+
validation_templates: Dict,
255255
bypass_validation: bool,
256256
log: bool = True,
257257
) -> Tuple[List[str], List[str]]:
258258
"""Central method to format and validate subject and session names."""
259259
format_sub = formatting.check_and_format_names(
260-
sub_names, "sub", name_templates, bypass_validation
260+
sub_names, "sub", validation_templates, bypass_validation
261261
)
262262

263263
if ses_names is not None:
264264
format_ses = formatting.check_and_format_names(
265-
ses_names, "ses", name_templates, bypass_validation
265+
ses_names, "ses", validation_templates, bypass_validation
266266
)
267267
else:
268268
format_ses = []
@@ -276,7 +276,7 @@ def _format_and_validate_names(
276276
include_central=False,
277277
display_mode="error",
278278
log=log,
279-
name_templates=name_templates,
279+
validation_templates=validation_templates,
280280
)
281281

282282
return format_sub, format_ses
@@ -1147,9 +1147,9 @@ def get_next_sub(
11471147
The next subject ID.
11481148
11491149
"""
1150-
name_template = self.get_name_templates()
1151-
name_template_regexp = (
1152-
name_template["sub"] if name_template["on"] else None
1150+
validation_template = self.get_validation_templates()
1151+
validation_template_regexp = (
1152+
validation_template["sub"] if validation_template["on"] else None
11531153
)
11541154

11551155
if self.is_local_project():
@@ -1162,7 +1162,7 @@ def get_next_sub(
11621162
include_central=include_central,
11631163
return_with_prefix=return_with_prefix,
11641164
search_str="sub-*",
1165-
name_template_regexp=name_template_regexp,
1165+
validation_template_regexp=validation_template_regexp,
11661166
)
11671167

11681168
@check_configs_set
@@ -1196,9 +1196,9 @@ def get_next_ses(
11961196
The next session ID.
11971197
11981198
"""
1199-
name_template = self.get_name_templates()
1200-
name_template_regexp = (
1201-
name_template["ses"] if name_template["on"] else None
1199+
validation_template = self.get_validation_templates()
1200+
validation_template_regexp = (
1201+
validation_template["ses"] if validation_template["on"] else None
12021202
)
12031203

12041204
if self.is_local_project():
@@ -1211,7 +1211,7 @@ def get_next_ses(
12111211
include_central=include_central,
12121212
return_with_prefix=return_with_prefix,
12131213
search_str="ses-*",
1214-
name_template_regexp=name_template_regexp,
1214+
validation_template_regexp=validation_template_regexp,
12151215
)
12161216

12171217
@check_configs_set
@@ -1226,36 +1226,38 @@ def is_local_project(self) -> bool:
12261226
# Name Templates
12271227
# -------------------------------------------------------------------------
12281228

1229-
def get_name_templates(self) -> Dict:
1229+
def get_validation_templates(self) -> Dict:
12301230
"""Return the regexp templates used for validation.
12311231
12321232
If the "on" key is set to `False`, template validation is not performed.
12331233
12341234
Returns
12351235
-------
1236-
name_templates
1237-
e.g. {"name_templates": {"on": False, "sub": None, "ses": None}}
1236+
validation_templates
1237+
e.g. {"validation_templates": {"on": False, "sub": None, "ses": None}}
12381238
12391239
"""
12401240
settings = self._load_persistent_settings()
1241-
return settings["name_templates"]
1241+
return settings["validation_templates"]
12421242

1243-
def set_name_templates(self, new_name_templates: Dict) -> None:
1243+
def set_validation_templates(self, new_validation_templates: Dict) -> None:
12441244
"""Update the persistent settings with new name templates.
12451245
1246-
Name templates are regexp for that, when ``name_templates["on"]`` is
1246+
Name templates are regexp for that, when ``validation_templates["on"]`` is
12471247
set to ``True``, ``"sub"`` and ``"ses"`` names are validated against
12481248
the regexp contained in the dict.
12491249
12501250
Parameters
12511251
----------
1252-
new_name_templates
1253-
e.g. ``{"name_templates": {"on": False, "sub": None, "ses": None}}``
1252+
new_validation_templates
1253+
e.g. ``{"validation_templates": {"on": False, "sub": None, "ses": None}}``
12541254
where ``"sub"`` or ``"ses"`` can be a regexp that subject and session
12551255
names respectively are validated against.
12561256
12571257
"""
1258-
self._update_persistent_setting("name_templates", new_name_templates)
1258+
self._update_persistent_setting(
1259+
"validation_templates", new_validation_templates
1260+
)
12591261

12601262
# -------------------------------------------------------------------------
12611263
# Showers
@@ -1328,7 +1330,7 @@ def validate_project(
13281330
local_vars=locals(),
13291331
)
13301332

1331-
name_templates = self.get_name_templates()
1333+
validation_templates = self.get_validation_templates()
13321334

13331335
if self.is_local_project():
13341336
include_central = False
@@ -1342,7 +1344,7 @@ def validate_project(
13421344
top_level_folder_to_validate,
13431345
include_central=include_central,
13441346
display_mode=display_mode,
1345-
name_templates=name_templates,
1347+
validation_templates=validation_templates,
13461348
strict_mode=strict_mode,
13471349
)
13481350

@@ -1624,8 +1626,15 @@ def _update_settings_with_new_canonical_keys(self, settings: Dict) -> None:
16241626
Added keys:
16251627
v0.4.0: tui "overwrite_existing_files" and "dry_run"
16261628
"""
1627-
if "name_templates" not in settings:
1628-
settings.update(canonical_configs.get_name_templates_defaults())
1629+
if "validation_template" not in settings:
1630+
if "validation_template" in settings:
1631+
settings["validation_template"] = settings.pop(
1632+
"validation_template"
1633+
)
1634+
else:
1635+
settings.update(
1636+
canonical_configs.get_validation_templates_defaults()
1637+
)
16291638

16301639
canonical_tui_configs = canonical_configs.get_tui_config_defaults()
16311640

datashuttle/datashuttle_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def quick_validate_project(
2727
top_level_folder: Optional[TopLevelFolder] = "rawdata",
2828
display_mode: DisplayMode = "warn",
2929
strict_mode: bool = False,
30-
name_templates: Optional[Dict] = None,
30+
validation_templates: Optional[Dict] = None,
3131
) -> List[str]:
3232
"""Perform validation on a NeuroBlueprint-formatted project.
3333
@@ -53,9 +53,9 @@ def quick_validate_project(
5353
any folder not prefixed with sub-, ses- or a valid datatype will
5454
raise a validation issue.
5555
56-
name_templates
56+
validation_templates
5757
A dictionary of templates for subject and session name
58-
to validate against. See ``DataShuttle.set_name_templates()``
58+
to validate against. See ``DataShuttle.set_validation_templates()``
5959
for details.
6060
6161
Returns
@@ -93,7 +93,7 @@ def quick_validate_project(
9393
top_level_folder_list=top_level_folders_to_validate,
9494
include_central=False,
9595
display_mode=display_mode,
96-
name_templates=name_templates,
96+
validation_templates=validation_templates,
9797
strict_mode=strict_mode,
9898
)
9999

datashuttle/tui/interface.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Interface:
3535
def __init__(self) -> None:
3636
"""Initialise the Interface class."""
3737
self.project: DataShuttle
38-
self.name_templates: Dict = {}
38+
self.validation_templates: Dict = {}
3939
self.tui_settings: Dict = {}
4040

4141
self.gdrive_rclone_setup_process: subprocess.Popen | None = None
@@ -171,7 +171,7 @@ def validate_names(
171171
top_level_folder,
172172
sub_names,
173173
ses_names,
174-
self.get_name_templates(),
174+
self.get_validation_templates(),
175175
bypass_validation=False,
176176
)
177177

@@ -352,28 +352,30 @@ def transfer_custom_selection(
352352
# Name templates
353353
# ----------------------------------------------------------------------------------
354354

355-
def get_name_templates(self) -> Dict:
356-
"""Return the `name_templates` defining templates to validate against.
355+
def get_validation_templates(self) -> Dict:
356+
"""Return the `validation_templates` defining templates to validate against.
357357
358358
These are stored in a variable to avoid constantly
359359
reading these values from disk where they are stored in
360360
`persistent_settings`. It is critical this variable
361361
and the file contents are in sync, so when changed
362362
on the TUI side they are updated also, in `get_tui_settings`.
363363
"""
364-
if not self.name_templates:
365-
self.name_templates = self.project.get_name_templates()
364+
if not self.validation_templates:
365+
self.validation_templates = self.project.get_validation_templates()
366366

367-
return self.name_templates
367+
return self.validation_templates
368368

369-
def set_name_templates(self, name_templates: Dict) -> InterfaceOutput:
370-
"""Set the `name_templates` here and on disk.
369+
def set_validation_templates(
370+
self, validation_templates: Dict
371+
) -> InterfaceOutput:
372+
"""Set the `validation_templates` here and on disk.
371373
372-
See `get_name_templates` for more information.
374+
See `get_validation_templates` for more information.
373375
"""
374376
try:
375-
self.project.set_name_templates(name_templates)
376-
self.name_templates = name_templates
377+
self.project.set_validation_templates(validation_templates)
378+
self.validation_templates = validation_templates
377379
return True, None
378380

379381
except BaseException as e:
@@ -382,7 +384,7 @@ def set_name_templates(self, name_templates: Dict) -> InterfaceOutput:
382384
def get_tui_settings(self) -> Dict:
383385
"""Return the "tui" field of `persistent_settings`.
384386
385-
Similar to `get_name_templates`, there are held on the
387+
Similar to `get_validation_templates`, there are held on the
386388
class to avoid constantly reading from disk.
387389
"""
388390
if not self.tui_settings:

datashuttle/tui/screens/create_folder_settings.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@
2929
class CreateFoldersSettingsScreen(ModalScreen):
3030
"""Settings for the Create Folders tab.
3131
32-
Handles setting datashuttle's `name_template`, as well
32+
Handles setting datashuttle's `validation_template`, as well
3333
as the top-level-folder select and option to bypass all validation.
3434
3535
Name Templates
3636
--------------
3737
These are regexp templates that can be validated against
3838
during folder creation / project validation.
3939
40-
An input is provided to input a `name_template` for validation. When
41-
the window is closed, the `name_template` is stored in datashuttle's
40+
An input is provided to input a `validation_template` for validation. When
41+
the window is closed, the `validation_template` is stored in datashuttle's
4242
persistent settings.
4343
4444
The Create tab validation of input widgets is immediately updated
4545
on closing of this screen.
4646
4747
Attributes
4848
----------
49-
Because the Input for `name_templates` is shared between subject
49+
Because the Input for `validation_templates` is shared between subject
5050
and session, the values are held in the `input_values` attribute.
5151
These are loaded from `persistent_settings` on init.
5252
@@ -131,7 +131,9 @@ def compose(self) -> ComposeResult:
131131
Checkbox(
132132
"Template validation",
133133
id="template_settings_validation_on_checkbox",
134-
value=self.interface.get_name_templates()["on"],
134+
value=self.interface.get_validation_templates()[
135+
"on"
136+
],
135137
),
136138
id="template_inner_horizontal_container",
137139
),
@@ -181,9 +183,9 @@ def on_mount(self) -> None:
181183

182184
def init_input_values_holding_variable(self) -> None:
183185
"""Add the project Name Templates to the relevant Inputs."""
184-
name_templates = self.interface.get_name_templates()
185-
self.input_values["sub"] = name_templates["sub"]
186-
self.input_values["ses"] = name_templates["ses"]
186+
validation_templates = self.interface.get_validation_templates()
187+
self.input_values["sub"] = validation_templates["sub"]
188+
self.input_values["ses"] = validation_templates["ses"]
187189

188190
def switch_template_container_disabled(self) -> None:
189191
"""Switch the name template widgets disabled / enabled."""
@@ -193,7 +195,7 @@ def switch_template_container_disabled(self) -> None:
193195
self.query_one("#template_inner_container").disabled = not is_on
194196

195197
def fill_input_from_template(self) -> None:
196-
"""Fill the `name_templates` Input.
198+
"""Fill the `validation_templates` Input.
197199
198200
The Input is shared between subject and session,
199201
depending on the current RadioSet value.
@@ -210,15 +212,15 @@ def fill_input_from_template(self) -> None:
210212
def on_button_pressed(self, event: Button.Pressed) -> None:
211213
"""Handle button press on the screen.
212214
213-
On close, update the `name_templates` stored in
215+
On close, update the `validation_templates` stored in
214216
`persistent_settings` with those set on the TUI.
215217
216218
Setting may error if templates are turned on but
217219
no template exists for either subject or session.
218220
"""
219221
if event.button.id == "create_folders_settings_close_button":
220-
success, output = self.interface.set_name_templates(
221-
self.make_name_templates_from_widgets()
222+
success, output = self.interface.set_validation_templates(
223+
self.make_validation_templates_from_widgets()
222224
)
223225
if success:
224226
self.dismiss(True)
@@ -228,8 +230,8 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
228230
elif event.button.id == "create_settings_bypass_validation_button":
229231
self.interface.save_tui_settings(False, "bypass_validation")
230232

231-
def make_name_templates_from_widgets(self) -> Dict:
232-
"""Return a canonical `name_templates` entry based on the current widget settings."""
233+
def make_validation_templates_from_widgets(self) -> Dict:
234+
"""Return a canonical `validation_templates` entry based on the current widget settings."""
233235
return {
234236
"on": self.query_one(
235237
"#template_settings_validation_on_checkbox"
@@ -239,7 +241,7 @@ def make_name_templates_from_widgets(self) -> Dict:
239241
}
240242

241243
def on_checkbox_changed(self, event: Checkbox.Changed) -> None:
242-
"""Turn `name_templates` on or off and update the TUI accordingly."""
244+
"""Turn `validation_templates` on or off and update the TUI accordingly."""
243245
is_on = event.value
244246

245247
if event.checkbox.id == "template_settings_validation_on_checkbox":

0 commit comments

Comments
 (0)