MWPath¶
- class lsst.daf.butler.cli.utils.MWPath(exists: bool | None = None, file_okay: bool = True, dir_okay: bool = True, writable: bool = False, readable: bool = True, resolve_path: bool = False, allow_dash: bool = False, path_type: type | None = None)¶
Bases:
PathOverrides
click.Pathto implement file-does-not-exist checking.Changes the definition of
existsso thatTrueindicates the location (file or directory) must exist,Falseindicates the location must not exist, andNoneindicates that the file may exist or not. The standard definition for theclick.Pathexistsparameter is that forTruea location must exist, butFalsemeans it is not required to exist (not that it is required to not exist).- Parameters:
- exists
boolorNone, optional If
True, the location (file or directory) indicated by the caller must exist. IfFalsethe location must not exist. IfNone, the location may exist or not.- file_okay
bool, optional Allow a file as a value.
- dir_okay
bool, optional Allow a directory as a value.
- writable
bool, optional If
True, a writable check is performed.- readable
bool, optional If
True, a readable check is performed.- resolve_path
bool, optional Resolve the path.
- allow_dash
bool, optional Allow single dash as value to mean a standard stream.
- path_type
typeorNone, optional Convert the incoming value to this type.
- exists
Notes
All parameters other than
existscome directly fromclick.Path.Attributes Summary
if a list of this type is expected and the value is pulled from a string environment variable, this is what splits it up.
Methods Summary
__call__(value[, param, ctx])Call self as a function.
coerce_path_result(value)convert(value, param, ctx)Convert values through types.
fail(message[, param, ctx])Helper method to fail with an invalid value message.
get_metavar(param, ctx)Returns the metavar default for this param if it provides one.
get_missing_message(param, ctx)Optionally might return extra information about a missing parameter.
shell_complete(ctx, param, incomplete)Return a special completion marker that tells the completion system to use the shell to provide path completions for only directories or any paths.
Given a value from an environment variable this splits it up into small chunks depending on the defined envvar list splitter.
Gather information that could be useful for a tool generating user-facing documentation.
Attributes Documentation
- envvar_list_splitter: t.ClassVar[str] = ':'¶
if a list of this type is expected and the value is pulled from a string environment variable, this is what splits it up.
Nonemeans any whitespace. For all parameters the general rule is that whitespace splits them up. The exception are paths and files which are split byos.path.pathsepby default (“:” on Unix and “;” on Windows).
Methods Documentation
- __call__(value: t.Any, param: Parameter | None = None, ctx: Context | None = None) t.Any¶
Call self as a function.
- convert(value: str | PathLike[str], param: Parameter | None, ctx: Context | None) Any¶
Convert values through types.
Called by
click.ParamTypeto “convert values through types”.click.Pathuses this step to verify Path conditions.- Parameters:
- value
stroros.PathLike File path.
- param
click.Parameter Parameters provided by Click.
- ctx
click.Context Context provided by Click.
- value
- fail(message: str, param: Parameter | None = None, ctx: Context | None = None) t.NoReturn¶
Helper method to fail with an invalid value message.
- get_metavar(param: Parameter, ctx: Context) str | None¶
Returns the metavar default for this param if it provides one.
- get_missing_message(param: Parameter, ctx: Context | None) str | None¶
Optionally might return extra information about a missing parameter.
New in version 2.0.
- shell_complete(ctx: Context, param: Parameter, incomplete: str) list[CompletionItem]¶
Return a special completion marker that tells the completion system to use the shell to provide path completions for only directories or any paths.
- Parameters:
ctx – Invocation context for this command.
param – The parameter that is requesting completion.
incomplete – Value being completed. May be empty.
New in version 8.0.
- split_envvar_value(rv: str) Sequence[str]¶
Given a value from an environment variable this splits it up into small chunks depending on the defined envvar list splitter.
If the splitter is set to
None, which means that whitespace splits, then leading and trailing whitespace is ignored. Otherwise, leading and trailing splitters usually lead to empty items being included.