to_abspath

Contents

to_abspath#

to_abspath(raw_path: Union[str, CloudPath, Path], create: bool = True, raise_file_not_found: bool = True) Union[CloudPath, Path][source]#

Return the absolute path of the specified path and check if it exists

If not:

  • If it is a file (aka has an extension), it raises an exception

  • If it is a folder, it creates it

To be used with argparse to retrieve the absolute path of a file, like:

>>> parser = argparse.ArgumentParser()
>>> # Add config file path key
>>> parser.add_argument("--config",
                        help="Config file path (absolute or relative)",
                        type=to_abspath)
Parameters:
  • raw_path (AnyPathStrType) – Path as a string (relative or absolute)

  • create (bool) – Create directory if not existing

Returns:

Absolute path

Return type:

AnyPathType