rocrate_action_recorder.adapters.click¶
Adapter for Click CLI framework.
Attributes¶
Functions¶
|
Get help text for a Click argument/option. |
|
Convert a Click parameter value to a list of Path objects. |
|
Try to convert a single item to a Path. |
|
Extract Program information from a Click context. |
|
Map a single Click parameter name to IOArgumentPath entries. |
|
Map multiple Click parameter names to IOArgumentPath entries. |
Collect Program and IOArgumentPaths from Click inputs. |
|
|
Record a CLI invocation in an RO-Crate using Click. |
|
Decorator to record a CLI invocation in an RO-Crate using Click. |
Module Contents¶
- rocrate_action_recorder.adapters.click.logger¶
- rocrate_action_recorder.adapters.click.click_help(ctx: click.Context, arg_name: str) str | None[source]¶
Get help text for a Click argument/option.
- Parameters:
ctx – The Click context.
arg_name – The normalized argument/option name.
- Returns:
The help text if found, otherwise None.
- rocrate_action_recorder.adapters.click.click_value2paths(value: Any) list[pathlib.Path][source]¶
Convert a Click parameter value to a list of Path objects.
Handles single paths, file-like objects, and tuples/lists of paths. Deduplicates paths before returning.
- Parameters:
value – A parsed Click parameter value.
- Returns:
A list of deduplicated paths.
- rocrate_action_recorder.adapters.click.try_convert_to_path(item: Any) pathlib.Path | None[source]¶
Try to convert a single item to a Path.
- rocrate_action_recorder.adapters.click.program_from_context(ctx: click.Context) rocrate_action_recorder.core.Program[source]¶
Extract Program information from a Click context.
- Parameters:
ctx – The current Click context.
- Returns:
Program with command and selected subcommand information.
- rocrate_action_recorder.adapters.click.map_name2paths(ctx: click.Context, params: dict[str, Any], name: str) list[rocrate_action_recorder.core.IOArgumentPath][source]¶
Map a single Click parameter name to IOArgumentPath entries.
- rocrate_action_recorder.adapters.click.map_names2paths(ctx: click.Context, params: dict[str, Any], names: list[str]) list[rocrate_action_recorder.core.IOArgumentPath][source]¶
Map multiple Click parameter names to IOArgumentPath entries.
- rocrate_action_recorder.adapters.click.collect_record_info_from_click(ctx: click.Context, params: dict[str, Any], ios: rocrate_action_recorder.adapters.shared.IOArgumentNames, software_version: str | None = None) tuple[rocrate_action_recorder.core.Program, rocrate_action_recorder.core.IOArgumentPaths][source]¶
Collect Program and IOArgumentPaths from Click inputs.
- Parameters:
ctx – Current Click context.
params – Parsed Click parameters.
ios – Parameter names that map to input/output files and directories.
software_version – Optional program version override.
- Returns:
A tuple of (Program, IOArgumentPaths).
- rocrate_action_recorder.adapters.click.record_click(ctx: click.Context, params: dict[str, Any], ios: rocrate_action_recorder.adapters.shared.IOArgumentNames, start_time: datetime.datetime, crate_dir: pathlib.Path | None = None, argv: list[str] | None = None, end_time: datetime.datetime | None = None, current_user: str | None = None, software_version: str | None = None, dataset_license: str | None = None) pathlib.Path[source]¶
Record a CLI invocation in an RO-Crate using Click.
Hint
The argument names passed in
IOArgumentNamesshould match keys in params (typically ctx.params), which are the normalized Click parameter names. For example @click.option(’–input-file’) usually corresponds to parameter name input_file.- Parameters:
ctx – Current Click context.
params – Parsed Click parameters.
ios – Parameter names that map to input/output files and directories.
start_time – Datetime when the action started.
crate_dir – Optional path to RO-Crate directory.
argv – Optional command arguments to use in action id.
end_time – Optional datetime when action ended.
current_user – Optional user override.
software_version – Optional software version override.
dataset_license – Optional dataset license string.
- Returns:
Path to generated ro-crate-metadata.json.
- rocrate_action_recorder.adapters.click.recorded_click(input_dirs: list[str] | None = None, output_dirs: list[str] | None = None, input_files: list[str] | None = None, output_files: list[str] | None = None, dataset_license: str | None = None, enabled_argument: str | None = None) collections.abc.Callable[[collections.abc.Callable[Ellipsis, recorded_click.T]], collections.abc.Callable[Ellipsis, recorded_click.T]][source]¶
Decorator to record a CLI invocation in an RO-Crate using Click.
Hint
The argument names for input_dirs, output_dirs, input_files, and output_files should match keys in ctx.params (normalized Click parameter names). For example @click.option(’–input-file’) usually corresponds to parameter name input_file.
- Parameters:
input_dirs – Parameter names representing input directories.
output_dirs – Parameter names representing output directories.
input_files – Parameter names representing input files.
output_files – Parameter names representing output files.
dataset_license – License string for the dataset.
enabled_argument – Optional parameter name controlling recording.
- Returns:
Decorator function.