Files Module

Custom file / path input handlers for Parameters

author:

Doug Skrypa

class cli_command_parser.inputs.files.FileInput(*, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = <StatMode:ANY>, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True)[source]

Bases: InputType[T], ABC

exists: InputParam[bool | None]
expand: InputParam[bool]
resolve: InputParam[bool]
type: InputParam[StatMode]
readable: InputParam[bool]
writable: InputParam[bool]
allow_dash: InputParam[bool]
use_windows_fix: InputParam[bool]
fix_default(value: T | str | None) T | str | None[source]

Fixes the default value to conform to the expected return type for this input. Allows the default value for a path to be provided as a string, for example.

validated_path(path: PathLike) _Path[source]
class cli_command_parser.inputs.files.Path(*, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = <StatMode:ANY>, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True)[source]

Bases: FileInput[Path]

Parameters:
  • exists – If set, then the provided path must already exist if True, or must not already exist if False. Default: existence is not checked.

  • expand – Whether tilde (~) should be expanded.

  • resolve – Whether the path should be fully resolved to its absolute path, with symlinks resolved, or not.

  • type – To restrict the acceptable types of files/directories that are accepted, specify the StatMode that matches the desired type. By default, any type is accepted. To accept specifically only regular files or directories, for example, use type=StatMode.DIR | StatMode.FILE.

  • readable – If True, the path must be readable.

  • writable – If True, the path must be writable.

  • allow_dash – Allow a dash (-) to be provided to indicate stdin/stdout (default: False).

  • use_windows_fix – If True (the default) and the program is running on Windows, then fix_windows_path() will be called to fix issues caused by auto-completion via Git Bash.

  • fix_default – Whether default values should be normalized using fix_default().

__call__(value: PathLike) _Path[source]
class cli_command_parser.inputs.files.File(mode: OpenTextMode = 'r', *, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[True] = True, parents: Bool = False)[source]
class cli_command_parser.inputs.files.File(mode: OpenBinaryMode, *, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[True] = True, parents: Bool = False)
class cli_command_parser.inputs.files.File(mode: OpenTextMode = 'r', *, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[False], parents: Bool = False)
class cli_command_parser.inputs.files.File(mode: OpenBinaryMode, *, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[False], parents: Bool = False)
class cli_command_parser.inputs.files.File(mode: OpenAnyMode = 'r', *, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Bool = True, parents: Bool = False)

Bases: FileInput[T_co]

Parameters:
  • mode – The mode in which the file should be opened. For more info, see open().

  • encoding – The encoding to use when reading the file in text mode. Ignored if the parsed path is -.

  • errors – Error handling when reading the file in text mode. Ignored if the parsed path is -.

  • lazy – If True, a FileWrapper will be stored in the Parameter using this File, otherwise the file will be read immediately upon parsing of the path argument.

  • parents – If True and mode implies writing, then create parent directories as needed. Ignored otherwise.

  • kwargs – Additional keyword arguments to pass to Path.

type: InputParam[StatMode]
mode: InputParam[OpenAnyMode]
encoding: InputParam[str | None]
errors: InputParam[str | None]
lazy: InputParam[bool]
parents: InputParam[bool]
__call__(value: PathLike) T_co[source]
class cli_command_parser.inputs.files.Serialized(serializer: AnySerializer[AnyStr], *, mode: OpenAnyMode = 'r', exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[True] = True, parents: Bool = False)[source]
class cli_command_parser.inputs.files.Serialized(serializer: AnySerializer, *, mode: OpenAnyMode = 'r', exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[False], parents: Bool = False)
class cli_command_parser.inputs.files.Serialized(serializer: AnySerializer, *, mode: OpenAnyMode = 'r', exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Bool = True, parents: Bool = False)

Bases: File[T_co]

Parameters:
  • serializer – Class or module that provides load/dump and/or loads/dumps methods/functions for deserialization and serialization, respectively. Expects them to follow the same interface as the json or pickle modules, with json.loads(), json.dumps(), pickle.load(), etc.

  • kwargs – Additional keyword arguments to pass to File

serializer: AnySerializer
class cli_command_parser.inputs.files.Json(*, mode: OpenTextMode = 'r', wrap_errors: Bool = True, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[True] = True, parents: Bool = False)[source]
class cli_command_parser.inputs.files.Json(*, mode: OpenTextMode = 'r', wrap_errors: Bool = True, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[False], parents: Bool = False)
class cli_command_parser.inputs.files.Json(*, mode: OpenTextMode = 'r', wrap_errors: Bool = True, exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Bool = True, parents: Bool = False)

Bases: Serialized[T_co]

Parameters:

kwargs – Additional keyword arguments to pass to File

class cli_command_parser.inputs.files.Pickle(*, mode: OpenBinaryMode = 'rb', exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[True] = True, parents: Bool = False)[source]
class cli_command_parser.inputs.files.Pickle(*, mode: OpenBinaryMode = 'rb', exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Literal[False], parents: Bool = False)
class cli_command_parser.inputs.files.Pickle(*, mode: OpenBinaryMode = 'rb', exists: Bool = None, expand: Bool = True, resolve: Bool = False, type: StatMode | str = StatMode.FILE, readable: Bool = False, writable: Bool = False, allow_dash: Bool = False, use_windows_fix: Bool = True, fix_default: Bool = True, encoding: OptStr = None, errors: OptStr = None, lazy: Bool = True, parents: Bool = False)

Bases: Serialized[T_co]

Parameters:

kwargs – Additional keyword arguments to pass to File