jinja-types 0.1.0__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.
Files changed (45) hide show
  1. jinja_types-0.1.0/LICENSE +21 -0
  2. jinja_types-0.1.0/PKG-INFO +162 -0
  3. jinja_types-0.1.0/README.md +126 -0
  4. jinja_types-0.1.0/pyproject.toml +120 -0
  5. jinja_types-0.1.0/pyproject.toml.orig +86 -0
  6. jinja_types-0.1.0/src/jinja_types/__init__.py +38 -0
  7. jinja_types-0.1.0/src/jinja_types/cli.py +53 -0
  8. jinja_types-0.1.0/src/jinja_types/contrib/__init__.py +1 -0
  9. jinja_types-0.1.0/src/jinja_types/contrib/babel.py +245 -0
  10. jinja_types-0.1.0/src/jinja_types/core/__init__.py +36 -0
  11. jinja_types-0.1.0/src/jinja_types/core/catalog.py +175 -0
  12. jinja_types-0.1.0/src/jinja_types/core/collection.py +237 -0
  13. jinja_types-0.1.0/src/jinja_types/core/errors.py +42 -0
  14. jinja_types-0.1.0/src/jinja_types/core/invoker.py +204 -0
  15. jinja_types-0.1.0/src/jinja_types/core/namespace.py +21 -0
  16. jinja_types-0.1.0/src/jinja_types/core/options.py +28 -0
  17. jinja_types-0.1.0/src/jinja_types/core/plugins.py +46 -0
  18. jinja_types-0.1.0/src/jinja_types/core/registry.py +192 -0
  19. jinja_types-0.1.0/src/jinja_types/core/spec.py +52 -0
  20. jinja_types-0.1.0/src/jinja_types/extension.py +84 -0
  21. jinja_types-0.1.0/src/jinja_types/helpers/__init__.py +8 -0
  22. jinja_types-0.1.0/src/jinja_types/helpers/convert.py +248 -0
  23. jinja_types-0.1.0/src/jinja_types/helpers/globals.py +133 -0
  24. jinja_types-0.1.0/src/jinja_types/py.typed +0 -0
  25. jinja_types-0.1.0/src/jinja_types/regex/__init__.py +1 -0
  26. jinja_types-0.1.0/src/jinja_types/regex/engine.py +64 -0
  27. jinja_types-0.1.0/src/jinja_types/regex/match_.py +121 -0
  28. jinja_types-0.1.0/src/jinja_types/regex/pattern_.py +165 -0
  29. jinja_types-0.1.0/src/jinja_types/regex/re_.py +170 -0
  30. jinja_types-0.1.0/src/jinja_types/types/__init__.py +41 -0
  31. jinja_types-0.1.0/src/jinja_types/types/ar_.py +354 -0
  32. jinja_types-0.1.0/src/jinja_types/types/bool_.py +12 -0
  33. jinja_types-0.1.0/src/jinja_types/types/date_.py +137 -0
  34. jinja_types-0.1.0/src/jinja_types/types/datetime_.py +267 -0
  35. jinja_types-0.1.0/src/jinja_types/types/decimal_.py +450 -0
  36. jinja_types-0.1.0/src/jinja_types/types/dict_.py +116 -0
  37. jinja_types-0.1.0/src/jinja_types/types/float_.py +53 -0
  38. jinja_types-0.1.0/src/jinja_types/types/fraction_.py +86 -0
  39. jinja_types-0.1.0/src/jinja_types/types/int_.py +102 -0
  40. jinja_types-0.1.0/src/jinja_types/types/list_.py +138 -0
  41. jinja_types-0.1.0/src/jinja_types/types/path_.py +190 -0
  42. jinja_types-0.1.0/src/jinja_types/types/str_.py +406 -0
  43. jinja_types-0.1.0/src/jinja_types/types/time_.py +120 -0
  44. jinja_types-0.1.0/src/jinja_types/types/timedelta_.py +34 -0
  45. jinja_types-0.1.0/src/jinja_types/types/uuid_.py +126 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 aaltatan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: jinja-types
