readable_dir

yoda_powers.toolbox.readable_dir(prospective_dir)[source]

‘Type’ for argparse - checks that directory exists and if readable, then return the absolute path as PosixPath() with pathlib

Notes

function need modules:

  • pathlib

  • argparse

Parameters

prospective_dir (str) – a path to existent path

Returns

Path(path).resolve()

Return type

PosixPath

Raises
  • ArgumentTypeError – If directory path does not exist.

  • ArgumentTypeError – If path is not a valid directory.

Examples

>>> import argparse
>>> parser = argparse.ArgumentParser(prog='test.py', description='''This is demo''')
>>> parser.add_argument('-f', '--file', metavar="<path/to/file>",type=readable_dir, required=True,
    dest='path_file', help='path to file')