typja 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.
- typja-0.1.0/PKG-INFO +144 -0
- typja-0.1.0/README.md +113 -0
- typja-0.1.0/pyproject.toml +106 -0
- typja-0.1.0/src/typja/__init__.py +18 -0
- typja-0.1.0/src/typja/__main__.py +4 -0
- typja-0.1.0/src/typja/analyzer.py +480 -0
- typja-0.1.0/src/typja/cli/__init__.py +0 -0
- typja-0.1.0/src/typja/cli/app.py +52 -0
- typja-0.1.0/src/typja/cli/check.py +210 -0
- typja-0.1.0/src/typja/cli/init.py +77 -0
- typja-0.1.0/src/typja/cli/watch.py +127 -0
- typja-0.1.0/src/typja/config/__init__.py +14 -0
- typja-0.1.0/src/typja/config/defaults.py +116 -0
- typja-0.1.0/src/typja/config/loader.py +161 -0
- typja-0.1.0/src/typja/config/schema.py +158 -0
- typja-0.1.0/src/typja/constants.py +32 -0
- typja-0.1.0/src/typja/exceptions.py +45 -0
- typja-0.1.0/src/typja/helpers.py +42 -0
- typja-0.1.0/src/typja/linter.py +501 -0
- typja-0.1.0/src/typja/parser/__init__.py +25 -0
- typja-0.1.0/src/typja/parser/ast.py +199 -0
- typja-0.1.0/src/typja/parser/comment.py +221 -0
- typja-0.1.0/src/typja/parser/imports.py +46 -0
- typja-0.1.0/src/typja/parser/type.py +150 -0
- typja-0.1.0/src/typja/registry.py +191 -0
- typja-0.1.0/src/typja/reporter.py +247 -0
- typja-0.1.0/src/typja/resolver.py +306 -0
typja-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: typja
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Type checker for your Jinja2 templates
|
|
5
|
+
Keywords: jinja2,type checking,static analysis
|
|
6
|
+
Author: Daniel Brai
|
|
7
|
+
Author-email: Daniel Brai <danielbrai.dev@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Topic :: Utilities
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Dist: jinja2>=3.1.6
|
|
23
|
+
Requires-Dist: typer>=0.23.0
|
|
24
|
+
Requires-Dist: tomli==2.4.0 ; python_full_version < '3.11'
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Project-URL: Homepage, https://github.com/Daniel-Brai/Typja
|
|
27
|
+
Project-URL: Repository, https://github.com/Daniel-Brai/Typja
|
|
28
|
+
Project-URL: Source, https://github.com/Daniel-Brai/Typja
|
|
29
|
+
Project-URL: Issues, https://github.com/Daniel-Brai/Typja/issues
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Typja
|
|
33
|
+
|
|
34
|
+
[](https://www.python.org/downloads/)
|
|
35
|
+
[](https://github.com/Daniel-Brai/Typja/actions/workflows/ci.yml)
|
|
36
|
+
[](https://codecov.io/gh/Daniel-Brai/Typja)
|
|
37
|
+
[](https://opensource.org/licenses/MIT)
|
|
38
|
+
|
|
39
|
+
An experimental tool to check Jinja templates for type errors using Python's type hints. It parses Jinja templates, extracts variable usage, and checks them against provided type information.
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Type Checking for Jinja2 Templates**: Validate that variables in your Jinja2 templates match their declared types
|
|
44
|
+
- **Python Type Hints Integration**: Leverage your existing Python type annotations to catch template errors early
|
|
45
|
+
- **Pre-commit Integration**: Built-in pre-commit hook for automated checking
|
|
46
|
+
- **Flexible Configuration**: Customize checking behavior with `typja.toml`
|
|
47
|
+
- **Rich Error Reports**: Detailed error messages with code snippets and suggestions
|
|
48
|
+
- **Watch Mode**: Monitor templates for changes and run checks automatically
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
### Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install typja
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Basic Usage
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Check all templates in current directory
|
|
62
|
+
typja check
|
|
63
|
+
|
|
64
|
+
# Run in watch mode
|
|
65
|
+
typja watch
|
|
66
|
+
|
|
67
|
+
# Initialize a new typja.toml configuration
|
|
68
|
+
typja init
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Configuration
|
|
72
|
+
|
|
73
|
+
Create a `typja.toml` file in your project root with `typja init` or manually:
|
|
74
|
+
|
|
75
|
+
```toml
|
|
76
|
+
[project]
|
|
77
|
+
root = "."
|
|
78
|
+
paths = ["./models/**/*.py"]
|
|
79
|
+
fail_on_warning = false
|
|
80
|
+
|
|
81
|
+
[environment]
|
|
82
|
+
template_dirs = ["./templates"]
|
|
83
|
+
include_patterns = ["*.html", "*.jinja", "*.jinja2"]
|
|
84
|
+
|
|
85
|
+
[linting]
|
|
86
|
+
strict = false
|
|
87
|
+
prefer_pep604_unions = true
|
|
88
|
+
validate_imports = true
|
|
89
|
+
validate_variables = true
|
|
90
|
+
|
|
91
|
+
[errors]
|
|
92
|
+
verbosity = "normal"
|
|
93
|
+
show_snippets = true
|
|
94
|
+
show_hints = true
|
|
95
|
+
color = "auto"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Type Annotations in Templates
|
|
99
|
+
|
|
100
|
+
Use special Jinja2 comments to declare variable types:
|
|
101
|
+
|
|
102
|
+
```jinja2
|
|
103
|
+
{# typja:var user: User #}
|
|
104
|
+
{# typja:var items: list[str] #}
|
|
105
|
+
{# typja:var count: int #}
|
|
106
|
+
|
|
107
|
+
<h1>{{ user.name }}</h1>
|
|
108
|
+
<ul>
|
|
109
|
+
{% for item in items %}
|
|
110
|
+
<li>{{ item }}</li>
|
|
111
|
+
{% endfor %}
|
|
112
|
+
</ul>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Examples
|
|
116
|
+
|
|
117
|
+
See the [examples/fastapi/](examples/fastapi/) directory for a complete FastAPI application with Jinja2 template type checking.
|
|
118
|
+
|
|
119
|
+
## Pre-commit Integration
|
|
120
|
+
|
|
121
|
+
Add to your `.pre-commit-config.yaml`:
|
|
122
|
+
|
|
123
|
+
```yaml
|
|
124
|
+
repos:
|
|
125
|
+
- repo: https://github.com/Daniel-Brai/Typja
|
|
126
|
+
rev: v0.1.0
|
|
127
|
+
hooks:
|
|
128
|
+
- id: typja-check
|
|
129
|
+
# With args
|
|
130
|
+
# args: ["--strict", "--fix"]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Documentation
|
|
134
|
+
|
|
135
|
+
- [Configuration Guide](docs/CONFIGURATION.md) - Detailed configuration options
|
|
136
|
+
- [Syntax Guide](docs/SYNTAX.md) - Template syntax and type annotations
|
|
137
|
+
|
|
138
|
+
## Contributing
|
|
139
|
+
|
|
140
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development instructions.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
See [LICENSE](LICENSE) for details.
|
typja-0.1.0/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Typja
|
|
2
|
+
|
|
3
|
+
[](https://www.python.org/downloads/)
|
|
4
|
+
[](https://github.com/Daniel-Brai/Typja/actions/workflows/ci.yml)
|
|
5
|
+
[](https://codecov.io/gh/Daniel-Brai/Typja)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
An experimental tool to check Jinja templates for type errors using Python's type hints. It parses Jinja templates, extracts variable usage, and checks them against provided type information.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Type Checking for Jinja2 Templates**: Validate that variables in your Jinja2 templates match their declared types
|
|
13
|
+
- **Python Type Hints Integration**: Leverage your existing Python type annotations to catch template errors early
|
|
14
|
+
- **Pre-commit Integration**: Built-in pre-commit hook for automated checking
|
|
15
|
+
- **Flexible Configuration**: Customize checking behavior with `typja.toml`
|
|
16
|
+
- **Rich Error Reports**: Detailed error messages with code snippets and suggestions
|
|
17
|
+
- **Watch Mode**: Monitor templates for changes and run checks automatically
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install typja
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Basic Usage
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Check all templates in current directory
|
|
31
|
+
typja check
|
|
32
|
+
|
|
33
|
+
# Run in watch mode
|
|
34
|
+
typja watch
|
|
35
|
+
|
|
36
|
+
# Initialize a new typja.toml configuration
|
|
37
|
+
typja init
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Configuration
|
|
41
|
+
|
|
42
|
+
Create a `typja.toml` file in your project root with `typja init` or manually:
|
|
43
|
+
|
|
44
|
+
```toml
|
|
45
|
+
[project]
|
|
46
|
+
root = "."
|
|
47
|
+
paths = ["./models/**/*.py"]
|
|
48
|
+
fail_on_warning = false
|
|
49
|
+
|
|
50
|
+
[environment]
|
|
51
|
+
template_dirs = ["./templates"]
|
|
52
|
+
include_patterns = ["*.html", "*.jinja", "*.jinja2"]
|
|
53
|
+
|
|
54
|
+
[linting]
|
|
55
|
+
strict = false
|
|
56
|
+
prefer_pep604_unions = true
|
|
57
|
+
validate_imports = true
|
|
58
|
+
validate_variables = true
|
|
59
|
+
|
|
60
|
+
[errors]
|
|
61
|
+
verbosity = "normal"
|
|
62
|
+
show_snippets = true
|
|
63
|
+
show_hints = true
|
|
64
|
+
color = "auto"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Type Annotations in Templates
|
|
68
|
+
|
|
69
|
+
Use special Jinja2 comments to declare variable types:
|
|
70
|
+
|
|
71
|
+
```jinja2
|
|
72
|
+
{# typja:var user: User #}
|
|
73
|
+
{# typja:var items: list[str] #}
|
|
74
|
+
{# typja:var count: int #}
|
|
75
|
+
|
|
76
|
+
<h1>{{ user.name }}</h1>
|
|
77
|
+
<ul>
|
|
78
|
+
{% for item in items %}
|
|
79
|
+
<li>{{ item }}</li>
|
|
80
|
+
{% endfor %}
|
|
81
|
+
</ul>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
See the [examples/fastapi/](examples/fastapi/) directory for a complete FastAPI application with Jinja2 template type checking.
|
|
87
|
+
|
|
88
|
+
## Pre-commit Integration
|
|
89
|
+
|
|
90
|
+
Add to your `.pre-commit-config.yaml`:
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
repos:
|
|
94
|
+
- repo: https://github.com/Daniel-Brai/Typja
|
|
95
|
+
rev: v0.1.0
|
|
96
|
+
hooks:
|
|
97
|
+
- id: typja-check
|
|
98
|
+
# With args
|
|
99
|
+
# args: ["--strict", "--fix"]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
- [Configuration Guide](docs/CONFIGURATION.md) - Detailed configuration options
|
|
105
|
+
- [Syntax Guide](docs/SYNTAX.md) - Template syntax and type annotations
|
|
106
|
+
|
|
107
|
+
## Contributing
|
|
108
|
+
|
|
109
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development instructions.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.9.26,<0.10.0"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "typja"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Type checker for your Jinja2 templates"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Daniel Brai", email = "danielbrai.dev@gmail.com" }
|
|
13
|
+
]
|
|
14
|
+
keywords = ["jinja2", "type checking", "static analysis"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
|
|
20
|
+
"Natural Language :: English",
|
|
21
|
+
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
28
|
+
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Operating System :: POSIX :: Linux",
|
|
31
|
+
|
|
32
|
+
"Topic :: Utilities",
|
|
33
|
+
|
|
34
|
+
"Typing :: Typed",
|
|
35
|
+
]
|
|
36
|
+
requires-python = ">=3.10"
|
|
37
|
+
dependencies = [
|
|
38
|
+
"jinja2>=3.1.6",
|
|
39
|
+
"typer>=0.23.0",
|
|
40
|
+
"tomli==2.4.0; python_version<'3.11'",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[dependency-groups]
|
|
44
|
+
dev = [
|
|
45
|
+
"pre-commit>=4.5.1",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
test = [
|
|
49
|
+
"pydantic>=2.12.5",
|
|
50
|
+
"coverage>=7.13.4",
|
|
51
|
+
"pytest>=9.0.2",
|
|
52
|
+
"pytest-cov>=7.0.0",
|
|
53
|
+
"pytest-xdist>=3.8.0",
|
|
54
|
+
"pytest-asyncio>=1.3.0",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[project.scripts]
|
|
58
|
+
typja = "typja:main"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
[project.urls]
|
|
62
|
+
Homepage = "https://github.com/Daniel-Brai/Typja"
|
|
63
|
+
Repository = "https://github.com/Daniel-Brai/Typja"
|
|
64
|
+
Source = "https://github.com/Daniel-Brai/Typja"
|
|
65
|
+
Issues = "https://github.com/Daniel-Brai/Typja/issues"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
[tool.uv]
|
|
69
|
+
package = true
|
|
70
|
+
|
|
71
|
+
[tool.bandit]
|
|
72
|
+
severity_level = "HIGH"
|
|
73
|
+
confidence_level = "HIGH"
|
|
74
|
+
exclude_dirs = ["tests", "venv", ".venv", "build", "dist", "__pycache__", "examples"]
|
|
75
|
+
|
|
76
|
+
[tool.mypy]
|
|
77
|
+
python_version = "3.10"
|
|
78
|
+
show_error_codes = true
|
|
79
|
+
warn_unused_configs = true
|
|
80
|
+
check_untyped_defs = true
|
|
81
|
+
implicit_optional = true
|
|
82
|
+
exclude = ["^./build/.*$", "^./.venv/.*$", "^.*/tests/.*$", "^./examples/.*$"]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint]
|
|
86
|
+
select = [
|
|
87
|
+
"E", # pycodestyle errors
|
|
88
|
+
"W", # pycodestyle warnings
|
|
89
|
+
"F", # pyflakes
|
|
90
|
+
"I", # isort
|
|
91
|
+
"B", # flake8-bugbear
|
|
92
|
+
"C4", # flake8-comprehensions
|
|
93
|
+
"UP", # pyupgrade
|
|
94
|
+
]
|
|
95
|
+
ignore = [
|
|
96
|
+
"E501", # line too long, handled by black
|
|
97
|
+
"B008", # do not perform function calls in argument defaults
|
|
98
|
+
"W191", # indentation contains tabs
|
|
99
|
+
"C416", # Allow use of list comprehensions
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
[tool.pytest.ini_options]
|
|
104
|
+
asyncio_mode = "auto"
|
|
105
|
+
testpaths = ["./tests/"]
|
|
106
|
+
python_files = ["test_*.py"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
typja - Type checking for Jinja2 templates
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import version
|
|
6
|
+
|
|
7
|
+
from typja.constants import PACKAGE_NAME
|
|
8
|
+
|
|
9
|
+
__version__ = version(PACKAGE_NAME)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> None:
|
|
13
|
+
from typja.cli.app import app
|
|
14
|
+
|
|
15
|
+
app()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
__all__ = ["main"]
|