ast-grep-py 0.39.7__cp314-cp314-macosx_11_0_arm64.whl

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.

Potentially problematic release.


This version of ast-grep-py might be problematic. Click here for more details.

@@ -0,0 +1,85 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import List, TypedDict, Literal, Dict, Union, Mapping, Optional
4
+ from .ast_grep_py import SgNode, SgRoot, Pos, Range, Edit, register_dynamic_language
5
+
6
+ Strictness = Union[Literal["cst"], Literal["smart"], Literal["ast"], Literal["relaxed"], Literal["signature"]]
7
+
8
+ class Pattern(TypedDict):
9
+ selector: Optional[str]
10
+ strictness: Optional[Strictness]
11
+ context: str
12
+
13
+ class NthChild(TypedDict):
14
+ position: int | str
15
+ ofRule: Rule
16
+ nth: int
17
+
18
+ class PosRule(TypedDict):
19
+ line: int
20
+ column: int
21
+
22
+ class RangeRule(TypedDict):
23
+ start: PosRule
24
+ end: PosRule
25
+
26
+ class RuleWithoutNot(TypedDict, total=False):
27
+ # atomic rule
28
+ pattern: str | Pattern
29
+ kind: str
30
+ regex: str
31
+ nthChild: int | str | NthChild
32
+ range: RangeRule
33
+
34
+ # relational rule
35
+ inside: "Relation" # pyright report error if forward reference here?
36
+ has: Relation
37
+ precedes: Relation
38
+ follows: Relation
39
+
40
+ # composite rule
41
+ all: List[Rule]
42
+ any: List[Rule]
43
+ # cannot add here due to reserved keyword
44
+ # not: Rule
45
+ matches: str
46
+
47
+ # workaround
48
+ # Python's keyword requires `not` be a special case
49
+ class Rule(RuleWithoutNot, TypedDict("Not", {"not": "Rule"}, total=False)):
50
+ pass
51
+
52
+ # Relational Rule Related
53
+ StopBy = Union[Literal["neighbor"], Literal["end"], Rule]
54
+
55
+ # Relation do NOT inherit from Rule due to pyright bug
56
+ # see tests/test_rule.py
57
+ class Relation(RuleWithoutNot, TypedDict("Not", {"not": "Rule"}, total=False), total=False):
58
+ stopBy: StopBy
59
+ field: str
60
+
61
+ class Config(TypedDict, total=False):
62
+ rule: Rule
63
+ constraints: Dict[str, Mapping]
64
+ utils: Dict[str, Rule]
65
+ transform: Dict[str, Mapping]
66
+
67
+ class CustomLang(TypedDict, total=False):
68
+ library_path: str
69
+ language_symbol: Optional[str]
70
+ meta_var_char: Optional[str]
71
+ expando_char: Optional[str]
72
+
73
+ __all__ = [
74
+ "Rule",
75
+ "Config",
76
+ "Relation",
77
+ "Pattern",
78
+ "NthChild",
79
+ "SgNode",
80
+ "SgRoot",
81
+ "Pos",
82
+ "Range",
83
+ "Edit",
84
+ "register_dynamic_language",
85
+ ]
@@ -0,0 +1,71 @@
1
+ from typing import List, Optional, overload, Unpack, Dict
2
+
3
+ from . import Rule, Config, CustomLang
4
+
5
+ class Pos:
6
+ line: int
7
+ column: int
8
+ index: int
9
+
10
+ class Range:
11
+ start: Pos
12
+ end: Pos
13
+
14
+ class Edit:
15
+ start_pos: int
16
+ end_pos: int
17
+ inserted_text: str
18
+
19
+ class SgRoot:
20
+ def __init__(self, src: str, language: str) -> None: ...
21
+ def root(self) -> SgNode: ...
22
+ def filename(self) -> str: ...
23
+
24
+ class SgNode:
25
+ # Node Inspection
26
+ def range(self) -> Range: ...
27
+ def is_leaf(self) -> bool: ...
28
+ def is_named(self) -> bool: ...
29
+ def is_named_leaf(self) -> bool: ...
30
+ def kind(self) -> str: ...
31
+ def text(self) -> str: ...
32
+
33
+ # Refinement
34
+ def matches(self, **rule: Unpack[Rule]) -> bool: ...
35
+ def inside(self, **rule: Unpack[Rule]) -> bool: ...
36
+ def has(self, **rule: Unpack[Rule]) -> bool: ...
37
+ def precedes(self, **rule: Unpack[Rule]) -> bool: ...
38
+ def follows(self, **rule: Unpack[Rule]) -> bool: ...
39
+ def get_match(self, meta_var: str) -> Optional[SgNode]: ...
40
+ def get_multiple_matches(self, meta_var: str) -> List[SgNode]: ...
41
+ def get_transformed(self, meta_var: str) -> Optional[str]: ...
42
+ def __getitem__(self, meta_var: str) -> SgNode: ...
43
+
44
+ # Search
45
+ @overload
46
+ def find(self, config: Config) -> Optional[SgNode]: ...
47
+ @overload
48
+ def find(self, **kwargs: Unpack[Rule]) -> Optional[SgNode]: ...
49
+ @overload
50
+ def find_all(self, config: Config) -> List[SgNode]: ...
51
+ @overload
52
+ def find_all(self, **kwargs: Unpack[Rule]) -> List[SgNode]: ...
53
+
54
+ # Tree Traversal
55
+ def get_root(self) -> SgRoot: ...
56
+ def field(self, name: str) -> Optional[SgNode]: ...
57
+ def field_children(self, name: str) -> List[SgNode]: ...
58
+ def parent(self) -> Optional[SgNode]: ...
59
+ def child(self, nth: int) -> Optional[SgNode]: ...
60
+ def children(self) -> List[SgNode]: ...
61
+ def ancestors(self) -> List[SgNode]: ...
62
+ def next(self) -> Optional[SgNode]: ...
63
+ def next_all(self) -> List[SgNode]: ...
64
+ def prev(self) -> Optional[SgNode]: ...
65
+ def prev_all(self) -> List[SgNode]: ...
66
+
67
+ # Edit
68
+ def replace(self, new_text: str) -> Edit: ...
69
+ def commit_edits(self, edits: List[Edit]) -> str: ...
70
+
71
+ def register_dynamic_language(langs: Dict[str, CustomLang]): ...
ast_grep_py/py.typed ADDED
File without changes
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: ast-grep-py
3
+ Version: 0.39.7
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Environment :: Console
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Rust
10
+ Classifier: Topic :: Security
11
+ Classifier: Topic :: Software Development :: Quality Assurance
12
+ Classifier: Topic :: Software Development
13
+ Classifier: Topic :: Text Processing
14
+ Requires-Dist: pytest>=7 ; extra == 'test'
15
+ Provides-Extra: test
16
+ Summary: Structural Search and Rewrite code at large scale using precise AST pattern.
17
+ Keywords: ast,pattern,codemod,structural search,rewrite
18
+ Author-email: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>
19
+ Maintainer-email: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>
20
+ License: MIT
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
23
+ Project-URL: Repository, https://github.com/ast-grep/ast-grep
24
+ Project-URL: Documentation, https://ast-grep.github.io/
25
+ Project-URL: Changelog, https://github.com/ast-grep/ast-grep/blob/main/CHANGELOG.md
26
+
27
+ # ast-grep python binding
28
+
29
+ [![PyPI](https://img.shields.io/pypi/v/ast-grep-py.svg?logo=PyPI)](https://pypi.org/project/ast-grep-py/)
30
+ [![Website](https://img.shields.io/badge/ast--grep-Ast--Grep_Website-red?logoColor=red)](https://ast-grep.github.io/)
31
+
32
+ <p align=center>
33
+ <img src="https://ast-grep.github.io/logo.svg" alt="ast-grep"/>
34
+ </p>
35
+
36
+ ## ast-grep
37
+
38
+ `ast-grep` is a tool for code structural search, lint, and rewriting.
39
+
40
+ This crate intends to build a native python binding of ast-grep and provide a python API for programmatic usage.
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install ast-grep-py
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ You can take our tests as examples. For example, [test_simple.py](./tests/test_simple.py) shows how to use ast-grep to search for a pattern in a file.
51
+
52
+ Please see the [API usage guide](https://ast-grep.github.io/guide/api-usage.html) and [API reference](https://ast-grep.github.io/reference/api.html) for more details.
53
+
54
+ Other resources include [ast-grep's official site](https://ast-grep.github.io/) and [repository](https://github.com/ast-grep/ast-grep).
55
+
56
+ ## Development
57
+
58
+ ### Setup virtualenv
59
+
60
+ ```shell
61
+ python -m venv venv
62
+ ```
63
+
64
+ ### Activate venv
65
+
66
+ ```shell
67
+ source venv/bin/activate
68
+ ```
69
+
70
+ ### Install `maturin`
71
+
72
+ ```shell
73
+ pip install maturin[patchelf]
74
+ ```
75
+
76
+ ### MacOS: Install `patchelf` and `maturin`
77
+
78
+ ```shell
79
+ brew install patchelf
80
+ pip install maturin
81
+ ```
82
+
83
+ ### Build bindings
84
+
85
+ ```shell
86
+ maturin develop
87
+ ```
88
+
89
+ ### Run tests
90
+
91
+ ```shell
92
+ pytest
93
+ ```
94
+
95
+ All tests files are under [tests](./tests) directory.
96
+
97
+ ## License
98
+
99
+ This project is licensed under the MIT license.
100
+
@@ -0,0 +1,7 @@
1
+ ast_grep_py-0.39.7.dist-info/METADATA,sha256=KH5c9wwF_kNFqfvilHtTw015G6csPSZ69twO77NpMs4,2748
2
+ ast_grep_py-0.39.7.dist-info/WHEEL,sha256=1PvyiPvcJ94VD-5qzLXvCxiTKltkB9r5dXMQ1otw8Pg,104
3
+ ast_grep_py/__init__.py,sha256=3X6B430_LMQp8gaddVN77rNfnBdGPvswWC49Zh-gw9w,2036
4
+ ast_grep_py/ast_grep_py.cpython-314-darwin.so,sha256=T9ue5Se4aC4Qwn8qRowYs2xm8sYXWEu4akVIhp62Ygc,40758672
5
+ ast_grep_py/ast_grep_py.pyi,sha256=esTZ37k9WxdLM7tszJMYI8fAFkycWKzbeHJh7gguIuY,2270
6
+ ast_grep_py/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ ast_grep_py-0.39.7.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.9.6)
3
+ Root-Is-Purelib: false
4
+ Tag: cp314-cp314-macosx_11_0_arm64