fileloc

Contents

fileloc#

tollan.utils.fileloc.fileloc(loc: str | Path | tuple[str, str] | dict | FileLoc, remote_parent_path: None | str | Path = None, local_parent_path: None | str | Path = None, *, revalidate: bool = False) FileLoc[source]#

Return a validated FileLoc object.

Parameters:
  • loc (str, Path, tuple, dict, FileLoc) –

    The file location, either remote or local. It can take the form of the follows:

    • URL format string. This is parsed as URL.

    • Non-URL format string. In this case, loc is interpreted as a local path, or a remote path similar to sftp syntax: <hostname>:<abspath>. A remote relative path is not valid.

    • Path. It is a local path.

    • Tuple of (<hostname>, <path>). It is a remote path, unless hostname is “localhost”. A remote relative path is not valid.

    • FileLoc. It is used as-is if revalidate is false, and re-validated with the data attribute otherwise.

  • local_parent_path (str, Path, None) – If not None, this is used as the parent of local relative path. Otherwise, the current path (pwd) is used. Ignored if loc is FileLoc.

  • remote_parent_path (str, Path, None) – If not None and is absolute, this is used as the parent of remote relative path. Otherwise, ValueError will be raised if a remote relative path is given. Ignored if loc is FileLoc.

  • revalidate (bool) – If True and loc is FileLoc object, the data gets re-validated with new context.