makejinja 2.3.2__tar.gz → 2.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {makejinja-2.3.2 → makejinja-2.3.4}/PKG-INFO +4 -3
- {makejinja-2.3.2 → makejinja-2.3.4}/README.md +2 -2
- {makejinja-2.3.2 → makejinja-2.3.4}/makejinja/__init__.py +2 -0
- {makejinja-2.3.2 → makejinja-2.3.4}/makejinja/app.py +26 -10
- {makejinja-2.3.2 → makejinja-2.3.4}/makejinja/cli.py +1 -0
- {makejinja-2.3.2 → makejinja-2.3.4}/makejinja/config.py +4 -4
- {makejinja-2.3.2 → makejinja-2.3.4}/pyproject.toml +1 -1
- {makejinja-2.3.2 → makejinja-2.3.4}/LICENSE +0 -0
- {makejinja-2.3.2 → makejinja-2.3.4}/makejinja/__main__.py +0 -0
- {makejinja-2.3.2 → makejinja-2.3.4}/makejinja/loader.py +0 -0
- {makejinja-2.3.2 → makejinja-2.3.4}/makejinja/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: makejinja
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.4
|
|
4
4
|
Summary: makejinja is a CLI tool and Python library to automatically generate files from Jinja2 templates. Use it to easily generate complex Home Assistant dashboards!
|
|
5
5
|
Home-page: https://mirkolenz.github.io/makejinja/
|
|
6
6
|
License: MIT
|
|
@@ -19,6 +19,7 @@ Classifier: Natural Language :: English
|
|
|
19
19
|
Classifier: Operating System :: OS Independent
|
|
20
20
|
Classifier: Programming Language :: Python :: 3
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
23
|
Classifier: Topic :: File Formats
|
|
23
24
|
Classifier: Topic :: Home Automation
|
|
24
25
|
Classifier: Topic :: Software Development :: Code Generators
|
|
@@ -39,7 +40,7 @@ Description-Content-Type: text/markdown
|
|
|
39
40
|
|
|
40
41
|
<!-- markdownlint-disable MD033 MD041 -->
|
|
41
42
|
<p align="center">
|
|
42
|
-
<img width="256px" src="https://raw.githubusercontent.com/mirkolenz/makejinja/main/assets/logo.png" />
|
|
43
|
+
<img width="256px" alt="makejinja logo" src="https://raw.githubusercontent.com/mirkolenz/makejinja/main/assets/logo.png" />
|
|
43
44
|
</p>
|
|
44
45
|
<p align="center">
|
|
45
46
|
<a href="https://pypi.org/project/makejinja/">PyPI</a> |
|
|
@@ -96,7 +97,7 @@ You can then directly invoke the app as follows:
|
|
|
96
97
|
|
|
97
98
|
### Nix
|
|
98
99
|
|
|
99
|
-
If you use the `nix` package manager, you can add this repository as an input to your flake and use `makejinja.packages.${system}.default`.
|
|
100
|
+
If you use the `nix` package manager, you can add this repository as an input to your flake and use `makejinja.packages.${system}.default` or apply the overlay `makejinja.overlays.default`.
|
|
100
101
|
You can also run it directly
|
|
101
102
|
|
|
102
103
|
`nix run github:mirkolenz/makejinja -- -i ./input -o ./output`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
2
|
<p align="center">
|
|
3
|
-
<img width="256px" src="https://raw.githubusercontent.com/mirkolenz/makejinja/main/assets/logo.png" />
|
|
3
|
+
<img width="256px" alt="makejinja logo" src="https://raw.githubusercontent.com/mirkolenz/makejinja/main/assets/logo.png" />
|
|
4
4
|
</p>
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://pypi.org/project/makejinja/">PyPI</a> |
|
|
@@ -57,7 +57,7 @@ You can then directly invoke the app as follows:
|
|
|
57
57
|
|
|
58
58
|
### Nix
|
|
59
59
|
|
|
60
|
-
If you use the `nix` package manager, you can add this repository as an input to your flake and use `makejinja.packages.${system}.default`.
|
|
60
|
+
If you use the `nix` package manager, you can add this repository as an input to your flake and use `makejinja.packages.${system}.default` or apply the overlay `makejinja.overlays.default`.
|
|
61
61
|
You can also run it directly
|
|
62
62
|
|
|
63
63
|
`nix run github:mirkolenz/makejinja -- -i ./input -o ./output`
|
|
@@ -45,9 +45,11 @@ def makejinja(config: Config):
|
|
|
45
45
|
# Save rendered files to avoid duplicate work
|
|
46
46
|
# Even if two files are in two separate folders, they will have the same template name (i.e., relative path)
|
|
47
47
|
# and thus only the first one will be rendered every time
|
|
48
|
-
|
|
48
|
+
# Key: output_path, Value: input_path
|
|
49
|
+
rendered_files: dict[Path, Path] = {}
|
|
49
50
|
|
|
50
51
|
# Save rendered folders to later copy metadata
|
|
52
|
+
# Key: output_path, Value: input_path
|
|
51
53
|
rendered_folders: dict[Path, Path] = {}
|
|
52
54
|
|
|
53
55
|
for user_input_path in config.inputs:
|
|
@@ -58,10 +60,24 @@ def makejinja(config: Config):
|
|
|
58
60
|
user_input_path, config, env, rendered_files, rendered_folders
|
|
59
61
|
)
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
postprocess_rendered_folders(config, rendered_folders)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def postprocess_rendered_folders(
|
|
67
|
+
config: Config,
|
|
68
|
+
rendered_folders: abc.Mapping[Path, Path],
|
|
69
|
+
) -> None:
|
|
70
|
+
# Start with the deepest folder and work our way up, otherwise the statistics could be modified after copying
|
|
71
|
+
for output_path, input_path in sorted(
|
|
72
|
+
rendered_folders.items(), key=lambda x: x[0], reverse=True
|
|
73
|
+
):
|
|
74
|
+
if not config.keep_empty and not any(output_path.iterdir()):
|
|
75
|
+
if not config.quiet:
|
|
76
|
+
print(f"Remove empty '{output_path}'")
|
|
77
|
+
|
|
78
|
+
shutil.rmtree(output_path)
|
|
79
|
+
|
|
80
|
+
elif config.copy_metadata:
|
|
65
81
|
if not config.quiet:
|
|
66
82
|
print(f"Copy metadata '{input_path}' -> '{output_path}'")
|
|
67
83
|
|
|
@@ -82,7 +98,7 @@ def handle_input_file(
|
|
|
82
98
|
input_path: Path,
|
|
83
99
|
config: Config,
|
|
84
100
|
env: Environment,
|
|
85
|
-
rendered_files: abc.
|
|
101
|
+
rendered_files: abc.MutableMapping[Path, Path],
|
|
86
102
|
) -> None:
|
|
87
103
|
relative_path = Path(input_path.name)
|
|
88
104
|
output_path = generate_output_path(config, relative_path)
|
|
@@ -97,14 +113,14 @@ def handle_input_file(
|
|
|
97
113
|
enforce_jinja_suffix=False,
|
|
98
114
|
)
|
|
99
115
|
|
|
100
|
-
rendered_files
|
|
116
|
+
rendered_files[output_path] = input_path
|
|
101
117
|
|
|
102
118
|
|
|
103
119
|
def handle_input_folder(
|
|
104
120
|
user_input_path: Path,
|
|
105
121
|
config: Config,
|
|
106
122
|
env: Environment,
|
|
107
|
-
rendered_files: abc.
|
|
123
|
+
rendered_files: abc.MutableMapping[Path, Path],
|
|
108
124
|
rendered_folders: abc.MutableMapping[Path, Path],
|
|
109
125
|
) -> None:
|
|
110
126
|
input_paths = (
|
|
@@ -130,7 +146,7 @@ def handle_input_folder(
|
|
|
130
146
|
env,
|
|
131
147
|
enforce_jinja_suffix=True,
|
|
132
148
|
)
|
|
133
|
-
rendered_files
|
|
149
|
+
rendered_files[output_path] = input_path
|
|
134
150
|
|
|
135
151
|
elif input_path.is_dir() and output_path not in rendered_folders:
|
|
136
152
|
if not config.quiet:
|
|
@@ -280,7 +296,7 @@ def load_data(config: Config) -> dict[str, Any]:
|
|
|
280
296
|
if not config.quiet:
|
|
281
297
|
print(f"Skip unsupported data '{path}'")
|
|
282
298
|
|
|
283
|
-
for key, value in config.data_vars:
|
|
299
|
+
for key, value in config.data_vars.items():
|
|
284
300
|
dict_nested_set(data, key, value)
|
|
285
301
|
|
|
286
302
|
return data
|
|
@@ -31,6 +31,7 @@ def makejinja_cli(config: Config):
|
|
|
31
31
|
**Note**: In this file, options may be named differently.
|
|
32
32
|
Please refer to the file [`makejinja/config.py`](https://github.com/mirkolenz/makejinja/blob/main/makejinja/config.py) to see their actual names.
|
|
33
33
|
You will also find an example here: [`makejinja/tests/data/makejinja.toml`](https://github.com/mirkolenz/makejinja/blob/main/tests/data/makejinja.toml).
|
|
34
|
+
To override its location, you can set the environment variable `MAKEJINJA_SETTINGS` to the path of your config file.
|
|
34
35
|
"""
|
|
35
36
|
|
|
36
37
|
makejinja(config)
|
|
@@ -246,8 +246,8 @@ class Config:
|
|
|
246
246
|
},
|
|
247
247
|
help="""
|
|
248
248
|
Load variables from yaml/yml/toml/json files for use in your Jinja templates.
|
|
249
|
-
The
|
|
250
|
-
Can either be a file or a folder
|
|
249
|
+
The definitions are passed to Jinja as globals.
|
|
250
|
+
Can either be a file or a folder containing files.
|
|
251
251
|
**Note:** This option may be passed multiple times to pass a list of values.
|
|
252
252
|
If multiple files are supplied, beware that previous declarations will be overwritten by newer ones.
|
|
253
253
|
""",
|
|
@@ -274,9 +274,9 @@ class Config:
|
|
|
274
274
|
Use custom Python code to adjust the used Jinja environment to your needs.
|
|
275
275
|
The specified Python file should export a **class** containing a subset of the following functions:
|
|
276
276
|
`filters`, `globals`, `data`, and `extensions`.
|
|
277
|
-
In addition, you may add an `__init__` function that
|
|
277
|
+
In addition, you may add an `__init__` function that receives two positional arguments:
|
|
278
278
|
the created Jinja environment and the data parsed from the files supplied to makejinja's `data` option.
|
|
279
|
-
This allows you to apply
|
|
279
|
+
This allows you to apply arbitrary logic to makejinja.
|
|
280
280
|
An import path can be specified either in dotted notation (`your.custom.Loader`)
|
|
281
281
|
or with a colon as object delimiter (`your.custom:Loader`).
|
|
282
282
|
**Note:** This option may be passed multiple times to pass a list of values.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "makejinja"
|
|
3
|
-
version = "2.3.
|
|
3
|
+
version = "2.3.4"
|
|
4
4
|
description = "makejinja is a CLI tool and Python library to automatically generate files from Jinja2 templates. Use it to easily generate complex Home Assistant dashboards!"
|
|
5
5
|
authors = ["Mirko Lenz <mirko@mirkolenz.com>"]
|
|
6
6
|
license = "MIT"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|