polyglot-piranha 0.3.0__cp38-cp38-macosx_10_16_x86_64.whl → 0.3.4__cp38-cp38-macosx_10_16_x86_64.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,4 +1,4 @@
1
- # Copyright (c) 2022 Uber Technologies, Inc.
1
+ # Copyright (c) 2023 Uber Technologies, Inc.
2
2
  #
3
3
  # <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4
4
  # except in compliance with the License. You may obtain a copy of the License at
@@ -9,7 +9,7 @@
9
9
  # express or implied. See the License for the specific language governing permissions and
10
10
  # limitations under the License.
11
11
 
12
- from typing import Optional
12
+ from typing import List, Optional
13
13
 
14
14
 
15
15
  def execute_piranha(piranha_argument: PiranhaArguments) -> list[PiranhaOutputSummary]:
@@ -33,19 +33,22 @@ class PiranhaArguments:
33
33
  def __init__(
34
34
  self,
35
35
  language: str,
36
- substitutions: dict,
37
- path_to_configurations: Optional[str],
38
- rule_graph: Optional[RuleGraph]= None,
39
36
  path_to_codebase: Optional[str] = None,
37
+ include: Optional[List[str]] = None,
38
+ exclude: Optional[List[str]] = None,
39
+ substitutions: Optional[dict] = None,
40
+ path_to_configurations: Optional[str] = None,
41
+ rule_graph: Optional[RuleGraph]= None,
40
42
  code_snippet: Optional[str] = None,
41
43
  dry_run: Optional[bool] = None,
42
44
  cleanup_comments: Optional[bool] = None,
43
45
  cleanup_comments_buffer: Optional[int] = None,
44
46
  number_of_ancestors_in_parent_scope: Optional[int] = None,
45
- delete_file_if_empty : Optional[bool] = None,
46
- delete_consecutive_new_lines : Optional[bool] = None,
47
- path_to_output: Optional[str] = None
48
-
47
+ delete_consecutive_new_lines: Optional[bool] = None,
48
+ global_tag_prefix: Optional[str] = 'GLOBAL_TAG',
49
+ delete_file_if_empty: Optional[bool] = None,
50
+ path_to_output: Optional[str] = None,
51
+ allow_dirty_ast: Optional[bool] = None
49
52
  ):
50
53
  """
51
54
  Constructs `PiranhaArguments`
@@ -54,20 +57,22 @@ class PiranhaArguments:
54
57
  ------------
55
58
  language: str
56
59
  the target language
57
- substitutions: dict
58
- Substitutions to instantiate the initial set of rules
60
+ path_to_codebase: str
61
+ Path to source code folder or file
59
62
  keyword arguments: _
60
- path_to_configurations (str) : Directory containing the configuration files - `piranha_arguments.toml`, `rules.toml`, and `edges.toml`
61
- rule_graph (RuleGraph) : The rule graph constructed via RuleGraph DSL
62
- path_to_codebase (str) : Path to source code folder or file
63
- code_snippet (str) : The input code snippet to transform
64
- dry_run (bool) : Disables in-place rewriting of code
65
- cleanup_comments (bool) : Enables deletion of associated comments
63
+ substitutions (dict): Substitutions to instantiate the initial set of rules
64
+ path_to_configurations (str): Directory containing the configuration files - `piranha_arguments.toml`, `rules.toml`, and `edges.toml`
65
+ rule_graph (RuleGraph): The rule graph constructed via RuleGraph DSL
66
+ code_snippet (str): The input code snippet to transform
67
+ dry_run (bool): Disables in-place rewriting of code
68
+ cleanup_comments (bool): Enables deletion of associated comments
66
69
  cleanup_comments_buffer (int): The number of lines to consider for cleaning up the comments
67
70
  number_of_ancestors_in_parent_scope (int): The number of ancestors considered when PARENT rules
71
+ delete_consecutive_new_lines (bool): Replaces consecutive \ns with a \n
72
+ global_tag_prefix (str): the prefix for global tags
68
73
  delete_file_if_empty (bool): User option that determines whether an empty file will be deleted
69
- delete_consecutive_new_lines (bool) : Replaces consecutive \ns with a \n
70
74
  path_to_output (str): Path to the output json file
75
+ allow_dirty_ast (bool): Allows syntax errors in the input source code
71
76
  """
72
77
  ...
73
78
 
@@ -77,17 +82,20 @@ class PiranhaOutputSummary:
77
82
 
78
83
  Attributes
