dycw-utilities 0.166.34__py3-none-any.whl → 0.166.35__py3-none-any.whl
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.
Potentially problematic release.
This version of dycw-utilities might be problematic. Click here for more details.
- {dycw_utilities-0.166.34.dist-info → dycw_utilities-0.166.35.dist-info}/METADATA +1 -1
- {dycw_utilities-0.166.34.dist-info → dycw_utilities-0.166.35.dist-info}/RECORD +7 -7
- utilities/__init__.py +1 -1
- utilities/jinja2.py +36 -3
- {dycw_utilities-0.166.34.dist-info → dycw_utilities-0.166.35.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.166.34.dist-info → dycw_utilities-0.166.35.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.166.34.dist-info → dycw_utilities-0.166.35.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
utilities/__init__.py,sha256=
|
|
1
|
+
utilities/__init__.py,sha256=PT1CZ7q5mXp5sGpg_AzIq7I1KdWZaz7zxPLtwU6uO0o,61
|
|
2
2
|
utilities/aeventkit.py,sha256=ddoleSwW9zdc2tjX5Ge0pMKtYwV_JMxhHYOxnWX2AGM,12609
|
|
3
3
|
utilities/altair.py,sha256=nHdpWt8ZwdUwRQN970MvHd5bRWokNqzHcZQEdSHKRuE,9033
|
|
4
4
|
utilities/asyncio.py,sha256=60l1IwjnRGeaVphAFiwDIHyfKoZYKY-XGpptUxGiU-M,17034
|
|
@@ -28,7 +28,7 @@ utilities/importlib.py,sha256=mV1xT_O_zt_GnZZ36tl3xOmMaN_3jErDWY54fX39F6Y,429
|
|
|
28
28
|
utilities/inflect.py,sha256=v7YkOWSu8NAmVghPcf4F3YBZQoJCS47_DLf9jbfWIs0,581
|
|
29
29
|
utilities/ipython.py,sha256=V2oMYHvEKvlNBzxDXdLvKi48oUq2SclRg5xasjaXStw,763
|
|
30
30
|
utilities/iterables.py,sha256=t2TsW-K3rVlS6y4_tqcc1fk9RwJV-bi7G_VwduMABK0,42558
|
|
31
|
-
utilities/jinja2.py,sha256=
|
|
31
|
+
utilities/jinja2.py,sha256=LjTeSafagqgNv_MKpRRUBTFwmAzayNnCAejmw8x9xH0,3804
|
|
32
32
|
utilities/json.py,sha256=-WcGtSsCr9Y42wHZzAMnfvU6ihAfVftylFfRUORaDFo,2102
|
|
33
33
|
utilities/jupyter.py,sha256=ft5JA7fBxXKzP-L9W8f2-wbF0QeYc_2uLQNFDVk4Z-M,2917
|
|
34
34
|
utilities/libcst.py,sha256=ngD4wxnR3Kh-RBVmU5l5ST7cuZLhMZwyMDjHZe5mhTs,5581
|
|
@@ -92,8 +92,8 @@ utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
|
|
|
92
92
|
utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
|
93
93
|
utilities/pytest_plugins/pytest_randomly.py,sha256=B1qYVlExGOxTywq2r1SMi5o7btHLk2PNdY_b1p98dkE,409
|
|
94
94
|
utilities/pytest_plugins/pytest_regressions.py,sha256=mnHYBfdprz50UGVkVzV1bZERZN5CFfoF8YbokGxdFwU,1639
|
|
95
|
-
dycw_utilities-0.166.
|
|
96
|
-
dycw_utilities-0.166.
|
|
97
|
-
dycw_utilities-0.166.
|
|
98
|
-
dycw_utilities-0.166.
|
|
99
|
-
dycw_utilities-0.166.
|
|
95
|
+
dycw_utilities-0.166.35.dist-info/METADATA,sha256=cA7U8NTIDwvrLpRoVpo6Cvmr-Zvnyjjnr6vf8ahQRB8,1699
|
|
96
|
+
dycw_utilities-0.166.35.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
97
|
+
dycw_utilities-0.166.35.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
|
|
98
|
+
dycw_utilities-0.166.35.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
|
99
|
+
dycw_utilities-0.166.35.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/jinja2.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Literal, assert_never, override
|
|
4
5
|
|
|
5
|
-
from jinja2 import BaseLoader, BytecodeCache, Environment, Undefined
|
|
6
|
+
from jinja2 import BaseLoader, BytecodeCache, Environment, FileSystemLoader, Undefined
|
|
6
7
|
from jinja2.defaults import (
|
|
7
8
|
BLOCK_END_STRING,
|
|
8
9
|
BLOCK_START_STRING,
|
|
@@ -18,13 +19,17 @@ from jinja2.defaults import (
|
|
|
18
19
|
VARIABLE_START_STRING,
|
|
19
20
|
)
|
|
20
21
|
|
|
22
|
+
from utilities.atomicwrites import writer
|
|
21
23
|
from utilities.text import pascal_case, snake_case
|
|
22
24
|
|
|
23
25
|
if TYPE_CHECKING:
|
|
24
26
|
from collections.abc import Callable, Sequence
|
|
27
|
+
from pathlib import Path
|
|
25
28
|
|
|
26
29
|
from jinja2.ext import Extension
|
|
27
30
|
|
|
31
|
+
from utilities.types import StrMapping
|
|
32
|
+
|
|
28
33
|
|
|
29
34
|
class EnhancedEnvironment(Environment):
|
|
30
35
|
"""Environment with enhanced features."""
|
|
@@ -83,4 +88,32 @@ class EnhancedEnvironment(Environment):
|
|
|
83
88
|
self.filters["pascal"] = pascal_case
|
|
84
89
|
|
|
85
90
|
|
|
86
|
-
|
|
91
|
+
@dataclass(order=True, unsafe_hash=True, kw_only=True, slots=True)
|
|
92
|
+
class TemplateJob:
|
|
93
|
+
"""A template with an associated rendering job."""
|
|
94
|
+
|
|
95
|
+
template: Path
|
|
96
|
+
kwargs: StrMapping
|
|
97
|
+
target: Path
|
|
98
|
+
mode: Literal["write", "append"] = "write"
|
|
99
|
+
|
|
100
|
+
def run(self) -> None:
|
|
101
|
+
"""Run the job."""
|
|
102
|
+
match self.mode:
|
|
103
|
+
case "write":
|
|
104
|
+
with writer(self.target, overwrite=True) as temp:
|
|
105
|
+
_ = temp.write_text(self.rendered)
|
|
106
|
+
case "append":
|
|
107
|
+
with self.target.open(mode="a") as fh:
|
|
108
|
+
_ = fh.write(self.rendered)
|
|
109
|
+
case never:
|
|
110
|
+
assert_never(never)
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def rendered(self) -> str:
|
|
114
|
+
"""The template, rendered."""
|
|
115
|
+
env = EnhancedEnvironment(loader=FileSystemLoader(self.template.parent))
|
|
116
|
+
return env.get_template(self.template.name).render(self.kwargs)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
__all__ = ["EnhancedEnvironment", "TemplateJob"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|