evariste.tree

Directory representation and compilation.

A Tree is an abstract class representing a directory structure (a directory with files and nested directories). Its implementations are:

Tree

class evariste.tree.Tree(path: Path, *, parent: Directory | None = None)[source]

A file system tree.

A directory, that contains files and has subdirectories.

Parameters:
  • path (pathlib.Path) – Relative path (relative to the root of this tree).

  • parent (Optional[Directory]) – Directory containing this file or directory.

basename: pathlib.Path

Name of the tree (path, relative to its Tree.parent).

config: Union[utils.DeepDict, None]

Computed configuration for this file. See Per-file and per-directory configuration files. Note: This attribute is None until Tree.set_config() has been called.

count(dirs: bool = False, files: bool = True) int[source]

Count the number of files or directories in this tree.

property depth: int

Return the depth of the path.

The root has depth 0, and depth of each path is one more than the depth of its parent.

find(path: str | Path | Tuple[str]) Tree | False[source]

Return the tree object corresponding to path if it exists; False otherwise.

Argument can be:

  • a string (str);

  • a pathlib.Path object;

  • a tuple of strings, as a list of directories and (optional) final file.

format(string: str) str[source]

Format given string, with several variables related to self.

Here are the replacements (with example /home/louis/repo/foo/bar.txt):

  • {dirname} (/home/louis/repo/foo): the name of the directory. Note that most of the time, this is useless, since when compiling a file, the working directory is the directory of this file (i.e. {dirname}).

  • {filename} (bar.txt): The file name (without directory).

  • {fullname} (/home/louis/repo/foo/bar.txt): The file name (with directory).

  • {extension} (txt): The extension (without the dot). If the file has several extensions (e.g. foo.tar.gz), this is only the last one gz.

  • {basename} (bar): The file name, without directory and extension.

from_fs: pathlib.Path

Absolute path

from_source: pathlib.Path

Path, relative to the Root.

abstract full_depends() Iterable[Path][source]

Iterate over all dependencies of this tree (recursively for directories).

is_dir() bool[source]

Return True iff self is a directory.

is_file() bool[source]

Return True iff self is a file.

static is_root()[source]

Return True iff self is the root.

local

Same as Tree.shared, but from a tree point of view: see get_tree_view().

parent: Union[Tree, None]

Parent directory (copied from constructor argument).

prune(path: Path | str | Tuple[str])[source]

Remove a file.

Argument can be either:

If called with a non-existing path, does nothing.

property relativename: Path

Return a relative name.

  • For root, return path relative to file system (or directory of setup file).

  • For non-root, return path relative to parent (i.e. basename of path).

report: Union[plugins.action.Report, None]

Once the file has been compiled, the report (compilation log, if any) is saved here.

property root: Root

Return the root of the tree.

shared: Shared

Common data shared with every Tree and Plugin of this Builder.

vcs: plugins.vcs.VCS

VCS plugin

walk(dirs: bool = False, files: bool = True) Iterable[Tree][source]

Iterator over itself.

File

class evariste.tree.File(path: Path, *, parent: Directory | None = None)[source]

A file

compile()[source]

Compile file.

depends() Iterable[Path][source]

Iterator over dependencies of this file (but not the file itself).

full_depends() Iterable[Path][source]

Iterate over all dependencies of this tree (recursively for directories).

last_modified() datetime[source]

Return the last modified date and time of self.

make_archive(destdir: Path) Path[source]

Make an archive of self and its dependency.

Steps are:

  • build the archive;

  • copy it to destdir;

  • return the path of the archive, relative to destdir.

If self has no dependencies, consider the file as an archive.

It can be called several times: the archive will be built only once.

Directory

class evariste.tree.Directory(*args, **kwargs)[source]
__contains__(key: str) bool[source]

Return True if key (a single file name or directory) is in this directory.

__delitem__(item: str)[source]

Remove a subfile or subdirectory.

If, after deletion, self is an empty directory (and is not root), self is remove from its parent.

__getitem__(key: str) Tree[source]

Return subfile or subdirectory self.from_fs / key.

If it does not exist, it is created first.

__iter__() Iterable[str][source]

Iterate over subpaths (this function is not recursive).

add_subpath(sub: List[Path])[source]

Add a path to the tree (relative to self).

compile()[source]

Compile directory.

full_depends() Iterable[Path][source]

Iterate over all dependencies of this tree (recursively for directories).

keys() Iterable[str][source]

Iterator over subpaths (as str objects).

values() Iterable[Tree][source]

Iterator over subpaths (as Tree objects).

walk(dirs: bool = False, files: bool = True) Iterable[Tree][source]

Iterator over files or directories of self.

Parameters:
  • dirs (bool) – If False, do not yield directories.

  • files (bool) – If False, do not yield files.

Directories are yielded before subfiles and subdirectories.

Root

class evariste.tree.Root(path, *, vcs=None, shared=None)[source]

Root object (directory with no parents).

classmethod from_vcs(repository: VCS) Root[source]

Return a directory, fully set.

static is_root() bool[source]

Return True iff self is the root.

root_compile()[source]

Recursively compile files..

set_config()[source]

Compute the configuration of each file of the tree.

That is:

  • look for the file that configure it (typically foo.evsconfig is the configuration for file foo),

  • load it,

  • and complete it using the recursive configuration of parent directories.