79
84
  ----------
80
- path : path to the file
81
- content : content of the file after all the rewrites
82
- matches : All the occurrences of "match-only" rules
85
+ path: path to the file
86
+ content: content of the file after all the rewrites
87
+ matches: All the occurrences of "match-only" rules
83
88
  rewrites: All the applied edits
84
89
  """
85
90
 
86
91
  path: str
87
92
  "path to the file"
88
93
 
94
+ original_content: str
95
+ "Original content of the file before any rewrites"
96
+
89
97
  content: str
90
- "content of the file after all the rewrites"
98
+ "Final content of the file after all the rewrites"
91
99
 
92
100
  matches: list[tuple[str, Match]]
93
101
  'All the occurrences of "match-only" rules'
@@ -101,9 +109,9 @@ class Edit:
101
109
 
102
110
  Attributes
103
111
  ----------
104
- p_match : The match representing the target site of the edit
105
- replacement_string : The string to replace the substring encompassed by the match
106
- matched_rule : The rule used for creating this match-replace
112
+ p_match: The match representing the target site of the edit
113
+ replacement_string: The string to replace the substring encompassed by the match
114
+ matched_rule: The rule used for creating this match-replace
107
115
  """
108
116
 
109
117
  p_match: Match
@@ -121,9 +129,9 @@ class Match:
121
129
 
122
130
  Attributes
123
131
  ----------
124
- matched_sting : Code snippet that matched
125
- range : Range of the entire AST node captured by the match
126
- matches : The mapping between tags and string representation of the AST captured
132
+ matched_sting: Code snippet that matched
133
+ range: Range of the entire AST node captured by the match
134
+ matches: The mapping between tags and string representation of the AST captured
127
135
  """
128
136
 
129
137
  matched_string: str
@@ -150,28 +158,37 @@ class Point:
150
158
  row: int
151
159
  column: int
152
160
 
153
- class Constraint:
154
- """ A class to capture Constraints of a Piranha Rule
161
+ class Filter:
162
+ """ A class to capture filters of a Piranha Rule
155
163
  """
156
- matcher: TSQuery
157
- "Scope in which the constraint query has to be applied"
158
- queries: list[TSQuery]
159
- "The Tree-sitter queries that need to be applied in the `matcher` scope"
160
-
164
+ enclosing_node: TSQuery
165
+ "AST patterns that some ancestor node of the primary match should comply"
166
+ not_contains: list[TSQuery]
167
+ "AST patterns that SHOULD NOT match any subtree of node matching `enclosing_node` pattern"
168
+ contains: TSQuery
169
+ "AST pattern that SHOULD match subtrees of `enclosing_node`. " \
170
+ "Number of matches should be within the range of `at_least` and `at_most`."
171
+ at_least: int
172
+ "The minimum number of times the contains query should match in the enclosing node"
173
+ at_most: int
174
+ "The maximum number of times the contains query should match in the enclosing node"
161
175
  def __init__(
162
176
  self,
163
- matcher: str,
164
- queries: list[str] = []
177
+ enclosing_node: str = '',
178
+ not_contains: list[str] = [],
179
+ contains: str = '',
180
+ at_least: int = 1,
181
+ at_most: int = 4294967295 # u32::MAX
165
182
  ):
166
183
  """
167
- Constructs `Constraint`
184
+ Constructs `Filter`
168
185
 
169
186
  Parameters
170
187
  ------------
171
- matcher: str
172
- Scope in which the constraint query has to be applied
173
- queries: list[str]
174
- The Tree-sitter queries that need to be applied in the `matcher` scope
188
+ enclosing_node: str
189
+ AST patterns that some ancestor node of the primary match should comply
190
+ not_contains: list[str]
191
+ AST patterns that should not match any subtree of node matching `enclosing_node` pattern
175
192
  """
176
193
  ...
177
194
 
@@ -190,8 +207,8 @@ class Rule:
190
207
  "Group(s) to which the rule belongs"
191
208
  holes: set[str]
192
209
  "Holes that need to be filled, in order to instantiate a rule"
193
- constraints: set[Constraint]
194
- "Additional constraints for matching the rule"
210
+ filters: set[Filter]
211
+ "Filters to test before applying a rule"
195
212
 
196
213
  def __init__(
197
214
  self,
@@ -201,7 +218,7 @@ class Rule:
201
218
  replace: Optional[str] = None,
202
219
  groups: set[str] = set(),
203
220
  holes: set[str] = set(),
204
- constraints: set[Constraint] = set(),
221
+ filters: set[Filter] = set(),
205
222
  is_seed_rule: bool = True,
206
223
  ):
