schemez 0.1.0__tar.gz → 0.1.1__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.
- {schemez-0.1.0 → schemez-0.1.1}/PKG-INFO +1 -1
- schemez-0.1.1/src/schemez/__init__.py +7 -0
- schemez-0.1.1/src/schemez/code.py +90 -0
- schemez-0.1.0/src/schemez/__init__.py +0 -6
- {schemez-0.1.0 → schemez-0.1.1}/.copier-answers.yml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/.github/FUNDING.yml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/.github/copilot-instructions.md +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/.github/dependabot.yml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/.github/workflows/build.yml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/.github/workflows/documentation.yml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/.gitignore +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/.pre-commit-config.yaml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/LICENSE +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/README.md +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/docs/.empty +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/duties.py +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/mkdocs.yml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/overrides/_dummy.txt +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/pyproject.toml +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/src/schemez/convert.py +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/src/schemez/docstrings.py +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/src/schemez/helpers.py +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/src/schemez/py.typed +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/src/schemez/schema.py +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/tests/__init__.py +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/tests/conftest.py +0 -0
- {schemez-0.1.0 → schemez-0.1.1}/tests/test_schema.py +0 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import ast
|
4
|
+
from typing import Literal
|
5
|
+
|
6
|
+
from pydantic import field_validator
|
7
|
+
|
8
|
+
from schemez.schema import Schema
|
9
|
+
|
10
|
+
|
11
|
+
CodeLanguage = Literal["python", "yaml", "json", "toml"]
|
12
|
+
|
13
|
+
|
14
|
+
class BaseCode(Schema):
|
15
|
+
"""Base class for syntax-validated code."""
|
16
|
+
|
17
|
+
code: str
|
18
|
+
"""The source code."""
|
19
|
+
|
20
|
+
@field_validator("code")
|
21
|
+
@classmethod
|
22
|
+
def validate_syntax(cls, code: str) -> str:
|
23
|
+
"""Override in subclasses."""
|
24
|
+
return code
|
25
|
+
|
26
|
+
|
27
|
+
class YAMLCode(BaseCode):
|
28
|
+
"""YAML with syntax validation."""
|
29
|
+
|
30
|
+
@field_validator("code")
|
31
|
+
@classmethod
|
32
|
+
def validate_syntax(cls, code: str) -> str:
|
33
|
+
import yamling
|
34
|
+
|
35
|
+
try:
|
36
|
+
yamling.load(code, mode="yaml")
|
37
|
+
except yamling.ParsingError as e:
|
38
|
+
msg = f"Invalid YAML syntax: {e}"
|
39
|
+
raise ValueError(msg) from e
|
40
|
+
else:
|
41
|
+
return code
|
42
|
+
|
43
|
+
|
44
|
+
class JSONCode(BaseCode):
|
45
|
+
"""JSON with syntax validation."""
|
46
|
+
|
47
|
+
@field_validator("code")
|
48
|
+
@classmethod
|
49
|
+
def validate_syntax(cls, code: str) -> str:
|
50
|
+
import yamling
|
51
|
+
|
52
|
+
try:
|
53
|
+
yamling.load(code, mode="json")
|
54
|
+
except yamling.ParsingError as e:
|
55
|
+
msg = f"Invalid JSON syntax: {e}"
|
56
|
+
raise ValueError(msg) from e
|
57
|
+
else:
|
58
|
+
return code
|
59
|
+
|
60
|
+
|
61
|
+
class TOMLCode(BaseCode):
|
62
|
+
"""TOML with syntax validation."""
|
63
|
+
|
64
|
+
@field_validator("code")
|
65
|
+
@classmethod
|
66
|
+
def validate_syntax(cls, code: str) -> str:
|
67
|
+
import yamling
|
68
|
+
|
69
|
+
try:
|
70
|
+
yamling.load(code, mode="toml")
|
71
|
+
except yamling.ParsingError as e:
|
72
|
+
msg = f"Invalid TOML syntax: {e}"
|
73
|
+
raise ValueError(msg) from e
|
74
|
+
else:
|
75
|
+
return code
|
76
|
+
|
77
|
+
|
78
|
+
class PythonCode(BaseCode):
|
79
|
+
"""Python with syntax validation."""
|
80
|
+
|
81
|
+
@field_validator("code")
|
82
|
+
@classmethod
|
83
|
+
def validate_syntax(cls, code: str) -> str:
|
84
|
+
try:
|
85
|
+
ast.parse(code)
|
86
|
+
except SyntaxError as e:
|
87
|
+
msg = f"Invalid Python syntax: {e}"
|
88
|
+
raise ValueError(msg) from e
|
89
|
+
else:
|
90
|
+
return code
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|