3
+ Version: 0.1.0
4
+ Summary: Python type methods and attributes as qualified Jinja2 filters and tests.
5
+ Keywords: jinja2,jinja,filters,templates,sandbox,decimal,dates,regex,arabic
6
+ Author: aaltatan
7
+ Author-email: aaltatan <a.altatan@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Text Processing :: Markup
18
+ Classifier: Typing :: Typed
19
+ Requires-Dist: arapy>=0.1.0
20
+ Requires-Dist: jinja2>=3.1
21
+ Requires-Dist: babel ; extra == 'babel'
22
+ Requires-Dist: arapy[hijri]>=0.1.0 ; extra == 'hijri'
23
+ Requires-Dist: regex ; extra == 'regex'
24
+ Requires-Dist: arapy[shape]>=0.1.0 ; extra == 'shape'
25
+ Requires-Python: >=3.12
26
+ Project-URL: Homepage, https://github.com/aaltatan/jinja-types
27
+ Project-URL: Repository, https://github.com/aaltatan/jinja-types
28
+ Project-URL: Issues, https://github.com/aaltatan/jinja-types/issues
29
+ Project-URL: Changelog, https://github.com/aaltatan/jinja-types/blob/main/CHANGELOG.md
30
+ Project-URL: Documentation, https://github.com/aaltatan/jinja-types/tree/main/docs
31
+ Provides-Extra: babel
32
+ Provides-Extra: hijri
33
+ Provides-Extra: regex
34
+ Provides-Extra: shape
35
+ Description-Content-Type: text/markdown
36
+
37
+ # jinja-types
38
+
39
+ `jinja-types` is a Jinja2 extension that exposes the methods and attributes of everyday Python
40
+ types (`str`, `int`, `float`, `bool`, `Decimal`, `Fraction`, `date`, `datetime`, `time`,
41
+ `timedelta`, `list`, `dict`, `UUID`, `PurePath`) and the `re` module as Jinja filters and tests.
42
+ Names and parameters match Python exactly, everything works in `ImmutableSandboxedEnvironment`,
43
+ and a registry makes it easy to plug in new filter sets.
44
+
45
+ ## Setup
46
+
47
+ Add jinja-types as an extension on your environment:
48
+
49
+ ```python
50
+ from jinja2.sandbox import ImmutableSandboxedEnvironment
51
+
52
+ from jinja_types import TypesExtension
53
+
54
+ env = ImmutableSandboxedEnvironment(extensions=[TypesExtension])
55
+
56
+ # with options: none_passthrough, coerce, regex_timeout, locale, registry
57
+ env = ImmutableSandboxedEnvironment(
58
+ extensions=[TypesExtension.configure(none_passthrough=True, locale="ar_SY")],
59
+ )
60
+ ```
61
+
62
+ The string `"jinja_types.TypesExtension"` works too, wherever Jinja takes extension names.
63
+
64
+ ## Qualified names only
65
+
66
+ Every type member is reachable only as `namespace.member`, so nothing clashes with Jinja's
67
+ built-in filters (`count`, `format`, `join`, `replace`, …):
68
+
69
+ ```jinja
70
+ {{ code | str.zfill(5) }}
71
+ {{ amount | decimal.quantize(decimal.Decimal("0.01")) }}
72
+ {{ invoice_date | date.strftime("%d/%m/%Y") }}
73
+ {% if code is str.isdigit %}…{% endif %}
74
+ ```
75
+
76
+ Helpers that are not type members use plain names: `fmt`, `to_int`, `to_decimal`, `to_date`, …
77
+
78
+ ## Example: money
79
+
80
+ Round a salary half-up to two places, then format it with thousands separators:
81
+
82
+ ```jinja
83
+ {{ salary | decimal.quantize(decimal.Decimal("0.01"), rounding=decimal.ROUND_HALF_UP) | fmt(",.2f") }}
84
+ ```
85
+
86
+ With `salary = Decimal("1500.005")` this gives `1,500.01`. The global `decimal` holds
87
+ `Decimal`, `Context` and the `ROUND_*` constants; the filter namespace `decimal.*` holds the
88
+ `Decimal` methods. `bool` is a subclass of `int`, so every `int.*` filter also accepts `true`
89
+ and `false`.
90
+
91
+ Dates work the same way. `date.*` filters also accept datetimes and call the `datetime` version
92
+ when one exists, so `{{ moment | date.isoformat(" ", "seconds") }}` works on a datetime. The
93
+ `datetime.*` namespace holds only what `datetime` adds or overrides. `datetime.astimezone` also
94
+ takes an IANA timezone name, e.g. `{{ moment | datetime.astimezone("Asia/Damascus") }}`; on
95
+ Windows, install the `tzdata` package for timezone names to resolve.
96
+
97
+ Regex filters take the string as the piped value and keep Python's parameter names:
98
+ `{{ code | re.search("abc-(\\d+)", flags=re.I) | match.group(1) }}`. Jinja string literals
99
+ process backslash escapes, so write `\\d` for the regex `\d`. `re.sub` also accepts a macro that
100
+ gets the match; under autoescape its output is kept as markup and the rest of the string is
101
+ escaped once. With the `[regex]` extra, the `regex` library is used and every call is limited
102
+ by `regex_timeout` (seconds, default 1.0).
103
+
104
+ `re.compile(pattern, flags)` returns a compiled pattern (cached); its members are the `pattern`
105
+ namespace, with the pattern piped in as in Python:
106
+
107
+ ```jinja
108
+ {% set word = re.compile("\\w+", re.I) %}
109
+ {{ word | pattern.findall(text) | join(", ") }}
110
+ {% if word is pattern.fullmatch(name) %}one word{% endif %}
111
+ ```
112
+
113
+ The full reference is in [docs/](docs/index.md), generated from the catalog. The same catalog is
114
+ available from the command line:
115
+
116
+ ```
117
+ jinja-types catalog --namespace str --format markdown
118
+ jinja-types catalog --kind test # JSON, see schema/catalog.schema.json
119
+ jinja-types conflicts --plugins
120
+ ```
121
+
122
+ To add your own filter sets as an installable plugin, see [docs/plugins.md](docs/plugins.md).
123
+
124
+ With the `[babel]` extra, `babel.*` formats numbers, money and dates for a locale. The locale
125
+ is the `locale=` argument, else `TypesExtension.configure(locale="ar_SY")`, else `en_US`:
126
+
127
+ ```jinja
128
+ {{ salary | babel.format_currency("USD") }} {# $1,234.50 (en_US) #}
129
+ {{ salary | babel.format_currency("SYP", locale="ar_SY", currency_digits=false) }} {# ‏1,234.50 ل.س.‏ #}
130
+ {{ salary | babel.format_decimal(locale="ar_SY", numbering_system="default") }} {# 1٬234٫5 #}
131
+ ```
132
+
133
+ `SYP` has no minor unit in CLDR, so `currency_digits=false` is needed to show piastres. `numbering_system="default"`
134
+ uses the locale's own separators (`٬` and `٫`); Babel keeps Latin digits either way, so
135
+ Arabic-Indic digits come from the arapy plugin.
136
+
137
+ Arabic text, numbers and dates come from [arapy](https://pypi.org/project/arapy/), a dependency,
138
+ under the `ar` namespace. arapy ships no currencies: define one in Python and pass it in:
139
+
140
+ ```python
141
+ from arapy import Currency, Gender, Noun
142
+
143
+ qirsh = Noun.create("قرش", "قرشان", "قروش", gender=Gender.MASCULINE)
144
+ syp = Currency.create(
145
+ code="SYP",
146
+ singular="ليرة سورية",
147
+ dual="ليرتان سوريتان",
148
+ plural="ليرات سورية",
149
+ gender=Gender.FEMININE,
150
+ subunit=qirsh,
151
+ symbol="ل.س",
152
+ )
153
+ ```
154
+
155
+ ```jinja
156
+ {{ salary | ar.to_words(syp) }} {# ألف وخمسمئة ليرة سورية #}
157
+ {{ salary | ar.format_money(syp) }} {# ١٬٥٠٠ ل.س #}
158
+ {{ day | ar.format_date("%A %d %B %Y", digits="arabic") }}
159
+ ```
160
+
161
+ `ar.to_hijri` needs `jinja-types[hijri]`, and `ar.shape` / `ar.reshape_only` need
162
+ `jinja-types[shape]`.
@@ -0,0 +1,126 @@
1
+ # jinja-types
2
+
3
+ `jinja-types` is a Jinja2 extension that exposes the methods and attributes of everyday Python
4
+ types (`str`, `int`, `float`, `bool`, `Decimal`, `Fraction`, `date`, `datetime`, `time`,
5
+ `timedelta`, `list`, `dict`, `UUID`, `PurePath`) and the `re` module as Jinja filters and tests.
6
+ Names and parameters match Python exactly, everything works in `ImmutableSandboxedEnvironment`,
7
+ and a registry makes it easy to plug in new filter sets.
8
+
9
+ ## Setup
10
+
11
+ Add jinja-types as an extension on your environment:
12
+
13
+ ```python
14
+ from jinja2.sandbox import ImmutableSandboxedEnvironment
15
+
16
+ from jinja_types import TypesExtension
17
+
18
+ env = ImmutableSandboxedEnvironment(extensions=[TypesExtension])
19
+
20
+ # with options: none_passthrough, coerce, regex_timeout, locale, registry
21
+ env = ImmutableSandboxedEnvironment(
22
+ extensions=[TypesExtension.configure(none_passthrough=True, locale="ar_SY")],
23
+ )
24
+ ```
25
+
26
+ The string `"jinja_types.TypesExtension"` works too, wherever Jinja takes extension names.
27
+
28
+ ## Qualified names only
29
+
30
+ Every type member is reachable only as `namespace.member`, so nothing clashes with Jinja's
31
+ built-in filters (`count`, `format`, `join`, `replace`, …):
32
+
33
+ ```jinja
34
+ {{ code | str.zfill(5) }}
35
+ {{ amount | decimal.quantize(decimal.Decimal("0.01")) }}
36
+ {{ invoice_date | date.strftime("%d/%m/%Y") }}
37
+ {% if code is str.isdigit %}…{% endif %}
38
+ ```
39
+
40
+ Helpers that are not type members use plain names: `fmt`, `to_int`, `to_decimal`, `to_date`, …
41
+
42
+ ## Example: money
43
+
44
+ Round a salary half-up to two places, then format it with thousands separators:
45
+
46
+ ```jinja
47
+ {{ salary | decimal.quantize(decimal.Decimal("0.01"), rounding=decimal.ROUND_HALF_UP) | fmt(",.2f") }}
48
+ ```
49
+
50
+ With `salary = Decimal("1500.005")` this gives `1,500.01`. The global `decimal` holds
51
+ `Decimal`, `Context` and the `ROUND_*` constants; the filter namespace `decimal.*` holds the
52
+ `Decimal` methods. `bool` is a subclass of `int`, so every `int.*` filter also accepts `true`
53
+ and `false`.
54
+
55
+ Dates work the same way. `date.*` filters also accept datetimes and call the `datetime` version
56
+ when one exists, so `{{ moment | date.isoformat(" ", "seconds") }}` works on a datetime. The
57
+ `datetime.*` namespace holds only what `datetime` adds or overrides. `datetime.astimezone` also
58
+ takes an IANA timezone name, e.g. `{{ moment | datetime.astimezone("Asia/Damascus") }}`; on
59
+ Windows, install the `tzdata` package for timezone names to resolve.
60
+
61
+ Regex filters take the string as the piped value and keep Python's parameter names:
62
+ `{{ code | re.search("abc-(\\d+)", flags=re.I) | match.group(1) }}`. Jinja string literals
63
+ process backslash escapes, so write `\\d` for the regex `\d`. `re.sub` also accepts a macro that
64
+ gets the match; under autoescape its output is kept as markup and the rest of the string is
65
+ escaped once. With the `[regex]` extra, the `regex` library is used and every call is limited
66
+ by `regex_timeout` (seconds, default 1.0).
67
+
68
+ `re.compile(pattern, flags)` returns a compiled pattern (cached); its members are the `pattern`
69
+ namespace, with the pattern piped in as in Python:
70
+
71
+ ```jinja
72
+ {% set word = re.compile("\\w+", re.I) %}
73
+ {{ word | pattern.findall(text) | join(", ") }}
74
+ {% if word is pattern.fullmatch(name) %}one word{% endif %}
75
+ ```
76
+
77
+ The full reference is in [docs/](docs/index.md), generated from the catalog. The same catalog is
78
+ available from the command line:
79
+
80
+ ```
81
+ jinja-types catalog --namespace str --format markdown
82
+ jinja-types catalog --kind test # JSON, see schema/catalog.schema.json
83
+ jinja-types conflicts --plugins
84
+ ```
85
+
86
+ To add your own filter sets as an installable plugin, see [docs/plugins.md](docs/plugins.md).
87
+
88
+ With the `[babel]` extra, `babel.*` formats numbers, money and dates for a locale. The locale
89
+ is the `locale=` argument, else `TypesExtension.configure(locale="ar_SY")`, else `en_US`:
90
+
91
+ ```jinja
92
+ {{ salary | babel.format_currency("USD") }} {# $1,234.50 (en_US) #}
93
+ {{ salary | babel.format_currency("SYP", locale="ar_SY", currency_digits=false) }} {# ‏1,234.50 ل.س.‏ #}
94
+ {{ salary | babel.format_decimal(locale="ar_SY", numbering_system="default") }} {# 1٬234٫5 #}
95
+ ```
96
+
97
+ `SYP` has no minor unit in CLDR, so `currency_digits=false` is needed to show piastres. `numbering_system="default"`
98
+ uses the locale's own separators (`٬` and `٫`); Babel keeps Latin digits either way, so
99
+ Arabic-Indic digits come from the arapy plugin.
100
+
101
+ Arabic text, numbers and dates come from [arapy](https://pypi.org/project/arapy/), a dependency,
102
+ under the `ar` namespace. arapy ships no currencies: define one in Python and pass it in:
103
+
104
+ ```python
105
+ from arapy import Currency, Gender, Noun
106
+
107
+ qirsh = Noun.create("قرش", "قرشان", "قروش", gender=Gender.MASCULINE)
108
+ syp = Currency.create(
109
+ code="SYP",
110
+ singular="ليرة سورية",
111
+ dual="ليرتان سوريتان",
112
+ plural="ليرات سورية",
113
+ gender=Gender.FEMININE,
114
+ subunit=qirsh,
115
+ symbol="ل.س",
116
+ )
117
+ ```
118
+
119
+ ```jinja
120
+ {{ salary | ar.to_words(syp) }} {# ألف وخمسمئة ليرة سورية #}
121
+ {{ salary | ar.format_money(syp) }} {# ١٬٥٠٠ ل.س #}
122
+ {{ day | ar.format_date("%A %d %B %Y", digits="arabic") }}
123
+ ```
124
+
125
+ `ar.to_hijri` needs `jinja-types[hijri]`, and `ar.shape` / `ar.reshape_only` need
126
+ `jinja-types[shape]`.
@@ -0,0 +1,120 @@
1
+ [project]
2
+ name = "jinja-types"
3
+ version = "0.1.0"
4
+ description = "Python type methods and attributes as qualified Jinja2 filters and tests."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.12"
9
+ keywords = [
10
+ "jinja2",
11
+ "jinja",
12
+ "filters",
13
+ "templates",
14
+ "sandbox",
15
+ "decimal",
16
+ "dates",
17
+ "regex",
18
+ "arabic",
19
+ ]
20
+ classifiers = [
21
+ "Development Status :: 3 - Alpha",
22
+ "Intended Audience :: Developers",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3 :: Only",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Topic :: Text Processing :: Markup",
29
+ "Typing :: Typed",
30
+ ]
31
+ dependencies = [
32
+ "arapy>=0.1.0",
33
+ "jinja2>=3.1",
34
+ ]
35
+
36
+ [[project.authors]]
37
+ name = "aaltatan"
38
+ email = "a.altatan@gmail.com"
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/aaltatan/jinja-types"
42
+ Repository = "https://github.com/aaltatan/jinja-types"
43
+ Issues = "https://github.com/aaltatan/jinja-types/issues"
44
+ Changelog = "https://github.com/aaltatan/jinja-types/blob/main/CHANGELOG.md"
45
+ Documentation = "https://github.com/aaltatan/jinja-types/tree/main/docs"
46
+
47
+ [project.optional-dependencies]
48
+ regex = ["regex"]
49
+ babel = ["babel"]
50
+ hijri = ["arapy[hijri]>=0.1.0"]
51
+ shape = ["arapy[shape]>=0.1.0"]
52
+
53
+ [project.scripts]
54
+ jinja-types = "jinja_types.cli:main"
55
+
56
+ [build-system]
57
+ requires = ["uv_build>=0.13.9,<0.14.0"]
58
+ build-backend = "uv_build"
59
+
60
+ [dependency-groups]
61
+ dev = [
62
+ "jsonschema>=4.26.0",
63
+ "mypy>=2.4.1",
64
+ "pytest>=9.2.0",
65
+ "pytest-cov>=7.1.0",
66
+ "ruff>=0.17.6",
67
+ "types-jsonschema>=4.26.0.20261006",
68
+ "tzdata>=2026.6",
69
+ ]
70
+
71
+ [tool.ruff]
72
+ line-length = 100
73
+ target-version = "py312"
74
+
75
+ [tool.ruff.lint]
76
+ select = [
77
+ "E",
78
+ "F",
79
+ "I",
80
+ "UP",
81
+ "B",
82
+ "SIM",
83
+ "RUF",
84
+ "ANN",
85
+ ]
86
+
87
+ [tool.ruff.lint.per-file-ignores]
88
+ "src/jinja_types/contrib/babel.py" = [
89
+ "RUF001",
90
+ "RUF002",
91
+ ]
92
+ "src/jinja_types/types/ar_.py" = [
93
+ "RUF001",
94
+ "RUF002",
95
+ ]
96
+ "tests/test_ar.py" = [
97
+ "RUF001",
98
+ "RUF002",
99
+ ]
100
+
101
+ [tool.mypy]
102
+ strict = true
103
+ files = [
104
+ "src",
105
+ "tests",
106
+ ]
107
+
108
+ [[tool.mypy.overrides]]
109
+ module = [
110
+ "jinja_types.regex.re_",
111
+ "jinja_types.regex.pattern_",
112
+ ]
113
+ warn_return_any = false
114
+
115
+ [tool.pytest.ini_options]
116
+ testpaths = ["tests"]
117
+ addopts = "--cov=jinja_types.core --cov-report=term-missing:skip-covered"
118
+
119
+ [tool.coverage.report]
120
+ fail_under = 95
@@ -0,0 +1,86 @@
1
+ [project]
2
+ name = "jinja-types"
3
+ version = "0.1.0"
4
+ description = "Python type methods and attributes as qualified Jinja2 filters and tests."
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "aaltatan", email = "a.altatan@gmail.com" }
8
+ ]
9
+ license = "MIT"
10
+ license-files = ["LICENSE"]
11
+ requires-python = ">=3.12"
12
+ keywords = ["jinja2", "jinja", "filters", "templates", "sandbox", "decimal", "dates", "regex", "arabic"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Operating System :: OS Independent",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Text Processing :: Markup",
22
+ "Typing :: Typed",
23
+ ]
24
+ dependencies = [
25
+ "arapy>=0.1.0",
26
+ "jinja2>=3.1",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/aaltatan/jinja-types"
31
+ Repository = "https://github.com/aaltatan/jinja-types"
32
+ Issues = "https://github.com/aaltatan/jinja-types/issues"
33
+ Changelog = "https://github.com/aaltatan/jinja-types/blob/main/CHANGELOG.md"
34
+ Documentation = "https://github.com/aaltatan/jinja-types/tree/main/docs"
35
+
36
+ [project.optional-dependencies]
37
+ regex = ["regex"]
38
+ babel = ["babel"]
39
+ hijri = ["arapy[hijri]>=0.1.0"]
40
+ shape = ["arapy[shape]>=0.1.0"]
41
+
42
+ [project.scripts]
43
+ jinja-types = "jinja_types.cli:main"
44
+
45
+ [build-system]
46
+ requires = ["uv_build>=0.13.9,<0.14.0"]
47
+ build-backend = "uv_build"
48
+
49
+ [dependency-groups]
50
+ dev = [
51
+ "jsonschema>=4.26.0",
52
+ "mypy>=2.4.1",
53
+ "pytest>=9.2.0",
54
+ "pytest-cov>=7.1.0",
55
+ "ruff>=0.17.6",
56
+ "types-jsonschema>=4.26.0.20261006",
57
+ "tzdata>=2026.6",
58
+ ]
59
+
60
+ [tool.ruff]
61
+ line-length = 100
62
+ target-version = "py312"
63
+
64
+ [tool.ruff.lint]
65
+ select = ["E", "F", "I", "UP", "B", "SIM", "RUF", "ANN"]
66
+
67
+ [tool.ruff.lint.per-file-ignores]
68
+ # locale output really contains Arabic separators and narrow no-break spaces
69
+ "src/jinja_types/contrib/babel.py" = ["RUF001", "RUF002"]
70
+ "src/jinja_types/types/ar_.py" = ["RUF001", "RUF002"]
71
+ "tests/test_ar.py" = ["RUF001", "RUF002"]
72
+
73
+ [tool.mypy]
74
+ strict = true
75
+ files = ["src", "tests"]
76
+
77
+ [[tool.mypy.overrides]]
78
+ module = ["jinja_types.regex.re_", "jinja_types.regex.pattern_"]
79
+ warn_return_any = false # the engine (re or the untyped regex library) returns Any
80
+
81
+ [tool.pytest.ini_options]
82
+ testpaths = ["tests"]
83
+ addopts = "--cov=jinja_types.core --cov-report=term-missing:skip-covered"
84
+
85
+ [tool.coverage.report]
86
+ fail_under = 95
@@ -0,0 +1,38 @@
1
+ """Python type methods and attributes as qualified Jinja2 filters and tests."""
2
+
3
+ from .core import (
4
+ BuiltinClashError,
5
+ Catalog,
6
+ CatalogEntry,
7
+ Collection,
8
+ Conflict,
9
+ DuplicateMemberError,
10
+ JinjaTypesError,
11
+ Kind,
12
+ MemberSpec,
13
+ Namespace,
14
+ Options,
15
+ Param,
16
+ Registry,
17
+ RegistryError,
18
+ )
19
+ from .extension import TypesExtension, install
20
+
21
+ __all__ = [
22
+ "BuiltinClashError",
23
+ "Catalog",
24
+ "CatalogEntry",
25
+ "Collection",
26
+ "Conflict",
27
+ "DuplicateMemberError",
28
+ "JinjaTypesError",
29
+ "Kind",
30
+ "MemberSpec",
31
+ "Namespace",
32
+ "Options",
33
+ "Param",
34
+ "Registry",
35
+ "RegistryError",
36
+ "TypesExtension",
37
+ "install",
38
+ ]
@@ -0,0 +1,53 @@
1
+ """The `jinja-types` command: export the catalog and list conflict resolutions."""
2
+
3
+ import argparse
4
+ import io
5
+ import sys
6
+
7
+ from jinja_types.core import Kind, Registry
8
+
9
+
10
+ def build_parser() -> argparse.ArgumentParser:
11
+ parser = argparse.ArgumentParser(prog="jinja-types", description=__doc__)
12
+ commands = parser.add_subparsers(dest="command", required=True)
13
+
14
+ catalog = commands.add_parser("catalog", help="print the catalog of every member")
15
+ catalog.add_argument("--namespace", help="only this namespace ('helpers' for plain names)")
16
+ catalog.add_argument("--kind", choices=[str(kind.name).lower() for kind in Kind])
17
+ catalog.add_argument("--format", choices=["json", "markdown"], default="json")
18
+
19
+ conflicts = commands.add_parser("conflicts", help="print every conflict resolution")
20
+
21
+ for command in (catalog, conflicts):
22
+ command.add_argument(
23
+ "--plugins", action="store_true", help="also load 'jinja_types.plugins' entry points"
24
+ )
25
+
26
+ return parser
27
+
28
+
29
+ def main(argv: list[str] | None = None) -> int:
30
+ """Run the `jinja-types` command."""
31
+
32
+ args = build_parser().parse_args(argv)
33
+ registry = Registry.default(plugins=args.plugins)
34
+
35
+ if isinstance(sys.stdout, io.TextIOWrapper):
36
+ sys.stdout.reconfigure(encoding="utf-8") # Windows consoles default to a legacy codepage
37
+
38
+ if args.command == "conflicts":
39
+ for conflict in registry.conflicts():
40
+ print(f"{conflict.name}\t{conflict.resolution}\t{conflict.detail}")
41
+
42
+ return 0
43
+
44
+ catalog = registry.catalog().select(namespace=args.namespace, kind=args.kind)
45
+
46
+ if not catalog:
47
+ print("jinja-types: no members match the filters", file=sys.stderr)
48
+
49
+ return 1
50
+
51
+ print(catalog.to_json() if args.format == "json" else catalog.to_markdown())
52
+
53
+ return 0
@@ -0,0 +1 @@
1
+ """Optional collections that need an extra (`[babel]`)."""