207
224
  """
@@ -221,8 +238,8 @@ class Rule:
221
238
  Group(s) to which the rule belongs
222
239
  holes: set[str]
223
240
  Holes that need to be filled, in order to instantiate a rule
224
- constraints: set[Constraint]
225
- Additional constraints for matching the rule
241
+ filters: set[Filter]
242
+ Filters to test before applying a rule
226
243
  """
227
244
  ...
228
245
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyglot_piranha
3
- Version: 0.3.0
3
+ Version: 0.3.4
4
4
  License-File: LICENSE
5
5
  License-File: LICENSE
6
6
  License-File: NOTICE
@@ -10,9 +10,9 @@ Author: Uber Technologies Inc.
10
10
  Author-email: Ameya Ketkar <ketkara@uber.com>, Lazaro Clapp <lazaro@uber.com>
11
11
  Requires-Python: >=3.7
12
12
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
13
+ Project-URL: homepage, https://github.com/uber/piranha
13
14
  Project-URL: documentation, https://github.com/uber/piranha
14
15
  Project-URL: repository, https://github.com/uber/piranha
15
- Project-URL: homepage, https://github.com/uber/piranha
16
16
 
17
17
  # Piranha
18
18
 
@@ -0,0 +1,10 @@
1
+ polyglot_piranha-0.3.4.dist-info/METADATA,sha256=0ibaLIqcy7Fg1mUV_0ZWFWjxyo7RlwQlizMsNYbVuWQ,3797
2
+ polyglot_piranha-0.3.4.dist-info/WHEEL,sha256=nqll5ynhXCwomcBqYs3lJrWlr8aFscLjrHGA10xvryk,104
3
+ polyglot_piranha-0.3.4.dist-info/license_files/LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
4
+ polyglot_piranha-0.3.4.dist-info/license_files/LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
5
+ polyglot_piranha-0.3.4.dist-info/license_files/NOTICE,sha256=9bEJKCdL0MABjEknpMHXbYBZSkGVGRXYcSxSXS293X0,147
6
+ polyglot_piranha/__init__.py,sha256=pghVgChf0-NgAG_zd7CzKtvFuBDxg5Wh-GcHx2PoTzg,147
7
+ polyglot_piranha/__init__.pyi,sha256=sDMJC2xnL0QPNkBARAljzgwu7D-hbccyC-79r9p0djw,9476
8
+ polyglot_piranha/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ polyglot_piranha/polyglot_piranha.cpython-38-darwin.so,sha256=g3_ubd4UZmfKn-KhCHag4BEj2_bLifMXzQUF7eHnPSA,13625120
10
+ polyglot_piranha-0.3.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (0.14.15)
2
+ Generator: maturin (1.0.0)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp38-cp38-macosx_10_16_x86_64
@@ -1,10 +0,0 @@
1
- polyglot_piranha-0.3.0.dist-info/METADATA,sha256=uXFsx2SMxlQRLRkUfABg3gRfDWdyeg5etrZ_3nr8Tuo,3797
2
- polyglot_piranha-0.3.0.dist-info/WHEEL,sha256=R9as0yyHDf-HADVClq720BdoCu3SSus4Pahnk2I6QnQ,106
3
- polyglot_piranha-0.3.0.dist-info/license_files/LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
4
- polyglot_piranha-0.3.0.dist-info/license_files/LICENSE,sha256=7qqytxojDvLpt8CphcCVvEQilegiJ0x_oDkwHJU-1z4,11359
5
- polyglot_piranha-0.3.0.dist-info/license_files/NOTICE,sha256=9bEJKCdL0MABjEknpMHXbYBZSkGVGRXYcSxSXS293X0,147
6
- polyglot_piranha/__init__.py,sha256=pghVgChf0-NgAG_zd7CzKtvFuBDxg5Wh-GcHx2PoTzg,147
7
- polyglot_piranha/__init__.pyi,sha256=76ufpcBsLCDOjAJucqyrFsBp8zPRVnpAnyfFQou7Srg,8480
8
- polyglot_piranha/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- polyglot_piranha/polyglot_piranha.cpython-38-darwin.so,sha256=fokYp5cEqWVAgT5Wp6ZICt5GjTAgFLUFJnGz5J3cDjk,13094992
10
- polyglot_piranha-0.3.0.dist-info/RECORD,,