polyglot-piranha 0.3.34__cp39-cp39-macosx_10_13_universal2.whl → 0.3.35__cp39-cp39-macosx_10_13_universal2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyglot_piranha
3
- Version: 0.3.34
3
+ Version: 0.3.35
4
4
  License-File: LICENSE
5
5
  License-File: NOTICE
6
6
  Summary: Polyglot Piranha is a library for performing structural find and replace with deep cleanup.
@@ -0,0 +1,12 @@
1
+ LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
2
+ polyglot_piranha.pyi,sha256=Aef4ZhgaF9WkC5tmBDCLSPmO2_qZUa_hIFf42fpDrD8,10802
3
+ NOTICE,sha256=9bEJKCdL0MABjEknpMHXbYBZSkGVGRXYcSxSXS293X0,147
4
+ polyglot_piranha/__init__.pyi,sha256=Aef4ZhgaF9WkC5tmBDCLSPmO2_qZUa_hIFf42fpDrD8,10802
5
+ polyglot_piranha/__init__.py,sha256=pghVgChf0-NgAG_zd7CzKtvFuBDxg5Wh-GcHx2PoTzg,147
6
+ polyglot_piranha/polyglot_piranha.cpython-39-darwin.so,sha256=6PXVrrAaTfg_spf_N5-LbABoy8KhRa9Ahcto9G2YX08,49097760
7
+ polyglot_piranha/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ polyglot_piranha-0.3.35.dist-info/RECORD,,
9
+ polyglot_piranha-0.3.35.dist-info/WHEEL,sha256=RXxZI60QkhR0dqQRWT8rrkfRTL8-Zao3hIFpXYs8Z2A,136
10
+ polyglot_piranha-0.3.35.dist-info/METADATA,sha256=YB8rrlOkk_ytze3f55Lx4Cs2PaQfCfY670FyzeHPGqc,4918
11
+ polyglot_piranha-0.3.35.dist-info/licenses/LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
12
+ polyglot_piranha-0.3.35.dist-info/licenses/NOTICE,sha256=9bEJKCdL0MABjEknpMHXbYBZSkGVGRXYcSxSXS293X0,147
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.8.6)
2
+ Generator: maturin (1.8.7)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp39-cp39-macosx_10_13_universal2
5
5
  Generator: delocate 0.13.0
