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
untilTree.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 onegz
.{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).
- local¶
Same as
Tree.shared
, but from a tree point of view: seeget_tree_view()
.
- prune(path: Path | str | Tuple[str])[source]¶
Remove a file.
Argument can be either:
a
pathlib.Path
,a
tuple
,or a
str
(which would be converted to apathlib.Path
.
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.
- vcs: plugins.vcs.VCS¶
VCS plugin
File
¶
- class evariste.tree.File(path: Path, *, parent: Directory | None = None)[source]¶
A 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).
- 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.