chooser_paths
anomaly_match_ui.utils.chooser_paths
¶
Resolve the starting directory and pre-selected file for setup-screen choosers.
Shared by :class:TrainingSetupScreen and :class:PredictionSetupScreen, which
otherwise carried two copies of the same precedence rules.
resolved_dir(cfg_value, *, purpose)
¶
Resolve a directory from persisted state or config, without a fallback.
Resolution order (#429):
ui_state.get_last_browsed_dir(purpose)— the directory the user last clicked Select in. Wins over the cfg value because cfg defaults (e.g.tests/test_data/grayscale) would otherwise clobber the user's actual recent intent on every fresh kernel start.cfg_value— used when no persisted dir exists yet, e.g. on first run of a notebook with a manually-setdata_dir.
Kept separate from :func:initial_dir so callers can tell a real
resolution from the cwd fallback: pre-selecting the cwd would silently
adopt it as the user's choice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg_value
|
str | None
|
A path from config (file or directory), or |
required |
purpose
|
str
|
Stable key identifying the chooser site so we can look up its persisted last-browsed directory. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
An existing directory, or |
Source code in anomaly_match_ui/utils/chooser_paths.py
initial_dir(cfg_value, *, purpose)
¶
Derive a starting directory for a chooser, falling back to the cwd.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg_value
|
str | None
|
A path from config (file or directory), or |
required |
purpose
|
str
|
Stable key identifying the chooser site so we can look up its persisted last-browsed directory. |
required |
Returns:
| Type | Description |
|---|---|
str
|
func: |
Source code in anomaly_match_ui/utils/chooser_paths.py
initial_file(cfg_value, *, purpose, is_shipped_default=False)
¶
Resolve the starting directory and pre-selected filename for a chooser.
A configured file that exists wins outright: the chooser opens in its
directory with it pre-selected, because a chooser that picks a file must
display the file the screen will then use — _resolve_label_path loads
cfg.label_file and _on_start writes cfg.model_path /
cfg.metadata_file regardless of what the widget shows. That reverses
:func:initial_dir's precedence (#429), which stands for the directory
choosers.
The shipped default is not something the user configured, so it keeps #429's
order: the remembered folder wins, and the default's filename is pre-selected
only if a file of that name really exists there. Without this the bundled
test-data labeled_data.csv, which always exists, would replace the user's
last-picked labels on every fresh kernel.
Nothing is pre-selected when the configured file is missing or unset: the chooser opens where the user was last browsing and the panel reports the field as unfilled, which is again what the caller acts on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg_value
|
str | None
|
A file path from config, or |
required |
purpose
|
str
|
Stable key identifying the chooser site, used to look up its persisted last-browsed directory when cfg resolves to nothing. |
required |
is_shipped_default
|
bool
|
Whether cfg_value is the bundled default rather than
a path the user configured (see
|
False
|
Returns:
| Type | Description |
|---|---|
str
|
Tuple of |
str
|
file resolves; callers pass |