polyglot_piranha.pyi ADDED
@@ -0,0 +1,326 @@
1
+ # Copyright (c) 2023 Uber Technologies, Inc.
2
+ #
3
+ # <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4
+ # except in compliance with the License. You may obtain a copy of the License at
5
+ # <p>http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # <p>Unless required by applicable law or agreed to in writing, software distributed under the
8
+ # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
9
+ # express or implied. See the License for the specific language governing permissions and
10
+ # limitations under the License.
11
+
12
+ from __future__ import annotations
13
+ from typing import List, Optional, Literal
14
+
15
+ # Languages that Piranha supports (see ./src/models/language.rs)
16
+ PiranhaLanguage = Literal["java", "kt", "kotlin", "go", "python", "swift", "typescript", "tsx", "thrift", "strings", "scm", "scala", "ruby", "yaml", "yml"]
17
+
18
+
19
+ def execute_piranha(piranha_argument: PiranhaArguments) -> list[PiranhaOutputSummary]:
20
+ """
21
+ Executes piranha for the given `piranha_arguments` and returns `PiranhaOutputSummary` for each file analyzed by Piranha
22
+ Parameters
23
+ ------------
24
+ piranha_arguments: Piranha Arguments
25
+ Configurations for piranha
26
+ Returns
27
+ ------------
28
+ List of `PiranhaOutPutSummary`
29
+ """
30
+ ...
31
+
32
+ class PiranhaArguments:
33
+ """
34
+ A class to capture Piranha's configurations
35
+ """
36
+
37
+ def __init__(
38
+ self,
39
+ language: PiranhaLanguage,
40
+ paths_to_codebase: Optional[List[str]] = None,
41
+ include: Optional[List[str]] = None,
42
+ exclude: Optional[List[str]] = None,
43
+ substitutions: Optional[dict[str, str]] = None,
44
+ path_to_configurations: Optional[str] = None,
45
+ rule_graph: Optional[RuleGraph] = None,
46
+ code_snippet: Optional[str] = None,
47
+ dry_run: Optional[bool] = None,
48
+ cleanup_comments: Optional[bool] = None,
49
+ cleanup_comments_buffer: Optional[int] = None,
50
+ number_of_ancestors_in_parent_scope: Optional[int] = None,
51
+ delete_consecutive_new_lines: Optional[bool] = None,
52
+ global_tag_prefix: Optional[str] = "GLOBAL_TAG",
53
+ delete_file_if_empty: Optional[bool] = None,
54
+ path_to_output: Optional[str] = None,
55
+ allow_dirty_ast: Optional[bool] = None,
56
+ should_validate: Optional[bool] = None,
57
+ experiment_dyn: Optional[bool] = None,
58
+ path_to_custom_builtin_rules: Optional[str] = None,
59
+ ):
60
+ """
61
+ Constructs `PiranhaArguments`
62
+
63
+ Parameters
64
+ ------------
65
+ language: PiranhaLanguage
66
+ the target language
67
+ paths_to_codebase: List[str]
68
+ Paths to source code folder or file
69
+ keyword arguments: _
70
+ substitutions (dict): Substitutions to instantiate the initial set of rules
71
+ path_to_configurations (str): Directory containing the configuration files - `piranha_arguments.toml`, `rules.toml`, and `edges.toml`
72
+ rule_graph (RuleGraph): The rule graph constructed via RuleGraph DSL
73
+ code_snippet (str): The input code snippet to transform
74
+ dry_run (bool): Disables in-place rewriting of code
75
+ cleanup_comments (bool): Enables deletion of associated comments
76
+ cleanup_comments_buffer (int): The number of lines to consider for cleaning up the comments
77
+ number_of_ancestors_in_parent_scope (int): The number of ancestors considered when PARENT rules
78
+ delete_consecutive_new_lines (bool): Replaces consecutive \ns with a \n
79
+ global_tag_prefix (str): the prefix for global tags
80
+ delete_file_if_empty (bool): User option that determines whether an empty file will be deleted
81
+ path_to_output (str): Path to the output json file
82
+ allow_dirty_ast (bool): Allows syntax errors in the input source code
83
+ path_to_custom_builtin_rules (str): If provided, the default built-in rules will be ignored
84
+ """
85
+ ...
86
+
87
+ class PiranhaOutputSummary:
88
+ """
89
+ A class to represent Piranha's output
90
+
91
+ Attributes
92
+ ----------
93
+ path: path to the file
94
+ content: content of the file after all the rewrites
95
+ matches: All the occurrences of "match-only" rules
96
+ rewrites: All the applied edits
97
+ """
98
+
99
+ path: str
100
+ "path to the file"
101
+
102
+ original_content: str
103
+ "Original content of the file before any rewrites"
104
+
105
+ content: str
106
+ "Final content of the file after all the rewrites"
107
+
108
+ matches: list[tuple[str, Match]]
109
+ 'All the occurrences of "match-only" rules'
110
+
111
+ rewrites: list[Edit]
112
+ "All the applied edits"
113
+
114
+ class Edit:
115
+ """
116
+ A class to represent an edit performed by Piranha
117
+
118
+ Attributes
119
+ ----------
120
+ p_match: The match representing the target site of the edit
121
+ replacement_string: The string to replace the substring encompassed by the match
122
+ matched_rule: The rule used for creating this match-replace
123
+ """
124
+
125
+ p_match: Match
126
+ "The match representing the target site of the edit"
127
+
128
+ matched_rule: str
129
+ "The rule used for creating this match-replace"
130
+
131
+ replacement_string: str
132
+ "The string to replace the substring encompassed by the match"
133
+
134
+ class Match:
135
+ """
136
+ A class to represent a match
137
+
138
+ Attributes
139
+ ----------
140
+ matched_sting: Code snippet that matched
141
+ range: Range of the entire AST node captured by the match
142
+ matches: The mapping between tags and string representation of the AST captured
143
+ """
144
+
145
+ matched_string: str
146
+ "Code snippet that matched"
147
+
148
+ range: Range
149
+ "Range of the entire AST node captured by the match"
150
+
151
+ matches: dict[str, str]
152
+ "The mapping between tags and string representation of the AST captured"
153
+ ""
154
+
155
+ class Range:
156
+ """A range of positions in a multi-line text document,
157
+ both in terms of bytes and of rows and columns.
158
+ """
159
+
160
+ start_byte: int
161
+ end_byte: int
162
+ start_point: Point
163
+ end_point: Point
164
+
165
+ class Point:
166
+ row: int
167
+ column: int
168
+
169
+ class Filter:
170
+ """A class to capture filters of a Piranha Rule"""
171
+
172
+ enclosing_node: TSQuery
173
+ "AST patterns that some ancestor node of the primary match should comply"
174
+ not_contains: list[TSQuery]
175
+ "AST patterns that SHOULD NOT match any subtree of node matching `enclosing_node` pattern"
176
+ contains: TSQuery
177
+ "AST pattern that SHOULD match subtrees of `enclosing_node`. " "Number of matches should be within the range of `at_least` and `at_most`."
178
+ at_least: int
179
+ "The minimum number of times the contains query should match in the enclosing node"
180
+ at_most: int
181
+ "The maximum number of times the contains query should match in the enclosing node"
182
+ child_count: int
183
+ "Number of named children under the primary matched node"
184
+ sibling_count: int
185
+ "Number of named siblings of the primary matched node"
186
+ def __init__(
187
+ self,
188
+ enclosing_node: Optional[str] = None,
189
+ not_enclosing_node: Optional[str] = None,
190
+ not_contains: list[str] = [],
191
+ contains: Optional[str] = None,
192
+ at_least: int = 1,
193
+ at_most: int = 4294967295, # u32::MAX
194
+ child_count: int = 4294967295, # u32::MAX
195
+ sibling_count: int = 4294967295, # u32::MAX
196
+ ):
197
+ """
198
+ Constructs `Filter`
199
+
200
+ Parameters
201
+ ------------
202
+ enclosing_node: str
203
+ AST patterns that some ancestor node of the primary match should comply
204
+ not_contains: list[str]
205
+ AST patterns that should not match any subtree of node matching `enclosing_node` pattern
206
+ """
207
+ ...
208
+
209
+ class Rule:
210
+ """A class to capture Piranha Rule"""
211
+
212
+ name: str
213
+ "Name of the rule"
214
+ query: TSQuery
215
+ "Tree-sitter query as string"
216
+ replace_node: str
217
+ "The tag corresponding to the node to be replaced"
218
+ replace_node_idx: str
219
+ "The i'th child of node corresponding to the replace_node tag will be replaced"
220
+ replace: str
221
+ "Replacement pattern"
222
+ groups: set[str]
223
+ "Group(s) to which the rule belongs"
224
+ holes: set[str]
225
+ "Holes that need to be filled, in order to instantiate a rule"
226
+ filters: set[Filter]
227
+ "Filters to test before applying a rule"
228
+ is_seed_rule: bool
229
+ "Marks a rule as a seed rule"
230
+ keep_comment_regexes: set[str]
231
+ "Make comment deleting optional"
232
+
233
+ def __init__(
234
+ self,
235
+ name: str,
236
+ query: Optional[str] = None,
237
+ replace_node: Optional[str] = None,
238
+ replace: Optional[str] = None,
239
+ groups: set[str] = set(),
240
+ holes: set[str] = set(),
241
+ filters: set[Filter] = set(),
242
+ is_seed_rule: bool = True,
243
+ keep_comment_regexes: Optional[set[str]] = None,
244
+ ):
245
+ """
246
+ Constructs `Rule`
247
+
248
+ Parameters
249
+ ------------
250
+ name: str
251
+ Name of the rule
252
+ query: str
253
+ Tree-sitter query as string
254
+ replace_node: str
255
+ The tag corresponding to the node to be replaced
256
+ replace: str
257
+ Replacement pattern
258
+ groups: set[str]
259
+ Group(s) to which the rule belongs
260
+ holes: set[str]
261
+ Holes that need to be filled, in order to instantiate a rule
262
+ filters: set[Filter]
263
+ Filters to test before applying a rule
264
+ is_seed_rule: bool
265
+ Marks a rule as a seed rule
266
+ """
267
+ ...
268
+
269
+ class OutgoingEdges:
270
+ frm: str
271
+ "The source rule or group of rules"
272
+ to: list[str]
273
+ "The target edges or groups of edges"
274
+ scope: str
275
+ "The scope label for the edge"
276
+
277
+ def __init__(
278
+ self,
279
+ frm: str,
280
+ to: list[str],
281
+ scope: str,
282
+ ):
283
+ """
284
+ Constructs `OutgoingEdge`
285
+
286
+ Parameters
287
+ ------------
288
+ frm: str
289
+ The source rule or group of rules
290
+ to: list[str]
291
+ The target edges or groups of edges
292
+ scope: str
293
+ The scope label for the edge
294
+ """
295
+ ...
296
+
297
+ class RuleGraph:
298
+ rules: list[Rule]
299
+ "The rules in the graph"
300
+ edges: list[OutgoingEdges]
301
+ "The edges in the graph"
302
+ graph: dict[str, list[tuple[str, str]]]
303
+ "The graph itself (as an adjacency list)"
304
+
305
+ def __init__(
306
+ self,
307
+ rules: list[Rule],
308
+ edges: list[OutgoingEdges],
309
+ ):
310
+ """
311
+ Constructs `OutgoingEdge`
312
+
313
+ Parameters
314
+ ------------
315
+ rules: list[Rule]
316
+ The rules in the graph
317
+ edges: list[OutgoingEdges]
318
+ The edges in the graph
319
+ """
320
+ ...
321
+
322
+ class TSQuery:
323
+ "Captures a Tree sitter query"
324
+ def query(self):
325
+ """The query"""
326
+ ...
@@ -1,11 +0,0 @@
1
- LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
2
- NOTICE,sha256=9bEJKCdL0MABjEknpMHXbYBZSkGVGRXYcSxSXS293X0,147
3
- polyglot_piranha/__init__.pyi,sha256=Aef4ZhgaF9WkC5tmBDCLSPmO2_qZUa_hIFf42fpDrD8,10802
4
- polyglot_piranha/__init__.py,sha256=pghVgChf0-NgAG_zd7CzKtvFuBDxg5Wh-GcHx2PoTzg,147
5
- polyglot_piranha/polyglot_piranha.cpython-39-darwin.so,sha256=KxOyx5RMUWHvxEfGGcyaOZELFbjTzQ-K52wopZgaPps,49097440
6
- polyglot_piranha/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- polyglot_piranha-0.3.34.dist-info/RECORD,,
8
- polyglot_piranha-0.3.34.dist-info/WHEEL,sha256=T9iYDKvFAMFXRfa0htlI8TnYOpVpfGPujmjDRJ-vP0o,136
9
- polyglot_piranha-0.3.34.dist-info/METADATA,sha256=e4asUYM4U_pE7b5V-DIx0W9QwTGab9MPW4dQ16S8EHE,4918
10
- polyglot_piranha-0.3.34.dist-info/licenses/LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
11
- polyglot_piranha-0.3.34.dist-info/licenses/NOTICE,sha256=9bEJKCdL0MABjEknpMHXbYBZSkGVGRXYcSxSXS293X0,147