Registry / devops / click-pathlib

click-pathlib

JSON →
library2020.3.13.0pypypi✓ verified 85d ago

A Click parameter type that behaves like click.Path but returns a pathlib.Path object instead of a string. Version 2020.3.13.0 is the latest released in March 2020. Low activity; no releases since 2020.

pip install click-pathlib
INSTALL
IMPORT
SIG · CLICK-PATHLIB
C
click-pathlib
devopspythonv2020.3.13.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Path
from click_pathlib import Path
from click_pathlib import Pathlib
Common mistake: wrong casing or using 'pathlib' suffix instead of 'Path'.

Defines a Click command with a pathlib.Path option that does not require the path to exist.

import click from click_pathlib import Path @click.command() @click.option('--output', type=Path(exists=False), help='Output file path') def main(output): click.echo(f'Output path: {output}') if __name__ == '__main__': main()
Debug
Known issues
breakingDoes not support the 'dir_okay', 'file_okay', or 'path_type' parameters from click.Path; only supports 'exists', 'file_okay', 'dir_okay', 'writable', 'readable', 'resolve_path'. In Click 8.x, click.Path behavior changed; this library may not be compatible.
fix
Check Click version compatibility. Use click.Path with path_type=pathlib.Path for simpler cases.
affects: all
deprecatedLibrary is not actively maintained. Since Click 7.0, click.Path supports a 'path_type' argument that can return pathlib.Path directly, making this library less necessary.
fix
Consider using click.Path(path_type=pathlib.Path) instead, which is built into Click.
affects: all
gotchaIf the file does not exist and exists=True, the parameter still returns a Path object even though the path doesn't exist at runtime; the exception is raised before the function body.
fix
Understand that validation happens at click parsing time; the function receives a valid Path.
affects: all
Errors
Common errors & fixes
AttributeError: module 'click_pathlib' has no attribute 'Path'
Incorrect import statement; sometimes people try import click_pathlib and then click_pathlib.Path() but the class is named 'Path' exactly.
fix
Use 'from click_pathlib import Path'.
TypeError: 'Path' object is not callable
Attempting to call the Path class without arguments incorrectly, or naming conflict with pathlib.Path.
fix
Use the parameter decorator correctly: @click.option('--path', type=Path(exists=False)).
click.exceptions.BadParameter: Invalid value for '--path': Path '...' does not exist.
Set exists=True and the file does not exist at the time of command invocation.
fix
Set exists=False if the file may not pre-exist, or create the file before invoking.
Upgrade
Version history
2020.3.13.0latest on PyPI · released Mar 13, 2020
Audit
Dependencies
clickrequiredCore dependency for Click types
Agent activity
8 hits · last 30 days
node
8
Resources
click-pathlib — pip install click-pathlib · libregistry