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.
Files changed (27) hide show
  1. {schemez-0.1.0 → schemez-0.1.1}/PKG-INFO +1 -1
  2. schemez-0.1.1/src/schemez/__init__.py +7 -0
  3. schemez-0.1.1/src/schemez/code.py +90 -0
  4. schemez-0.1.0/src/schemez/__init__.py +0 -6
  5. {schemez-0.1.0 → schemez-0.1.1}/.copier-answers.yml +0 -0
  6. {schemez-0.1.0 → schemez-0.1.1}/.github/FUNDING.yml +0 -0
  7. {schemez-0.1.0 → schemez-0.1.1}/.github/copilot-instructions.md +0 -0
  8. {schemez-0.1.0 → schemez-0.1.1}/.github/dependabot.yml +0 -0
  9. {schemez-0.1.0 → schemez-0.1.1}/.github/workflows/build.yml +0 -0
  10. {schemez-0.1.0 → schemez-0.1.1}/.github/workflows/documentation.yml +0 -0
  11. {schemez-0.1.0 → schemez-0.1.1}/.gitignore +0 -0
  12. {schemez-0.1.0 → schemez-0.1.1}/.pre-commit-config.yaml +0 -0
  13. {schemez-0.1.0 → schemez-0.1.1}/LICENSE +0 -0
  14. {schemez-0.1.0 → schemez-0.1.1}/README.md +0 -0
  15. {schemez-0.1.0 → schemez-0.1.1}/docs/.empty +0 -0
  16. {schemez-0.1.0 → schemez-0.1.1}/duties.py +0 -0
  17. {schemez-0.1.0 → schemez-0.1.1}/mkdocs.yml +0 -0
  18. {schemez-0.1.0 → schemez-0.1.1}/overrides/_dummy.txt +0 -0
  19. {schemez-0.1.0 → schemez-0.1.1}/pyproject.toml +0 -0
  20. {schemez-0.1.0 → schemez-0.1.1}/src/schemez/convert.py +0 -0
  21. {schemez-0.1.0 → schemez-0.1.1}/src/schemez/docstrings.py +0 -0
  22. {schemez-0.1.0 → schemez-0.1.1}/src/schemez/helpers.py +0 -0
  23. {schemez-0.1.0 → schemez-0.1.1}/src/schemez/py.typed +0 -0
  24. {schemez-0.1.0 → schemez-0.1.1}/src/schemez/schema.py +0 -0
  25. {schemez-0.1.0 → schemez-0.1.1}/tests/__init__.py +0 -0
  26. {schemez-0.1.0 → schemez-0.1.1}/tests/conftest.py +0 -0
  27. {schemez-0.1.0 → schemez-0.1.1}/tests/test_schema.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: schemez
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Pydantic shim for config stuff
5
5
  Project-URL: Documentation, https://phil65.github.io/schemez/
6
6
  Project-URL: Source, https://github.com/phil65/schemez
@@ -0,0 +1,7 @@
1
+ __version__ = "0.1.1"
2
+
3
+
4
+ from schemez.schema import Schema
5
+ from schemez.code import PythonCode, JSONCode, TOMLCode, YAMLCode
6
+
7
+ __all__ = ["JSONCode", "PythonCode", "Schema", "TOMLCode", "YAMLCode"]
@@ -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
@@ -1,6 +0,0 @@
1
- __version__ = "0.1.0"
2
-
3
-
4
- from schemez.schema import Schema
5
-
6
- __all__ = ["Schema"]
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