You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""the central build context and configuration options"""
2
+
3
+
importlogging
4
+
importre
5
+
importshutil
6
+
7
+
frompathlibimportPath
8
+
9
+
fromjinja2importEnvironment, FileSystemLoader
10
+
11
+
from .utilsimportis_html
12
+
13
+
14
+
log=logging.getLogger(__name__)
15
+
16
+
17
+
classContext:
18
+
"""Collects shared configuration and simple methods for determining which files/directories to watch. There should only be one instance of this during the program's lifeycle."""
"""Initializer, creates a new `Context`. For best results, all `Path` type arguments should be absolute (this is automatically done in the initializer, but if you want to change the properties after initializing, make sure you do this).
24
+
25
+
Args:
26
+
input_dir (Path, optional): The directory to watch for changes. Defaults to Path(".").
27
+
output_dir (Path, optional): The directory to save generated files. Defaults to Path("out").
28
+
template_dir (str, optional): The directory containing jinja2 mixin-type templates. If it exists, this is the name of a folder under `input_dir`. Defaults to "templates".
29
+
ignore_list (set[Path], optional): The set of directories to ignore (will not be watched, even if `input_dir` is a parent folder). Defaults to set().
30
+
dev_mode (bool, optional): Flag which turns on development mode (i.e. livereload server). Defaults to False.
"""Convenience method, gets the path stub of `f` relative to `self.input_dir`. Useful for determining the path of the file in the output directory (`self.output_dir`).
53
+
54
+
Args:
55
+
f (Path): The file `Path` to get an output stub for.
56
+
57
+
Returns:
58
+
Path: The output path of `f` relative to `self.input_dir`.
59
+
"""
60
+
returnf.relative_to(self.input_dir)
61
+
62
+
defis_template(self, f: Path) ->bool:
63
+
"""Convienience method, determines whether a file is a template (i.e. in the `self.template_dir` directory)
64
+
65
+
Args:
66
+
f (Path): The file to check. Use an absolute `Path` for best results.
67
+
68
+
Returns:
69
+
bool: `True` if `f` is a template in the `self.template_dir` directory.
70
+
"""
71
+
returnself.template_dirinf.parentsandis_html(f)
72
+
73
+
defis_config_json(self, f: Path) ->bool:
74
+
"""Convienience method, determines whether `f` is the `config.json` file.
75
+
76
+
Args:
77
+
f (Path): The file to check. Use an absolute `Path` for best results.
78
+
79
+
Returns:
80
+
bool: `True` if `f` is the `config.json` file.
81
+
"""
82
+
returnf==self.config_json
83
+
84
+
defshould_watch_file(self, p: str) ->bool:
85
+
"""Determines whether a file should be watched.
86
+
87
+
Args:
88
+
entry (str): The path to the file to check. Must be a full path.
0 commit comments