A library of path-like types for the Click command-line library
Reason this release was yanked:
Library is irrelevant now that click supports the pathlib.Path type
Project description
Advanced Path Types for Click
A library of path-like types for the Click command-line library.
I really like the click library for creating Python command-line interfaces, however, I've run into issues because it lacks the ability to do a couple of key things - namely the ability to produce a pathlib.Path
argument and the ability to use glob-based arguments. I am hoping to fix both of these with, and eventually add more useful commandline parameter types to this library. This library primarily implemented custom types for click parameters similar to how they're described here.
Installation & Setup
To install click-path with pip
execute the following:
pip install /path/to/repo/click-path
If you don't want to re-install every time there is an update, and prefer to just pull from the git repository, then use the -e
flag.
Usage Examples
PathlibPath
Allows the user of this library (and click
) to create CLIs which output Path
parameter types with a lot of the same validation as what's available for the standard click.Path
type. Here is an example:
from pathlib import Path
import click
from click_path import PathlibPath
EXISTING_READABLE_FILE = PathlibPath(exists=True,
file_okay=True,
dir_okay=False,
writable=False,
readable=True,
resolve_path=True)
@click.command()
@click.option('-t', '--test', type=EXISTING_READABLE_FILE)
def cli_existing_readable_file(test: Path):
click.echo(str(test))
GlobPaths
GlobPaths
allow you to take commandline arguments in the form of /path/to/directory/*
which then produces an iterable of pathlib.Path
objects for you to work with. It also allows filtering of said iterable of paths based on some specific parameters, like read/write permissions, and files vs. directories.
import click
from click_path import GlobPaths
READABLE_FILES = GlobPaths(extant_only=False,
files_okay=True,
dirs_okay=False,
writable_only=False,
readable_only=True,
resolve=False,
at_least_one=True)
@click.command()
@click.option('-t', '--tests', type=READABLE_FILES)
@typechecked
def cli(tests: Iterable[Path]):
click.echo(str(tests))
Development
For development, you're going to want to set up a virtual development environment with pipenv by following the linked instructions. I also strongly recommend setting the export PIPENV_VENV_IN_PROJECT=1
environment variable in your ~/.bashrc
or ~/.zshrc
file because that makes the venvs much easier to work with.
Then execute the following in the repo directory:
pipenv --three
To install the package for development, please use the dev
extra inside the virtualenv
pipenv install -e "/path/to/repo/click-path[dev]"
The -e
installs the package in place for development, so that you don't have to reinstall when you make changes.
Running Tests
You can run all the tests with pytest and coverage (or all the unit tests, by changing the path to tests/unit
) like so inside the virtualenv (pipenv shell
):
(click-path) pytest -s -vv --cov=click_path --cov-report=term-missing --cov-branch tests
Similarly, if you'd like to add HTML coverage reporting:
(click-path) pytest -s -vv --cov=click_path --cov-report=html:htmlcov --cov-report=term-missing --cov-branch tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file click-path-0.0.5.tar.gz
.
File metadata
- Download URL: click-path-0.0.5.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff5f968e55648640f745a646f136866bbb552bfeca0224aef9216d0c122004ea |
|
MD5 | 00efcac5c46b82335246dde196327a64 |
|
BLAKE2b-256 | 77a3c3444a4b753d21e889120b9b889a12da5ad4039879168949b2bdbcb525dd |