jacinle.cli package¶
Submodules¶
jacinle.cli.argument module¶
A customized argument parser.
-
class
jacinle.cli.argument.JacArgumentParser(*args, **kwargs)[source]¶ Bases:
argparse.ArgumentParserA customized argument parser. The main difference is that
JacArgumentParsersupports additional types, including:type='bool': a boolean value, internally converted toTrue(true, t, yes, y, 1) orFalse(no, n, false, f, 0).type='checked_file': a file path, checked to be an existing file.type='checked_dir': a directory path, checked to be an existing directory.type='ensured_dir': a directory path, checked to be an existing directory, and created if not.type='kv': a key-value pair, separated by=and;. For example,--configs "data.int_or_float=int_value; data.string='string_value'".action='set_device': set CUDA visible devices.action='as_enum': convert the argument to an enum value.
jacinle.cli.device module¶
Uiltity functions to parse CPU/CUDA device strings.
-
class
jacinle.cli.device.DeviceNameFormat[source]¶ Bases:
jacinle.utils.enum.JacEnumThe target fmt of device names. Supported formats are:
DeviceNameFormat.INT: integer, e.g.,0,1,2, etc.DeviceNameFormat.TENSORFLOW: TensorFlow-style device name, e.g.,/cpu:0,/gpu:1, etc.
-
INT= 'int'¶
-
TENSORFLOW= 'tensorflow'¶
-
jacinle.cli.device.canonlize_device_name(d: str, fmt: Union[str, jacinle.cli.device.DeviceNameFormat] = <DeviceNameFormat.INT: 'int'>) → Union[str, int][source]¶ Convert a device name to a canonical format.
Parameters: - d – the device name to be converted. The string can be either:
cpu,gpu0, or0. - fmt – the target format.
Returns: the canonical device name. If the target format is
DeviceNameFormat.INT, the return value is an integer. When d iscpu, the return value is-1. If the target format isDeviceNameFormat.TENSORFLOW, the return value is a string: e.g.,/cpu:0,/gpu:1, etc.- d – the device name to be converted. The string can be either:
-
jacinle.cli.device.parse_devices(devs: Union[str, Sequence[str]], fmt: Union[str, jacinle.cli.device.DeviceNameFormat] = <DeviceNameFormat.INT: 'int'>) → List[Union[str, int]][source]¶ Parse a input list of strings or a single comma-separated string into a list of device names.
Parameters: - devs – the input device list.
- fmt – the target format.
Returns: the parsed device list.
-
jacinle.cli.device.set_cuda_visible_devices(devs: Union[str, Sequence[str]])[source]¶ Set the CUDA_VISIBLE_DEVICES environment variable with a single comma-separated string or a list of strings.
Parameters: devs – the input device list. Either a single comma-separated string or a list of strings.
-
jacinle.cli.device.parse_and_set_devices(devs: Union[str, Sequence[str]], fmt: Union[str, jacinle.cli.device.DeviceNameFormat] = <DeviceNameFormat.INT: 'int'>, set_device: bool = True)[source]¶ Parse a input list of strings or a single comma-separated string into a list of device names. When
set_deviceis True, the CUDA_VISIBLE_DEVICES environment variable will be set accordingly.Parameters: - devs – the input device list.
- fmt – the target format.
- set_device – whether to set the CUDA_VISIBLE_DEVICES environment variable.
Returns: the parsed device list.
jacinle.cli.git module¶
Utility functions to get git information of the current directory.
-
jacinle.cli.git.git_current_tracking_remote() → str[source]¶ Get the current tracking remote.
Returns: the name of the current tracking remote.
-
jacinle.cli.git.git_guard(force: bool = False)[source]¶ A utility function to guard the current git repo. It will check whether there are uncommitted files.
- When
forceis False, it will print a warning message including the list of uncommitted files and the diff of the uncommitted files. - When
forceis True, it will ask a confirmation from the user. If the user confirms, it will return True. Otherwise, it will terminate the program.
- When
-
jacinle.cli.git.git_recent_logs(revision_hash: str, n: int = 5) → str[source]¶ Get the recent logs of the given revision hash.
Parameters: - revision_hash – the revision hash.
- n – the number of logs to be returned.
Returns: the recent logs as a single string.
-
jacinle.cli.git.git_remote_url(remote_identifier: Optional[str] = None) → str[source]¶ Get the URL of the remote.
Parameters: remote_identifier – the identifier of the remote. If None, use the current tracking remote. Returns: the URL of the remote.
-
jacinle.cli.git.git_revision_hash(short: bool = False) → str[source]¶ Get the current revision hash.
Parameters: short – whether to use the short version of the hash. Returns: the current revision hash.
-
jacinle.cli.git.git_root() → str[source]¶ Get the root directory of the git repo.
Returns: the root directory of the git repo.
-
jacinle.cli.git.git_status_full()[source]¶ Get the full status of the current git repo. This includes the content of the untracked files and the diff of the uncommitted files. Note that when the file is too large (larger than 128 kb), its content will not be shown.
Returns: a single string containing the full status of the current git repo.
jacinle.cli.keyboard module¶
Uiltity functions to parse keyboard inputs.
-
jacinle.cli.keyboard.str2bool(s: str) → bool[source]¶ Convert a string to boolean value.
Parameters: s – the string to be converted. Returns: True if the string is “yes”, “true”, “y”, “t”, “1”; False if the string is “no”, “false”, “n”, “f”, “0”; otherwise, raise ValueError.
-
jacinle.cli.keyboard.yn2bool(s: str) → bool[source]¶ Convert a string to boolean value.
Parameters: s – the string to be converted. Returns: True if the string is “y” or “yes”; False if the string is “n” or “no”; otherwise, raise ValueError.
-
jacinle.cli.keyboard.str2bool_long(s: str) → bool[source]¶ Convert a string to boolean value.
Parameters: s – the string to be converted. Returns: True if the string is “yes”, “true”; False if the string is “no”, “false”; otherwise, raise ValueError.
-
jacinle.cli.keyboard.yes_or_no(question: str, default: Optional[str] = 'yes') → bool[source]¶ Ask a yes/no question via input() and return their answer.
Parameters: - question – the question to be asked.
- default – the default answer. It must be “yes” (the default), “no” or None (meaning that an answer is required from the user).