opencode-pine2pyne 0.2.3__py3-none-any.whl → 0.2.4__py3-none-any.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.
- {opencode_pine2pyne-0.2.3.dist-info → opencode_pine2pyne-0.2.4.dist-info}/METADATA +4 -4
- {opencode_pine2pyne-0.2.3.dist-info → opencode_pine2pyne-0.2.4.dist-info}/RECORD +8 -8
- {opencode_pine2pyne-0.2.3.dist-info → opencode_pine2pyne-0.2.4.dist-info}/WHEEL +1 -1
- pine2pyne/__init__.py +1 -1
- pine2pyne/scope_renamer.py +49 -3
- {opencode_pine2pyne-0.2.3.dist-info → opencode_pine2pyne-0.2.4.dist-info}/entry_points.txt +0 -0
- {opencode_pine2pyne-0.2.3.dist-info → opencode_pine2pyne-0.2.4.dist-info}/licenses/LICENSE +0 -0
- {opencode_pine2pyne-0.2.3.dist-info → opencode_pine2pyne-0.2.4.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opencode-pine2pyne
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Pine Script v6 to PyneCore Python transpiler
|
|
5
5
|
Author: rubycell
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -35,9 +35,9 @@ Backlog and known bugs: [Projects board #10](https://github.com/users/rubycell/p
|
|
|
35
35
|
of the PyneCore runtime (repo `/home/mike/workspace/github/pynecore`).
|
|
36
36
|
- Where it runs: a command-line tool and a Python library. It has no service, no port and no host of its own.
|
|
37
37
|
Development happens on mike-PC. Full test suites run on Minh_pc (see section 7).
|
|
38
|
-
- Package: `opencode-pine2pyne` on PyPI, version `0.2.
|
|
39
|
-
Live PyPI state is UNVERIFIED: 0.2.
|
|
40
|
-
`CHANGELOG.md` lists #
|
|
38
|
+
- Package: `opencode-pine2pyne` on PyPI, version `0.2.4` in `pine2pyne/__init__.py` and `CHANGELOG.md`.
|
|
39
|
+
Live PyPI state is UNVERIFIED: 0.2.4 is prepared (commit and local tag `v0.2.4`), not uploaded. 0.2.3 is on PyPI.
|
|
40
|
+
`CHANGELOG.md` lists #119 and its export case under 0.2.4; the tag `v0.2.3` is the release before them.
|
|
41
41
|
- The transpiler imports only the standard library (`pyproject.toml`: `dependencies = []`).
|
|
42
42
|
The generated script needs the runtime `opencode-pyneruntime` (`runtime` extra, `>=6.9.1`).
|
|
43
43
|
- License: Apache-2.0 (`pyproject.toml`, `LICENSE`).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
opencode_pine2pyne-0.2.
|
|
1
|
+
opencode_pine2pyne-0.2.4.dist-info/licenses/LICENSE,sha256=l6ZEJ0BCsllGRX5Pg-ygs6mQD03fLXJggIyKnSMwC8E,11342
|
|
2
2
|
pine2pyne/README.md,sha256=7O2y_Jn9EQ6yNXZio7qAvEqdfVnuiJE_C6zyTdWkUgM,6021
|
|
3
3
|
pine2pyne/TRANSPILER_BEST_PRACTICES.md,sha256=I9UQYI-KlObGGODfItU0kIt-Bo6MVh9XgPfXPRvjh_4,18197
|
|
4
4
|
pine2pyne/TRANSPILER_USAGE.md,sha256=7iT-dnig8t-gMxozVYHgKoxr7W--SITLoyJk41PYlrs,5569
|
|
5
|
-
pine2pyne/__init__.py,sha256=
|
|
5
|
+
pine2pyne/__init__.py,sha256=PqJf1aRI8XZcTorES777Ia80YJmS19NYMpm4FVIahig,2436
|
|
6
6
|
pine2pyne/__main__.py,sha256=w6UY1yZijkjI0YRgq03guOunEYTp9S4DjwsAips2GOk,228
|
|
7
7
|
pine2pyne/ast_nodes.py,sha256=xk0Zrjdip1sZWE6WINKFK4AK3ikxcOnZkirC9RwDl0E,11354
|
|
8
8
|
pine2pyne/ast_walk.py,sha256=Qt0HUyF7nR3G9kErTB22TuarUJ0g4xQV8QBQ3YeuuIg,4037
|
|
@@ -27,7 +27,7 @@ pine2pyne/parse_repair.py,sha256=Uec959EDCvnqeHdVD1ZpSizH150rUAk55BnYF9EbNBM,188
|
|
|
27
27
|
pine2pyne/parser.py,sha256=c-JQu6LEls_EacpeSGfOHZJSJo_k25wJ9CnojZI3CqE,77634
|
|
28
28
|
pine2pyne/pine_builtins.py,sha256=XRds4zd7t2Twdgi7dK06iEvpw73glo863CaSz0wKG5s,16733
|
|
29
29
|
pine2pyne/pine_semantics.py,sha256=e0CSoUCFp6BYzb2XNIi5_cQVgHfm--lMTKGvaTuraJw,34765
|
|
30
|
-
pine2pyne/scope_renamer.py,sha256=
|
|
30
|
+
pine2pyne/scope_renamer.py,sha256=SW0Cga1UzSIcteqGX-acCOQKjVMxqPuGkuGOmvIIRjA,47809
|
|
31
31
|
pine2pyne/strategy_when_lowering.py,sha256=bN5rAEKGy6bkp3Rm093GnAfpwtswExYsBbBGOdMeMbo,5334
|
|
32
32
|
pine2pyne/strict_boolean.py,sha256=7Z-q2tdVk0rFgu4SecX9GVaWgBof_IFtBKjw1tBolB0,5471
|
|
33
33
|
pine2pyne/symbol_table.py,sha256=SO40do-faSu-n29-5GOrkKAqEK6Ef9BGtw4sC0w9Jbo,6146
|
|
@@ -35,8 +35,8 @@ pine2pyne/tokens.py,sha256=diG6z5_9DsDCdSN-sapdDAbdIwvklQPuC-05tkhQzDk,3792
|
|
|
35
35
|
pine2pyne/transformer.py,sha256=mwgIMx1GRapzPsZfDWNY16NTxDPVsYVI3Y4svWlud3w,115673
|
|
36
36
|
pine2pyne/type_inference.py,sha256=UFg7y9Q5Vkd_NnjQ1DD9LrqJ3ywpHSMHv28D_lQlb08,19895
|
|
37
37
|
pine2pyne/udt_field_defaults.py,sha256=DpOwtiCxKdQjAK5senw2wAzT7JNfgRl3NxCrlLTfk3c,7746
|
|
38
|
-
opencode_pine2pyne-0.2.
|
|
39
|
-
opencode_pine2pyne-0.2.
|
|
40
|
-
opencode_pine2pyne-0.2.
|
|
41
|
-
opencode_pine2pyne-0.2.
|
|
42
|
-
opencode_pine2pyne-0.2.
|
|
38
|
+
opencode_pine2pyne-0.2.4.dist-info/METADATA,sha256=qyX1DNP9q_oasUTaTIu6nahNKhStgJglBD4sqfqART8,24367
|
|
39
|
+
opencode_pine2pyne-0.2.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
40
|
+
opencode_pine2pyne-0.2.4.dist-info/entry_points.txt,sha256=OQmVtMqXUdYsmXqUEe09w30h54Gmn3JsPjGgVnTO4sA,49
|
|
41
|
+
opencode_pine2pyne-0.2.4.dist-info/top_level.txt,sha256=ge_qvuxsfM_9zOv_hIwyLCMe1S8RAr5nUR6n3aBO6J0,10
|
|
42
|
+
opencode_pine2pyne-0.2.4.dist-info/RECORD,,
|
pine2pyne/__init__.py
CHANGED
pine2pyne/scope_renamer.py
CHANGED
|
@@ -22,6 +22,9 @@ not the binding's own member (see library_collision.MemberRule). Two kinds of
|
|
|
22
22
|
binding keep their name: an input (its name is the key of the script's input
|
|
23
23
|
settings) and an `export` declaration (its name is the library's API); a
|
|
24
24
|
namespace use under such a binding reads an alias of the namespace instead.
|
|
25
|
+
An `export` with a parameter named like a function or method of the script is split into a private `f_body<N>`
|
|
26
|
+
(the same body, its parameters renamed like any function's) and the public export, which keeps the parameter names
|
|
27
|
+
and calls it (card #119).
|
|
25
28
|
|
|
26
29
|
A local named like a builtin series variable (`close`, `time`, `hour`) gets its own name
|
|
27
30
|
wherever it is declared below the top level: in a function, as a loop variable (card #84) or
|
|
@@ -103,11 +106,39 @@ class Binding:
|
|
|
103
106
|
def rename_shadowing_locals(script: Script) -> RenamedScript:
|
|
104
107
|
"""Return a copy of `script` with shadowing locals and library-named
|
|
105
108
|
bindings renamed. The input script is not modified."""
|
|
109
|
+
script = split_exports_with_shadowed_callees(script)
|
|
106
110
|
renamer = _ScopeRenamer(script)
|
|
107
111
|
return RenamedScript(renamer.run(script), renamer.namespace_aliases,
|
|
108
112
|
{name: renames for name, renames in renamer.parameter_names.items() if renames})
|
|
109
113
|
|
|
110
114
|
|
|
115
|
+
def split_exports_with_shadowed_callees(script: Script) -> Script:
|
|
116
|
+
"""An `export` function keeps its parameter names (its public signature), so a parameter named like a
|
|
117
|
+
function or method of the script hides that function from the exported body. Such an export becomes a
|
|
118
|
+
private function with the same body, whose parameters the renamer then renames like any function's, and an
|
|
119
|
+
export of the same signature that calls it (card #119 follow-up)."""
|
|
120
|
+
function_names = {declaration.name for declaration in script.declarations if isinstance(declaration, FuncDecl)}
|
|
121
|
+
used_names = collect_names(script)
|
|
122
|
+
declarations = []
|
|
123
|
+
split_any = False
|
|
124
|
+
for declaration in script.declarations:
|
|
125
|
+
if not (isinstance(declaration, FuncDecl) and declaration.is_export
|
|
126
|
+
and any(parameter.name in function_names for parameter in declaration.params)):
|
|
127
|
+
declarations.append(declaration)
|
|
128
|
+
continue
|
|
129
|
+
split_any = True
|
|
130
|
+
private_name = fresh_name(f'{declaration.name}_body', used_names)
|
|
131
|
+
declarations.append(dataclasses.replace(
|
|
132
|
+
declaration, name=private_name, is_export=False, is_overload=False,
|
|
133
|
+
params=[dataclasses.replace(parameter, default=None) for parameter in declaration.params]))
|
|
134
|
+
declarations.append(dataclasses.replace(
|
|
135
|
+
declaration, indexed_params=set(),
|
|
136
|
+
body=FunctionCall(func=private_name, args=[Identifier(name=parameter.name)
|
|
137
|
+
for parameter in declaration.params],
|
|
138
|
+
line=declaration.line, column=declaration.column)))
|
|
139
|
+
return dataclasses.replace(script, declarations=declarations) if split_any else script
|
|
140
|
+
|
|
141
|
+
|
|
111
142
|
def collect_names(tree) -> Set[str]:
|
|
112
143
|
"""Every identifier-like string in the tree: the names a fresh name must avoid."""
|
|
113
144
|
names: Set[str] = set()
|
|
@@ -205,8 +236,11 @@ class _ScopeRenamer:
|
|
|
205
236
|
# sanitized spellings of keyword-named inputs and exports: the settings id and the
|
|
206
237
|
# library API keep them, so another binding of that spelling moves
|
|
207
238
|
self.external_spellings: Set[str] = set()
|
|
208
|
-
# keyword-named input whose spelling another input holds
|
|
239
|
+
# keyword-named input whose spelling another input holds, or input named like a function or method of
|
|
240
|
+
# the script -> its new name
|
|
209
241
|
self.moved_inputs: Dict[str, str] = {}
|
|
242
|
+
# the inputs named like a function or method of the script: they keep their Pine label (card #119)
|
|
243
|
+
self.inputs_named_like_a_function: Set[str] = set()
|
|
210
244
|
self.moved_bindings = False
|
|
211
245
|
# global named like a builtin series -> its first declaration: an input (card #86), a
|
|
212
246
|
# var, an assignment or a tuple target (card #89)
|
|
@@ -479,6 +513,9 @@ class _ScopeRenamer:
|
|
|
479
513
|
renames = self.parameter_names.setdefault(name, {})
|
|
480
514
|
renamed_names = self.library_names if name in exported else self.library_names | global_names
|
|
481
515
|
renamed_names = renamed_names | self.external_spellings
|
|
516
|
+
if name not in exported:
|
|
517
|
+
# a parameter named like a function or method of the script hides it from the body (card #119)
|
|
518
|
+
renamed_names = renamed_names | self.user_function_names | self.method_names
|
|
482
519
|
for parameter in declaration.params:
|
|
483
520
|
if parameter.name in renamed_names and parameter.name not in renames:
|
|
484
521
|
renames[parameter.name] = self.fresh_name(parameter.name)
|
|
@@ -511,6 +548,12 @@ class _ScopeRenamer:
|
|
|
511
548
|
self.moved_inputs[name] = free_spelling(spelling, self.spellings.occupied)
|
|
512
549
|
else:
|
|
513
550
|
self.external_spellings.add(spelling)
|
|
551
|
+
# an input named like a function or method of the script: the input is a parameter of main() and the
|
|
552
|
+
# script's functions are defined inside main(), so the function overwrites the parameter (card #119)
|
|
553
|
+
self.inputs_named_like_a_function = {name for name in input_names
|
|
554
|
+
if name in self.user_function_names or name in self.method_names}
|
|
555
|
+
for name in sorted(self.inputs_named_like_a_function - self.moved_inputs.keys()):
|
|
556
|
+
self.moved_inputs[name] = self.fresh_name(name)
|
|
514
557
|
exported = {node.name for node in script.declarations
|
|
515
558
|
if isinstance(node, FuncDecl) and node.is_export}
|
|
516
559
|
for name in sorted(exported & PYTHON_RESERVED_WORDS):
|
|
@@ -662,8 +705,11 @@ class _ScopeRenamer:
|
|
|
662
705
|
[declaration.args, declaration.kwargs])
|
|
663
706
|
arguments = self.expression(declaration.args), self.expression(declaration.kwargs)
|
|
664
707
|
self.scopes[0].update(saved)
|
|
665
|
-
|
|
666
|
-
|
|
708
|
+
args, kwargs = arguments
|
|
709
|
+
if name in self.inputs_named_like_a_function and len(args) < 2 and 'title' not in kwargs:
|
|
710
|
+
# Pine shows the variable name when the call gives no title: the rename must not change the label
|
|
711
|
+
kwargs = {**kwargs, 'title': Literal(value=name, literal_type='string', is_double_quoted=True)}
|
|
712
|
+
return dataclasses.replace(declaration, name=self.moved_inputs.get(name, name), args=args, kwargs=kwargs)
|
|
667
713
|
|
|
668
714
|
def read_builtin_by_alias(self, names: Set[str], tree) -> Dict[str, Binding]:
|
|
669
715
|
"""Until the caller restores the returned bindings, each input of `names` that `tree`
|
|
File without changes
|
|
File without changes
|
|
File without changes
|