Undocumented
Constant | F |
Undocumented |
Class | KeepOpenFile |
Undocumented |
Class | LazyFile |
No summary |
Class | PacifyFlushWrapper |
No summary |
Function | _detect_program_name |
No summary |
Function | _expand_args |
Simulate Unix shell expansion with Python functions. |
Function | _posixify |
Undocumented |
Function | echo |
Print a message and newline to stdout or a file. This should be used instead of print because it provides better support for different data, files, and environments. |
Function | format_filename |
No summary |
Function | get_app_dir |
Returns the config folder for the application. The default behavior is to return whatever is most appropriate for the operating system. |
Function | get_binary_stream |
Returns a system stream for byte processing. |
Function | get_os_args |
Returns the argument part of sys.argv, removing the first value which is the name of the script. |
Function | get_text_stream |
No summary |
Function | make_default_short_help |
Returns a condensed version of help string. |
Function | make_str |
Converts a value into a valid string. |
Function | open_file |
This is similar to how the File works but for manual usage. Files are opened non lazy by default. This can open regular files as well as stdin/stdout if '-' is passed. |
Function | safecall |
Wraps a function so that it swallows exceptions. |
Determine the command used to run the program, for use in help text. If a file or entry point was executed, the file name is returned. If python -m was used to execute a module or package, python -m name is returned.
This doesn't try to be too precise, the goal is to give a concise name for help text. Files are only shown as their name without the path. python is only shown for modules, and the full path to sys.executable is not shown.
Parameters | |
path:t.Optional[ | The Python file being executed. Python puts this in sys.argv[0], which is used by default. |
_main:ModuleType | The __main__ module. This should only be passed during internal testing. |
Returns | |
str | Undocumented |
Unknown Field: meta | |
private |
Simulate Unix shell expansion with Python functions.
See glob.glob
, os.path.expanduser
, and
os.path.expandvars
.
This intended for use on Windows, where the shell does not do any expansion. It may not exactly match what a Unix shell would do.
Parameters | |
args:t.Iterable[ | List of command line arguments to expand. |
user:bool | Expand user home directory. |
env:bool | Expand environment variables. |
glob_recursive:bool | ** matches directories recursively. |
Returns | |
t.List[ | Undocumented |
Unknown Field: meta | |
private |
Print a message and newline to stdout or a file. This should be
used instead of print
because it provides better support
for different data, files, and environments.
Compared to print
, this does the following:
Parameters | |
message:t.Optional[ | The string or bytes to output. Other objects are converted to strings. |
file:t.Optional[ | The file to write to. Defaults to stdout. |
nl:bool | Print a newline after the message. Enabled by default. |
err:bool | Write to stderr instead of stdout. |
color:t.Optional[ | Force showing or hiding colors and other styles. By default Click will remove color if the output does not look like an interactive terminal. |
Parameters | |
filename:t.Union[ | formats a filename for UI display. This will also convert the filename into unicode without failing. |
shorten:bool | this optionally shortens the filename to strip of the path that leads up to it. |
Returns | |
str | Undocumented |
Returns the config folder for the application. The default behavior is to return whatever is most appropriate for the operating system.
To give you an idea, for an app called "Foo Bar", something like the following folders could be returned:
Parameters | |
app_name:str | the application name. This should be properly capitalized and can contain whitespace. |
roaming:bool | controls if the folder should be roaming or not on Windows. Has no affect otherwise. |
force_posix:bool | if this is set to True then on any POSIX system the
folder will be stored in the home folder with a leading
dot instead of the XDG config home or darwin's
application support folder. |
Returns | |
str | Undocumented |
Parameters | |
name:te.Literal[ | the name of the stream to open. Valid names are 'stdin', 'stdout' and 'stderr' |
Returns | |
t.BinaryIO | Undocumented |
Returns the argument part of sys.argv, removing the first value which is the name of the script.
Returns | |
t.Sequence[ | Undocumented |
get_binary_stream
but it also can take shortcuts for already
correctly configured streams.Parameters | |
name:te.Literal[ | the name of the stream to open. Valid names are 'stdin', 'stdout' and 'stderr' |
encoding:t.Optional[ | overrides the detected default encoding. |
errors:t.Optional[ | overrides the default error mode. |
Returns | |
t.TextIO | Undocumented |
Parameters | |
help:str | Undocumented |
max_length:int | Undocumented |
Returns | |
str | Undocumented |
Parameters | |
value:t.Any | Undocumented |
Returns | |
str | Undocumented |
This is similar to how the File
works but for manual
usage. Files are opened non lazy by default. This can open regular
files as well as stdin/stdout if '-' is passed.
If stdin/stdout is returned the stream is wrapped so that the context manager will not close the stream accidentally. This makes it possible to always use the function like this without having to worry to accidentally close a standard stream:
with open_file(filename) as f: ...
Parameters | |
filename:str | the name of the file to open (or '-' for stdin/stdout). |
mode:str | the mode in which to open the file. |
encoding:t.Optional[ | the encoding to use. |
errors:t.Optional[ | the error handling for this file. |
lazy:bool | can be flipped to true to open the file lazily. |
atomic:bool | in atomic mode writes go into a temporary file and it's moved on close. |
Returns | |
t.IO | Undocumented |