Skip to content

isimip_utils.cli

Command-line interface utilities for ISIMIP tools.

ArgumentParser

Extended ArgumentParser that reads defaults from config files and environment.

Supports reading configuration from TOML files in the following order:

  • ./isimip.toml
  • ~/.isimip.toml
  • /etc/isimip.toml

Environment variables (uppercase) override config file values.

setup_env()

Load environment variables from .env file in current working directory.

setup_logs(log_level='WARNING', log_file=None, log_console=True, log_rich=True, show_time=False, show_path=False)

Configure logging with console and/or file handlers.

Parameters:

Name Type Description Default
log_level str

Logging level (default: 'WARNING').

'WARNING'
log_file str | None

Path to log file, or None for no file logging (default: None).

None
log_console bool

Whether to log to console (default: True).

True
log_rich bool

Whether to use RichHandler for console logging (default: True).

True
show_time bool

Whether to show the time in the console logs (default: False).

False
show_path bool

Whether to show the path in the console logs (default: False).

False

parse_dict(string)

Parse a string in format 'key=value1,value2' into a dictionary.

Parameters:

Name Type Description Default
string str

String to parse in format 'key=value1,value2,value3'.

required

Returns:

Type Description
dict[str, list[str]] | None

Dictionary with single key mapping to list of values.

parse_list(string)

Parse a comma-separated string into a list.

Parameters:

Name Type Description Default
string str

Comma-separated string to parse.

required

Returns:

Type Description
list[str]

List of stripped values.

parse_version(value)

Parse a version string in YYYYMMDD format.

Parameters:

Name Type Description Default
value str

Version string in YYYYMMDD format.

required

Returns:

Type Description
str

Version string in YYYYMMDD format.

Raises:

Type Description
ArgumentTypeError

If format is incorrect.

parse_path(value)

Parse and expand a path string.

Parameters:

Name Type Description Default
value str

Path string to parse.

required

Returns:

Type Description
Path

Expanded Path object.

parse_locations(value)

Parse and expand a location string as list of URL or Path objects.

Parameters:

Name Type Description Default
value str

Location string to parse.

required

Returns:

Type Description
list[str | Path]

List of URL or Path objects.

parse_filelist(filelist_file)

Parse a filelist file into a set of file paths.

Parameters:

Name Type Description Default
filelist_file str | Path | None

Path to file containing list of paths (one per line). Lines starting with '#' are treated as comments.

required

Returns:

Type Description
set[str]

List of file paths.

parse_parameters(value)

Parse and expand a parameters string (a=b).

Parameters:

Name Type Description Default
value str

Parameter string to parse.

required

Returns:

Type Description
Path

Dict of the form {key: values}