pydantree 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.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.1
2
+ Name: pydantree
3
+ Version: 0.1.0
4
+ Summary: Pydantic parser for tree-sitter
5
+ Author-Email: Louis Maddox <louismmx@gmail.com>
6
+ License: MIT
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: defopt>=6.4.0
18
+ Requires-Dist: pydantic>=2.8.2
19
+ Description-Content-Type: text/markdown
20
+
21
+ # pydantree
22
+
23
+ Pydantic parser for tree-sitter
24
+
25
+ [![PyPI Version](https://img.shields.io/pypi/v/pydantree)](https://pypi.org/project/pydantree/)
26
+ [![Python Versions](https://img.shields.io/pypi/pyversions/pydantree.svg)](https://pypi.org/project/pydantree/)
27
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
28
+ [![Documentation](https://img.shields.io/badge/docs-pydantree.vercel.app-blue)](https://pydantree.vercel.app/)
29
+ [![CI Status](https://github.com/lmmx/pydantree/actions/workflows/ci.yml/badge.svg)](https://github.com/lmmx/pydantree/actions/workflows/ci.yml)
30
+ [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/lmmx/pydantree/master.svg)](https://results.pre-commit.ci/latest/github/lmmx/pydantree/master)
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install pydantree
36
+ ```
37
+
38
+ ## Grammar
39
+
40
+ The grammar comes from
41
+ [this version][gr]
42
+ and should be updated when that changes.
43
+
44
+ **Last updated**: 20th July 2024
45
+
46
+ [gr]: https://github.com/tree-sitter/tree-sitter-python/blob/0dee05ef958ba2eae88d1e65f24b33cad70d4367/src/grammar.json
@@ -0,0 +1,26 @@
1
+ # pydantree
2
+
3
+ Pydantic parser for tree-sitter
4
+
5
+ [![PyPI Version](https://img.shields.io/pypi/v/pydantree)](https://pypi.org/project/pydantree/)
6
+ [![Python Versions](https://img.shields.io/pypi/pyversions/pydantree.svg)](https://pypi.org/project/pydantree/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![Documentation](https://img.shields.io/badge/docs-pydantree.vercel.app-blue)](https://pydantree.vercel.app/)
9
+ [![CI Status](https://github.com/lmmx/pydantree/actions/workflows/ci.yml/badge.svg)](https://github.com/lmmx/pydantree/actions/workflows/ci.yml)
10
+ [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/lmmx/pydantree/master.svg)](https://results.pre-commit.ci/latest/github/lmmx/pydantree/master)
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pip install pydantree
16
+ ```
17
+
18
+ ## Grammar
19
+
20
+ The grammar comes from
21
+ [this version][gr]
22
+ and should be updated when that changes.
23
+
24
+ **Last updated**: 20th July 2024
25
+
26
+ [gr]: https://github.com/tree-sitter/tree-sitter-python/blob/0dee05ef958ba2eae88d1e65f24b33cad70d4367/src/grammar.json
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = [
3
+ "pdm-backend",
4
+ ]
5
+ build-backend = "pdm.backend"
6
+
7
+ [project]
8
+ name = "pydantree"
9
+ version = "0.1.0"
10
+ description = "Pydantic parser for tree-sitter"
11
+ authors = [
12
+ { name = "Louis Maddox", email = "louismmx@gmail.com" },
13
+ ]
14
+ dependencies = [
15
+ "defopt>=6.4.0",
16
+ "pydantic>=2.8.2",
17
+ ]
18
+ requires-python = ">=3.10"
19
+ readme = "README.md"
20
+ classifiers = [
21
+ "Development Status :: 3 - Alpha",
22
+ "Intended Audience :: Developers",
23
+ "Operating System :: OS Independent",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Programming Language :: Python",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3 :: Only",
30
+ ]
31
+
32
+ [project.license]
33
+ text = "MIT"
34
+
35
+ [project.scripts]
36
+ pdt = "pydantree.cli:run_cli"
37
+
38
+ [tool.pdm]
39
+ distribution = true
File without changes
@@ -0,0 +1,57 @@
1
+ import json
2
+ from pathlib import Path
3
+ from sys import stderr
4
+ from textwrap import indent
5
+
6
+ import defopt
7
+ from pydantic import BaseModel, ValidationError, FilePath
8
+
9
+ __all__ = ["run_cli"]
10
+
11
+
12
+ class GrammarConfig(BaseModel):
13
+ input_file: FilePath | None = None
14
+
15
+
16
+ def handle_validation_error(ve: ValidationError) -> None:
17
+ error_msgs = "\n".join(str(e["ctx"]["error"]) for e in ve.errors())
18
+ msg = "Invalid command:\n" + indent(error_msgs, prefix="- ")
19
+ print(msg, end="\n\n", file=stderr)
20
+
21
+
22
+ def generate_grammar(config: GrammarConfig) -> None:
23
+ if config.input_file is None:
24
+ # Use the default grammar file shipped with the package
25
+ package_dir = Path(__file__).parent
26
+ default_grammar_file = package_dir / "grammar.json"
27
+ input_file = default_grammar_file
28
+ else:
29
+ input_file = config.input_file
30
+
31
+ try:
32
+ with open(input_file) as f:
33
+ grammar = json.load(f)
34
+ print(f"Grammar generated from file: {input_file}")
35
+ print(json.dumps(grammar, indent=2))
36
+ except FileNotFoundError:
37
+ print(f"Error: Grammar file not found at {input_file}", file=stderr)
38
+ except json.JSONDecodeError:
39
+ print(f"Error: Invalid JSON in grammar file {input_file}", file=stderr)
40
+
41
+
42
+ def run_cli():
43
+ try:
44
+ config = defopt.run(GrammarConfig, no_negated_flags=True)
45
+ except ValidationError as ve:
46
+ handle_validation_error(ve)
47
+ try:
48
+ defopt.run(generate_grammar, argv=["-h"], no_negated_flags=True)
49
+ except SystemExit as exc:
50
+ exc.code = 1
51
+ raise
52
+ else:
53
+ generate_grammar(config=config)
54
+
55
+
56
+ if __name__ == "__main__":
57
+ run_cli()