filesystem#

is_hidden(path: str) bool#
max_name_length() int#
which(*args: str, path: str | list[str] | tuple[str, ...] | None = None, required: Literal[True]) str#
which(*args: str, path: str | list[str] | tuple[str, ...] | None = None, required: Literal[False] = False) str | None

Finds an executable in the path like command-line which.

If given multiple executables, returns the first one that is found. If no executables are found, returns None.

Parameters:
  • args – One or more executables to search for

  • path – The path to search. Defaults to PATH

  • required (bool) – If set to True, raise an error if executable not found

Returns:

The first executable that is found in the path

Return type:

exe

copyfile(src: str, dst: str) None#

Copy file src to dst

movefile(src: str, dst: str) None#

Move file src to dst

filesystem_root(root: str, sigil: str = '@') str#

Return the path after sigil if there is a partitioning

synctree(src: str, dst: str, ignore: str | list | tuple | None = None, delete: bool = False, verbose: bool = False, **kwargs: Any)#

Sync source directory src with destination directory dst

force_remove(file_or_dir: Path | str) None#

Remove file_or_dir forcefully

force_copy(src: str, dst: str) None#

Forcefully copy src to dst

remove(file_or_dir: Path | str) None#

Removes file or directory file_or_dir

rmtree2(path: Path | str, n: int = 5) None#

Wrapper around shutil.rmtree to make it more robust when used on NFS mounted file systems.

async_rmtree(path: Path | str) None#
getuser() str#

Return the name of the logged on user

gethost() str#

Return the host name of the machine, as reported by os.uname().nodename

getnode() str#

Return the host name of the machine, as reported by os.uname().nodename

gettempdir(user: bool = False, suffix: str | None = None) str#

Get the name of the system’s preferred temporary directory. If user is given, postfix the directory with the user name

tmpdir(remove: bool = True, suffix: str | None = None) Generator[str, None, None]#

Create a temporary directory and remove it when the context is exited

Keyword Arguments:
  • remove – remove the temporary directory when the context is exited

  • suffix – added to the end of the directory name

Examples

>>> with tmpdir():
...    # do work in temporary directory
gethome() str#

Return the home directory of the currently logged in user

filesize(filename: str, *, units: str | None = None) int#

Return filename‘s size. If units is None, the size in bytes is returned. Valid units are kilobytes, megabytes, and gigabytes.

git_revision(path: str) str#

Get the git revision at path. Equivalent to git -C path rev-parse HEAD

file_age_in_days(file: str) float#

Return the file‘s age in days

sortby_mtime(files: list[str]) list[str]#

Sort the list of files by mtime.

touch(path: str) None#

Creates an empty file at the specified path.

touchp(path: str) None#

Like touch, but creates any parent directories needed for the file.

working_dir(dirname: str | Path, create: bool = False) Generator[None, None, None]#

Context manager that changes the working directory to dirname and returns to the calling directory when the context is exited

mkdirp(*paths: str, mode: int | None = None) None#

Creates a directory, as well as parent directories if needed.

Parameters:

paths (str) – paths to create with mkdirp

Keyword Aguments:
mode (permission bits or None, optional): optional permissions to

set on the created directory – use OS default if not provided

set_executable(path: Path | str) None#

Set executable bits on path

is_exe(path: str) bool#

True if path is an executable file.

Forcefully create a symbolic link from src to dest

accessible(file_name: str) bool#

True if we have read/write access to the file.

readable(file_name: str) bool#

True if we have read access to the file.

writeable(file_name: str) bool#

True if we have write access to the file.

chgrp(path: str, group: str) None#

Implement the bash chgrp function on a single path

chmod_x(entry: str, perms: int) None#

Implements chmod, treating all executable bits as set using the chmod utility’s +X option.

samepath(path1: str, path2: str) bool#

Does path1 point to the same path as path2?

ancestor(dir: str, n: int = 1) str#

Get the nth ancestor of a directory.

grep(regex: str | Pattern, file: Path | str) bool#
find_work_tree(start: str | None = None) str | None#
clean_out_folder(folder: str) None#
write_directory_tag(file: Path | str) None#
atomic_write(path: Path, text: str) None#