pyscript-programming-language 1.15.1__py3-none-any.whl → 1.15.2__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.
- pyscript/__main__.py +2 -2
- pyscript/core/constants.py +2 -1
- pyscript/core/handlers.py +13 -1
- pyscript/core/highlight.py +0 -1
- pyscript/core/interpreter.py +9 -5
- pyscript/core/nodes.py +44 -16
- pyscript/core/parser.py +47 -42
- pyscript/core/pysbuiltins.py +10 -6
- pyscript/core/pystypes.py +8 -3
- pyscript/core/shell.py +15 -17
- pyscript/core/utils/decorators.py +4 -3
- pyscript/core/utils/string.py +4 -2
- pyscript/core/version.py +2 -2
- pyscript/lib/dual/py_dual.py +11 -17
- pyscript/lib/explorer.pys +53 -75
- pyscript/lib/getch/__init__.pys +2 -1
- pyscript/lib/getch/py_getch.py +5 -2
- pyscript/lib/history.pys +15 -5
- pyscript/lib/site.pys +19 -19
- pyscript/other/message.txt +11 -1
- {pyscript_programming_language-1.15.1.dist-info → pyscript_programming_language-1.15.2.dist-info}/METADATA +9 -8
- {pyscript_programming_language-1.15.1.dist-info → pyscript_programming_language-1.15.2.dist-info}/RECORD +25 -25
- /pyscript/{site-packages → lib}/this.pys +0 -0
- {pyscript_programming_language-1.15.1.dist-info → pyscript_programming_language-1.15.2.dist-info}/WHEEL +0 -0
- {pyscript_programming_language-1.15.1.dist-info → pyscript_programming_language-1.15.2.dist-info}/top_level.txt +0 -0
pyscript/__main__.py
CHANGED
|
@@ -139,7 +139,7 @@ parser.add_argument(
|
|
|
139
139
|
parser.add_argument(
|
|
140
140
|
'-t', '--terminal',
|
|
141
141
|
action='store_true',
|
|
142
|
-
help="configure terminal encoding to
|
|
142
|
+
help=f"configure terminal encoding to {pys_sys.encoding} and enable ANSI escape code processing on Windows"
|
|
143
143
|
)
|
|
144
144
|
|
|
145
145
|
parser.add_argument(
|
|
@@ -216,7 +216,7 @@ if args.terminal:
|
|
|
216
216
|
|
|
217
217
|
for fd in (sys.stdout, sys.stderr, sys.stdin):
|
|
218
218
|
try:
|
|
219
|
-
fd.reconfigure(encoding=
|
|
219
|
+
fd.reconfigure(encoding=pys_sys.encoding)
|
|
220
220
|
except:
|
|
221
221
|
continue
|
|
222
222
|
|
pyscript/core/constants.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import site
|
|
2
3
|
|
|
3
4
|
PYSCRIPT_PATH = os.path.sep.join(__file__.split(os.path.sep)[:-2])
|
|
4
5
|
CORE_PATH = os.path.join(PYSCRIPT_PATH, 'core')
|
|
5
6
|
LIBRARIES_PATH = os.path.join(PYSCRIPT_PATH, 'lib')
|
|
6
7
|
OTHER_PATH = os.path.join(PYSCRIPT_PATH, 'other')
|
|
7
|
-
SITE_PACKAGES_PATH = os.path.join(
|
|
8
|
+
SITE_PACKAGES_PATH = os.path.join(site.getusersitepackages(), 'pyscript')
|
|
8
9
|
ICON_PATH = os.path.join(OTHER_PATH, 'PyScript.ico')
|
|
9
10
|
GLOBAL_HISTORY_PATH = os.path.join(os.path.expanduser('~'), '.pyscript_history')
|
|
10
11
|
CONFIGURATIONS_PATH = os.path.join(OTHER_PATH, 'configurations.json')
|
pyscript/core/handlers.py
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
from .cache import pys_sys
|
|
2
|
-
from .constants import ENV_PYSCRIPT_WITH_GIL
|
|
2
|
+
from .constants import SITE_PACKAGES_PATH, ENV_PYSCRIPT_WITH_GIL
|
|
3
3
|
from .context import PysContext
|
|
4
4
|
from .position import PysPosition
|
|
5
5
|
from .pystypes import PysFunction
|
|
6
6
|
from .utils.generic import is_environ
|
|
7
7
|
|
|
8
|
+
from site import ENABLE_USER_SITE
|
|
8
9
|
from types import MethodType
|
|
9
10
|
from typing import Any
|
|
10
11
|
|
|
12
|
+
import os
|
|
13
|
+
|
|
11
14
|
wrapper_function = (MethodType, classmethod, staticmethod)
|
|
12
15
|
|
|
16
|
+
if ENABLE_USER_SITE:
|
|
17
|
+
try:
|
|
18
|
+
if os.path.isfile(SITE_PACKAGES_PATH):
|
|
19
|
+
os.remove(SITE_PACKAGES_PATH)
|
|
20
|
+
if not os.path.exists(SITE_PACKAGES_PATH):
|
|
21
|
+
os.mkdir(SITE_PACKAGES_PATH)
|
|
22
|
+
except:
|
|
23
|
+
pass
|
|
24
|
+
|
|
13
25
|
GIL = pys_sys.gil = False
|
|
14
26
|
if is_environ(ENV_PYSCRIPT_WITH_GIL):
|
|
15
27
|
try:
|
pyscript/core/highlight.py
CHANGED
pyscript/core/interpreter.py
CHANGED
|
@@ -308,17 +308,19 @@ def visit_BinaryOperatorNode(node: PysBinaryOperatorNode, context: PysContext) -
|
|
|
308
308
|
result._context = context
|
|
309
309
|
result._position = node.position
|
|
310
310
|
with result:
|
|
311
|
-
return_right = True
|
|
312
311
|
|
|
313
312
|
if otype == T_OR:
|
|
314
313
|
if left:
|
|
315
314
|
return result.success(left)
|
|
315
|
+
return_right = True
|
|
316
316
|
elif otype == T_AND:
|
|
317
317
|
if not left:
|
|
318
318
|
return result.success(left)
|
|
319
|
+
return_right = True
|
|
319
320
|
elif otype == T_NULLISH:
|
|
320
321
|
if left is not None:
|
|
321
322
|
return result.success(left)
|
|
323
|
+
return_right = True
|
|
322
324
|
else:
|
|
323
325
|
return_right = False
|
|
324
326
|
|
|
@@ -595,13 +597,13 @@ def visit_MatchNode(node: PysMatchNode, context: PysContext) -> PysRunTimeResult
|
|
|
595
597
|
should_return = result.should_return
|
|
596
598
|
ntarget = node.target
|
|
597
599
|
|
|
598
|
-
compare = False
|
|
599
|
-
|
|
600
600
|
if ntarget:
|
|
601
601
|
target = register(get_visitor(ntarget.__class__)(ntarget, context))
|
|
602
602
|
if should_return():
|
|
603
603
|
return result
|
|
604
604
|
compare = True
|
|
605
|
+
else:
|
|
606
|
+
compare = False
|
|
605
607
|
|
|
606
608
|
for ncondition, nvalue in node.cases:
|
|
607
609
|
condition = register(get_visitor(ncondition.__class__)(ncondition, context))
|
|
@@ -611,7 +613,7 @@ def visit_MatchNode(node: PysMatchNode, context: PysContext) -> PysRunTimeResult
|
|
|
611
613
|
result._position = ncondition.position
|
|
612
614
|
with result:
|
|
613
615
|
|
|
614
|
-
if target == condition if compare else
|
|
616
|
+
if (target == condition) if compare else condition:
|
|
615
617
|
value = register(get_visitor(nvalue.__class__)(nvalue, context))
|
|
616
618
|
if should_return():
|
|
617
619
|
return result
|
|
@@ -654,7 +656,6 @@ def visit_TryNode(node: PysTryNode, context: PysContext) -> PysRunTimeResult:
|
|
|
654
656
|
failure(None)
|
|
655
657
|
|
|
656
658
|
for (targets, tparameter), body in node.catches:
|
|
657
|
-
handle_exception = True
|
|
658
659
|
stop = False
|
|
659
660
|
|
|
660
661
|
if targets:
|
|
@@ -683,6 +684,9 @@ def visit_TryNode(node: PysTryNode, context: PysContext) -> PysRunTimeResult:
|
|
|
683
684
|
handle_exception = True
|
|
684
685
|
break
|
|
685
686
|
|
|
687
|
+
else:
|
|
688
|
+
handle_exception = True
|
|
689
|
+
|
|
686
690
|
if stop:
|
|
687
691
|
break
|
|
688
692
|
|
pyscript/core/nodes.py
CHANGED
|
@@ -274,6 +274,7 @@ class PysTernaryOperatorNode(PysNode):
|
|
|
274
274
|
invalid: PysNode,
|
|
275
275
|
style: Literal['general', 'pythonic']
|
|
276
276
|
) -> 'PysTernaryOperatorNode | PysNode':
|
|
277
|
+
|
|
277
278
|
if (l_condition := _get_literal_value(condition)) is not undefined:
|
|
278
279
|
return valid if l_condition else invalid
|
|
279
280
|
|
|
@@ -398,17 +399,15 @@ class PysStatementsNode(PysNode):
|
|
|
398
399
|
return elements[0]
|
|
399
400
|
|
|
400
401
|
new = []
|
|
401
|
-
constant_nodes = {PysConstantNode, PysDebugNode, PysEllipsisNode}
|
|
402
|
-
interrupt_nodes = {PysReturnNode, PysThrowNode, PysContinueNode, PysBreakNode}
|
|
403
402
|
|
|
404
403
|
for node in elements:
|
|
405
|
-
if node.__class__ in
|
|
404
|
+
if node.__class__ in _constant_nodes:
|
|
406
405
|
continue
|
|
407
406
|
elif node.__class__ is PysStatementsNode:
|
|
408
407
|
new.extend(node.elements)
|
|
409
408
|
else:
|
|
410
409
|
new.append(node)
|
|
411
|
-
if node.__class__ in
|
|
410
|
+
if node.__class__ in _interrupt_nodes:
|
|
412
411
|
break
|
|
413
412
|
|
|
414
413
|
self = super().__new__(cls, position)
|
|
@@ -510,12 +509,16 @@ class PysSwitchNode(PysNode):
|
|
|
510
509
|
target: PysNode,
|
|
511
510
|
cases: list[tuple[PysNode, PysNode]],
|
|
512
511
|
default: PysNode | None
|
|
513
|
-
) -> 'PysSwitchNode':
|
|
512
|
+
) -> 'PysSwitchNode | PysNode':
|
|
513
|
+
default = _optional_part(default)
|
|
514
|
+
|
|
515
|
+
if not (cases or default):
|
|
516
|
+
return target
|
|
514
517
|
|
|
515
518
|
self = super().__new__(cls, position)
|
|
516
519
|
setimuattr(self, 'target', target)
|
|
517
520
|
setimuattr(self, 'cases', tuple(cases))
|
|
518
|
-
setimuattr(self, 'default',
|
|
521
|
+
setimuattr(self, 'default', default)
|
|
519
522
|
return self
|
|
520
523
|
|
|
521
524
|
def __repr__(self) -> str:
|
|
@@ -532,12 +535,31 @@ class PysMatchNode(PysNode):
|
|
|
532
535
|
target: PysNode | None,
|
|
533
536
|
cases: list[tuple[PysNode, PysNode]],
|
|
534
537
|
default: PysNode | None
|
|
535
|
-
) -> 'PysMatchNode':
|
|
538
|
+
) -> 'PysMatchNode | PysNode':
|
|
539
|
+
|
|
540
|
+
if target and (l_target := _get_literal_value(target)) is not undefined:
|
|
541
|
+
new_cases = []
|
|
542
|
+
|
|
543
|
+
for condition, value in cases:
|
|
544
|
+
if (l_condition := _get_literal_value(condition)) is undefined:
|
|
545
|
+
new_cases.append((condition, value))
|
|
546
|
+
elif l_target == l_condition:
|
|
547
|
+
default = value
|
|
548
|
+
break
|
|
549
|
+
|
|
550
|
+
cases = new_cases
|
|
551
|
+
default = _optional_part(default, expression=True)
|
|
552
|
+
|
|
553
|
+
if not cases:
|
|
554
|
+
return default if default else PysConstantNode(position, None)
|
|
555
|
+
|
|
556
|
+
else:
|
|
557
|
+
default = _optional_part(default, expression=True)
|
|
536
558
|
|
|
537
559
|
self = super().__new__(cls, position)
|
|
538
560
|
setimuattr(self, 'target', target)
|
|
539
561
|
setimuattr(self, 'cases', tuple(cases))
|
|
540
|
-
setimuattr(self, 'default',
|
|
562
|
+
setimuattr(self, 'default', default)
|
|
541
563
|
return self
|
|
542
564
|
|
|
543
565
|
def __repr__(self) -> str:
|
|
@@ -602,8 +624,7 @@ class PysForNode(PysNode):
|
|
|
602
624
|
def __new__(
|
|
603
625
|
cls,
|
|
604
626
|
position: PysPosition,
|
|
605
|
-
header: tuple[PysNode | None, PysNode | None, PysNode | None] |
|
|
606
|
-
tuple[PysNode, PysNode],
|
|
627
|
+
header: tuple[PysNode | None, PysNode | None, PysNode | None] | tuple[PysNode, PysNode],
|
|
607
628
|
body: PysNode,
|
|
608
629
|
else_: PysNode | None
|
|
609
630
|
) -> 'PysForNode':
|
|
@@ -628,12 +649,16 @@ class PysWhileNode(PysNode):
|
|
|
628
649
|
condition: PysNode,
|
|
629
650
|
body: PysNode,
|
|
630
651
|
else_: PysNode | None
|
|
631
|
-
) -> 'PysWhileNode':
|
|
652
|
+
) -> 'PysWhileNode | PysNode':
|
|
653
|
+
else_ = _optional_part(else_)
|
|
654
|
+
|
|
655
|
+
if (l_condition := _get_literal_value(condition)) is not undefined and not l_condition:
|
|
656
|
+
return else_ if else_ else PysStatementsNode(position, [])
|
|
632
657
|
|
|
633
658
|
self = super().__new__(cls, position)
|
|
634
659
|
setimuattr(self, 'condition', condition)
|
|
635
660
|
setimuattr(self, 'body', body)
|
|
636
|
-
setimuattr(self, 'else_',
|
|
661
|
+
setimuattr(self, 'else_', else_)
|
|
637
662
|
return self
|
|
638
663
|
|
|
639
664
|
def __repr__(self) -> str:
|
|
@@ -770,7 +795,7 @@ class PysReturnNode(PysNode):
|
|
|
770
795
|
@typecheck
|
|
771
796
|
def __new__(cls, position: PysPosition, value: PysNode | None) -> 'PysReturnNode':
|
|
772
797
|
self = super().__new__(cls, position)
|
|
773
|
-
setimuattr(self, 'value', _optional_part(value))
|
|
798
|
+
setimuattr(self, 'value', _optional_part(value, expression=True))
|
|
774
799
|
return self
|
|
775
800
|
|
|
776
801
|
def __repr__(self) -> str:
|
|
@@ -855,6 +880,9 @@ class PysBreakNode(PysNode):
|
|
|
855
880
|
def __repr__(self) -> Literal['Break()']:
|
|
856
881
|
return 'Break()'
|
|
857
882
|
|
|
883
|
+
_constant_nodes = frozenset([PysConstantNode, PysDebugNode, PysEllipsisNode])
|
|
884
|
+
_interrupt_nodes = frozenset([PysReturnNode, PysThrowNode, PysContinueNode, PysBreakNode])
|
|
885
|
+
|
|
858
886
|
def _get_literal_value(item: Any) -> Any | PysUndefined:
|
|
859
887
|
|
|
860
888
|
if isinstance(item, (PysConstantNode, PysToken)):
|
|
@@ -886,9 +914,9 @@ def _get_literal_value(item: Any) -> Any | PysUndefined:
|
|
|
886
914
|
|
|
887
915
|
return undefined
|
|
888
916
|
|
|
889
|
-
def _optional_part(part: PysNode | None) -> PysNode | None:
|
|
917
|
+
def _optional_part(part: PysNode | None, *, expression: bool = False) -> PysNode | None:
|
|
890
918
|
return None if (
|
|
919
|
+
(not expression and part.__class__ in _constant_nodes) or
|
|
891
920
|
_get_literal_value(part) is None or
|
|
892
|
-
(part.__class__ is PysStatementsNode and not part.elements)
|
|
893
|
-
(part.__class__ in (PysDebugNode, PysEllipsisNode))
|
|
921
|
+
(part.__class__ is PysStatementsNode and not part.elements)
|
|
894
922
|
) else part
|
pyscript/core/parser.py
CHANGED
|
@@ -1197,66 +1197,71 @@ class PysParser(Pys):
|
|
|
1197
1197
|
|
|
1198
1198
|
self.skip(result)
|
|
1199
1199
|
|
|
1200
|
-
|
|
1201
|
-
|
|
1200
|
+
cases = []
|
|
1201
|
+
default = None
|
|
1202
1202
|
|
|
1203
|
-
|
|
1203
|
+
if self.current_token.type == TOKENS['SEMICOLON']:
|
|
1204
|
+
result.register_advancement()
|
|
1205
|
+
self.advance()
|
|
1204
1206
|
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
self.skip(result)
|
|
1207
|
+
elif self.current_token.type == TOKENS['LEFT_CURLY']:
|
|
1208
|
+
left_bracket_token = self.current_token
|
|
1208
1209
|
|
|
1209
|
-
|
|
1210
|
-
|
|
1210
|
+
result.register_advancement()
|
|
1211
|
+
self.advance()
|
|
1212
|
+
self.skip(result)
|
|
1211
1213
|
|
|
1212
|
-
|
|
1214
|
+
while True:
|
|
1213
1215
|
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1216
|
+
if self.current_token.match(TOKENS['KEYWORD'], 'case'):
|
|
1217
|
+
result.register_advancement()
|
|
1218
|
+
self.advance()
|
|
1219
|
+
self.skip(result)
|
|
1218
1220
|
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1221
|
+
case = result.register(self.walrus(), True)
|
|
1222
|
+
if result.error:
|
|
1223
|
+
return result
|
|
1222
1224
|
|
|
1223
|
-
|
|
1225
|
+
self.skip(result)
|
|
1224
1226
|
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
+
if self.current_token.type != TOKENS['COLON']:
|
|
1228
|
+
return result.failure(self.new_error("expected ':'"))
|
|
1227
1229
|
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
+
result.register_advancement()
|
|
1231
|
+
self.advance()
|
|
1230
1232
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1233
|
+
body = result.register(self.statements())
|
|
1234
|
+
if result.error:
|
|
1235
|
+
return result
|
|
1234
1236
|
|
|
1235
|
-
|
|
1237
|
+
cases.append((case, body))
|
|
1236
1238
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1239
|
+
elif self.current_token.match(TOKENS['KEYWORD'], 'default', 'else'):
|
|
1240
|
+
result.register_advancement()
|
|
1241
|
+
self.advance()
|
|
1242
|
+
self.skip(result)
|
|
1241
1243
|
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
+
if self.current_token.type != TOKENS['COLON']:
|
|
1245
|
+
return result.failure(self.new_error("expected ':'"))
|
|
1244
1246
|
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
+
result.register_advancement()
|
|
1248
|
+
self.advance()
|
|
1247
1249
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1250
|
+
default = result.register(self.statements())
|
|
1251
|
+
if result.error:
|
|
1252
|
+
return result
|
|
1251
1253
|
|
|
1252
|
-
|
|
1254
|
+
break
|
|
1253
1255
|
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
+
else:
|
|
1257
|
+
break
|
|
1256
1258
|
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1259
|
+
self.close_bracket(result, left_bracket_token)
|
|
1260
|
+
if result.error:
|
|
1261
|
+
return result
|
|
1262
|
+
|
|
1263
|
+
else:
|
|
1264
|
+
return result.failure(self.new_error("expected '{'"))
|
|
1260
1265
|
|
|
1261
1266
|
return result.success(
|
|
1262
1267
|
PysSwitchNode(
|
pyscript/core/pysbuiltins.py
CHANGED
|
@@ -461,7 +461,8 @@ def ce(context, position, a, b, *, rel_tol=1e-9, abs_tol=0):
|
|
|
461
461
|
abs_tol: maximum difference for being considered "close", regardless of the magnitude of the input values.
|
|
462
462
|
"""
|
|
463
463
|
|
|
464
|
-
|
|
464
|
+
b_isinstance = isinstance
|
|
465
|
+
if b_isinstance(a, real_complex_number) and b_isinstance(b, real_complex_number):
|
|
465
466
|
return isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol)
|
|
466
467
|
|
|
467
468
|
result = _magic_method(context, position, a, '__ce__', b, rel_tol=rel_tol, abs_tol=abs_tol)
|
|
@@ -495,7 +496,8 @@ def nce(context, position, a, b, *, rel_tol=1e-9, abs_tol=0):
|
|
|
495
496
|
abs_tol: maximum difference for being considered "close", regardless of the magnitude of the input values.
|
|
496
497
|
"""
|
|
497
498
|
|
|
498
|
-
|
|
499
|
+
b_isinstance = isinstance
|
|
500
|
+
if b_isinstance(a, real_complex_number) and b_isinstance(b, real_complex_number):
|
|
499
501
|
return not isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol)
|
|
500
502
|
|
|
501
503
|
result = _magic_method(context, position, a, '__nce__', b, rel_tol=rel_tol, abs_tol=abs_tol)
|
|
@@ -526,9 +528,10 @@ def increment(context, position, object):
|
|
|
526
528
|
__increment__ method, which if unsuccessful will throw a TypeError.
|
|
527
529
|
"""
|
|
528
530
|
|
|
529
|
-
|
|
531
|
+
b_isinstance = isinstance
|
|
532
|
+
if b_isinstance(object, real_number):
|
|
530
533
|
return object + 1
|
|
531
|
-
elif
|
|
534
|
+
elif b_isinstance(object, sequence):
|
|
532
535
|
return tuple(_pyincrement(context, position, obj) for obj in object)
|
|
533
536
|
|
|
534
537
|
result = _magic_method(context, position, object, '__increment__')
|
|
@@ -550,9 +553,10 @@ def decrement(context, position, object):
|
|
|
550
553
|
call the __decrement__ method, which if unsuccessful will throw a TypeError.
|
|
551
554
|
"""
|
|
552
555
|
|
|
553
|
-
|
|
556
|
+
b_isinstance = isinstance
|
|
557
|
+
if b_isinstance(object, real_number):
|
|
554
558
|
return object - 1
|
|
555
|
-
elif
|
|
559
|
+
elif b_isinstance(object, sequence):
|
|
556
560
|
return tuple(_pydecrement(context, position, obj) for obj in object)
|
|
557
561
|
|
|
558
562
|
result = _magic_method(context, position, object, '__decrement__')
|
pyscript/core/pystypes.py
CHANGED
|
@@ -11,7 +11,6 @@ from .utils.generic import setimuattr, dinit, drepr, dor, dror, dior, dsetitem,
|
|
|
11
11
|
from .utils.similarity import diff_get_closest
|
|
12
12
|
from .utils.string import join
|
|
13
13
|
|
|
14
|
-
from builtins import help as pyhelp
|
|
15
14
|
from itertools import islice
|
|
16
15
|
from types import MethodType
|
|
17
16
|
from typing import Any, Callable, Optional
|
|
@@ -311,10 +310,16 @@ class PysPrinter(PysObject):
|
|
|
311
310
|
|
|
312
311
|
class PysHelper(PysPrinter):
|
|
313
312
|
|
|
314
|
-
__slots__ = ()
|
|
313
|
+
__slots__ = ('_pyhelp',)
|
|
315
314
|
|
|
316
315
|
def __init__(self) -> None:
|
|
317
316
|
super().__init__('help')
|
|
317
|
+
try:
|
|
318
|
+
from builtins import help
|
|
319
|
+
except:
|
|
320
|
+
def help(*args, **kwargs):
|
|
321
|
+
raise NotImplementedError('python builtins.help not found')
|
|
322
|
+
setimuattr(self, '_pyhelp', help)
|
|
318
323
|
|
|
319
324
|
def __repr__(self) -> str:
|
|
320
325
|
return f'Type {self.name}() for interactive help, or {self.name}(object) for help about object.'
|
|
@@ -328,4 +333,4 @@ class PysHelper(PysPrinter):
|
|
|
328
333
|
"To get the list of builtin functions, types, exceptions, and other objects, type 'help(\"builtins\")'."
|
|
329
334
|
)
|
|
330
335
|
else:
|
|
331
|
-
|
|
336
|
+
self._pyhelp(*args, **kwargs)
|
pyscript/core/shell.py
CHANGED
|
@@ -233,10 +233,8 @@ try:
|
|
|
233
233
|
@singleton
|
|
234
234
|
class PysHistory(Pys, History):
|
|
235
235
|
|
|
236
|
-
def __new_singleton__(cls) -> 'PysHistory':
|
|
237
|
-
if USE_FILE_HISTORY
|
|
238
|
-
return super().__new__(cls)
|
|
239
|
-
raise NotImplementedError('not using file history')
|
|
236
|
+
def __new_singleton__(cls) -> 'PysHistory | InMemoryHistory':
|
|
237
|
+
return super().__new__(cls) if USE_FILE_HISTORY else InMemoryHistory()
|
|
240
238
|
|
|
241
239
|
def _write_history_safely(self, mode: str, function: str, *args) -> None:
|
|
242
240
|
try:
|
|
@@ -254,16 +252,16 @@ try:
|
|
|
254
252
|
self._write_history_safely('w', 'write', '')
|
|
255
253
|
return []
|
|
256
254
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
lines = []
|
|
255
|
+
strings = []
|
|
256
|
+
lines = []
|
|
260
257
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
258
|
+
def add_to_string():
|
|
259
|
+
if not lines:
|
|
260
|
+
return
|
|
261
|
+
strings.insert(0, '\n'.join(lines))
|
|
262
|
+
lines.clear()
|
|
266
263
|
|
|
264
|
+
try:
|
|
267
265
|
with open(HISTORY_PATH, 'r', encoding=pys_sys.encoding) as file:
|
|
268
266
|
for line in file:
|
|
269
267
|
line = line[:-1]
|
|
@@ -273,13 +271,15 @@ try:
|
|
|
273
271
|
lines.append(line)
|
|
274
272
|
add_to_string()
|
|
275
273
|
|
|
276
|
-
if
|
|
274
|
+
if 0 < HISTORY_LIMIT < len(strings):
|
|
277
275
|
self._manage_history_capacity(strings)
|
|
278
276
|
|
|
279
|
-
return strings
|
|
280
277
|
except:
|
|
281
278
|
return []
|
|
282
279
|
|
|
280
|
+
else:
|
|
281
|
+
return strings
|
|
282
|
+
|
|
283
283
|
# this function is called within `append_string()` which adds a new string or history entry to `_loaded_strings`
|
|
284
284
|
# before invoking this function
|
|
285
285
|
def store_string(self, string: str) -> None:
|
|
@@ -290,8 +290,6 @@ try:
|
|
|
290
290
|
else:
|
|
291
291
|
self._manage_history_capacity(self._loaded_strings)
|
|
292
292
|
|
|
293
|
-
history = (PysHistory if USE_FILE_HISTORY else InMemoryHistory)()
|
|
294
|
-
|
|
295
293
|
class PysPromptToolkitLineShell(PysLineShell, PromptSession):
|
|
296
294
|
|
|
297
295
|
def __init__(self, ps1: str = '>>> ', ps2: str = '... ', colored: bool = True) -> None:
|
|
@@ -381,7 +379,7 @@ try:
|
|
|
381
379
|
input_processors=[TabsProcessor(tabstop=4)],
|
|
382
380
|
key_bindings=key_bindings,
|
|
383
381
|
prompt_continuation=lambda width, line_number, is_soft_wrap: self._ps2,
|
|
384
|
-
history=
|
|
382
|
+
history=PysHistory(),
|
|
385
383
|
**other_keyword
|
|
386
384
|
)
|
|
387
385
|
|
|
@@ -13,9 +13,10 @@ class _PysUtilities(Pys):
|
|
|
13
13
|
# circular import problem solved
|
|
14
14
|
from ..cache import pys_sys
|
|
15
15
|
singletons = pys_sys.singletons
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
object = singletons.get(cls, None)
|
|
17
|
+
if type(object) is not cls:
|
|
18
|
+
singletons[cls] = object = cls.__new_singleton__(cls, *args, **kwargs)
|
|
19
|
+
return object
|
|
19
20
|
|
|
20
21
|
@staticmethod
|
|
21
22
|
def readonly_attribute(*args, **kwargs):
|
pyscript/core/utils/string.py
CHANGED
|
@@ -43,8 +43,10 @@ def join(sequence: Sequence[str], conjunction: str = 'and') -> str:
|
|
|
43
43
|
elif length == 1:
|
|
44
44
|
return sequence[0]
|
|
45
45
|
elif length == 2:
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
a, b = sequence
|
|
47
|
+
return f'{a} {conjunction} {b}'
|
|
48
|
+
*others, end = sequence
|
|
49
|
+
return f'{", ".join(others)}, {conjunction} {end}'
|
|
48
50
|
|
|
49
51
|
def indent(string: str, length: int, indent: str = ' ') -> str:
|
|
50
52
|
prefix = indent * length
|
pyscript/core/version.py
CHANGED
|
@@ -7,8 +7,8 @@ from re import match as match_regex
|
|
|
7
7
|
from types import NotImplementedType
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
|
-
__version__ = '1.15.
|
|
11
|
-
__date__ = '
|
|
10
|
+
__version__ = '1.15.2'
|
|
11
|
+
__date__ = '08 November 2026, 12:30 UTC+7'
|
|
12
12
|
__author__ = ('AzzamMuhyala',)
|
|
13
13
|
|
|
14
14
|
version = pys_sys.version = f'{__version__} ({__date__})'
|
pyscript/lib/dual/py_dual.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
1
|
+
# formula from: https://github.com/BaguetteBunny/dual-lib
|
|
2
|
+
# by: BaguetteBunny
|
|
3
3
|
|
|
4
4
|
from pyscript.core.pysbuiltins import ce, nce
|
|
5
5
|
from pyscript.core.utils.decorators import immutable
|
|
@@ -37,15 +37,15 @@ class dual:
|
|
|
37
37
|
case 0:
|
|
38
38
|
real = epsilon = 0
|
|
39
39
|
case 1:
|
|
40
|
-
real = args
|
|
40
|
+
real, = args
|
|
41
41
|
if isinstance(real, dual):
|
|
42
42
|
return real
|
|
43
43
|
epsilon = 0
|
|
44
44
|
case _:
|
|
45
45
|
real, epsilon = args
|
|
46
|
-
|
|
46
|
+
real, b = _parts(real)
|
|
47
47
|
c, _ = _parts(epsilon)
|
|
48
|
-
|
|
48
|
+
epsilon = b + c
|
|
49
49
|
|
|
50
50
|
self = super().__new__(cls)
|
|
51
51
|
setimuattr(self, 'real', real)
|
|
@@ -62,10 +62,7 @@ class dual:
|
|
|
62
62
|
)
|
|
63
63
|
|
|
64
64
|
def __radd__(self, other: 'dual | Any') -> 'dual':
|
|
65
|
-
return dual(
|
|
66
|
-
other.real + self.real,
|
|
67
|
-
other.epsilon + self.epsilon
|
|
68
|
-
) if isinstance(other, dual) else dual(
|
|
65
|
+
return other + self if isinstance(other, dual) else dual(
|
|
69
66
|
other + self.real,
|
|
70
67
|
self.epsilon
|
|
71
68
|
)
|
|
@@ -80,10 +77,7 @@ class dual:
|
|
|
80
77
|
)
|
|
81
78
|
|
|
82
79
|
def __rsub__(self, other: 'dual | Any') -> 'dual':
|
|
83
|
-
return dual(
|
|
84
|
-
other.real - self.real,
|
|
85
|
-
other.epsilon - self.epsilon
|
|
86
|
-
) if isinstance(other, dual) else dual(
|
|
80
|
+
return other - self if isinstance(other, dual) else dual(
|
|
87
81
|
other - self.real,
|
|
88
82
|
self.epsilon
|
|
89
83
|
)
|
|
@@ -98,10 +92,7 @@ class dual:
|
|
|
98
92
|
)
|
|
99
93
|
|
|
100
94
|
def __rmul__(self, other: 'dual | Any') -> 'dual':
|
|
101
|
-
return dual(
|
|
102
|
-
other.real * self.real,
|
|
103
|
-
other.real * self.epsilon + other.epsilon * self.real
|
|
104
|
-
) if isinstance(other, dual) else dual(
|
|
95
|
+
return other * self if isinstance(other, dual) else dual(
|
|
105
96
|
other * self.real,
|
|
106
97
|
other * self.epsilon
|
|
107
98
|
)
|
|
@@ -228,6 +219,9 @@ class dual:
|
|
|
228
219
|
def __float__(self) -> float:
|
|
229
220
|
return float(self.real)
|
|
230
221
|
|
|
222
|
+
def __complex__(self) -> complex:
|
|
223
|
+
return complex(self.real)
|
|
224
|
+
|
|
231
225
|
def __floor__(self) -> 'dual':
|
|
232
226
|
return dual(math.floor(self.real), 0)
|
|
233
227
|
|
pyscript/lib/explorer.pys
CHANGED
|
@@ -8,9 +8,8 @@ class ExplorerResult {
|
|
|
8
8
|
|
|
9
9
|
__slots__ = ('success', 'exception')
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
constructor()
|
|
12
12
|
self._success()
|
|
13
|
-
}
|
|
14
13
|
|
|
15
14
|
func _success(self) {
|
|
16
15
|
self.success = True
|
|
@@ -29,12 +28,8 @@ class ExplorerResult {
|
|
|
29
28
|
self.exception = result.exception
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
func __repr__(self) {
|
|
33
|
-
return 'ExplorerResult(success={!r}, exception={!r})'.format(self.success, self.exception)
|
|
34
|
-
}
|
|
35
|
-
|
|
31
|
+
func __repr__(self) => 'ExplorerResult(success={!r}, exception={!r})'.format(self.success, self.exception)
|
|
36
32
|
func __enter__(self);
|
|
37
|
-
|
|
38
33
|
func __exit__(self, exc_type, exc_value, exc_tb) {
|
|
39
34
|
exc_type is None ? self._success() : self._failure(exc_value is None ? exc_type : exc_value)
|
|
40
35
|
return True
|
|
@@ -42,36 +37,32 @@ class ExplorerResult {
|
|
|
42
37
|
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
func newfile(path,
|
|
40
|
+
func newfile(path, exist_ok=True, make_dirs=True) {
|
|
46
41
|
result = ExplorerResult()
|
|
47
42
|
path = normpath(path, absolute=False)
|
|
48
43
|
|
|
49
44
|
if (os.path.exists(path)) {
|
|
50
|
-
if (!
|
|
45
|
+
if (!exist_ok)
|
|
51
46
|
return result._failure(FileExistsError("{!r} already exists".format(path)))
|
|
52
|
-
}
|
|
53
47
|
}
|
|
54
48
|
else {
|
|
49
|
+
if (make_dirs and (dirpath := os.path.dirname(path))) {
|
|
50
|
+
result._register(newfolder(dirpath))
|
|
51
|
+
if (!result.success)
|
|
52
|
+
return result
|
|
53
|
+
}
|
|
55
54
|
with (result, open(path, 'a'));
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
return result
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
func newfolder(path,
|
|
60
|
+
func newfolder(path, exist_ok=True) {
|
|
62
61
|
result = ExplorerResult()
|
|
63
62
|
path = normpath(path, absolute=False)
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return result._failure(FileExistsError("{!r} already exists".format(path)))
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
with (result) {
|
|
72
|
-
os.mkdir(path)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
64
|
+
with (result)
|
|
65
|
+
os.makedirs(path, exist_ok=exist_ok)
|
|
75
66
|
|
|
76
67
|
return result
|
|
77
68
|
}
|
|
@@ -79,80 +70,77 @@ func newfolder(path, exists_ok=True) {
|
|
|
79
70
|
func rename(path, name) {
|
|
80
71
|
result = ExplorerResult()
|
|
81
72
|
path = normpath(path, absolute=False)
|
|
82
|
-
newname = os.path.join(os.path.dirname(path), name)
|
|
83
73
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
if (!os.path.exists(path))
|
|
75
|
+
return result._failure(FileNotFoundError("{!r} not found".format(path)))
|
|
76
|
+
|
|
77
|
+
with (result)
|
|
78
|
+
os.rename(path, os.path.join(os.path.dirname(path), name))
|
|
87
79
|
|
|
88
80
|
return result
|
|
89
81
|
}
|
|
90
82
|
|
|
91
|
-
func move(path, dist, replace=False) {
|
|
83
|
+
func move(path, dist, replace=False, make_dirs=True) {
|
|
92
84
|
result = ExplorerResult()
|
|
93
85
|
path = normpath(path, absolute=False)
|
|
94
86
|
dist = normpath(dist, absolute=False)
|
|
95
87
|
|
|
96
|
-
if (!os.path.exists(path))
|
|
88
|
+
if (!os.path.exists(path))
|
|
97
89
|
return result._failure(FileNotFoundError("{!r} not found".format(path)))
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
basename = os.path.basename(path)
|
|
101
|
-
distpath = os.path.join(dist, basename)
|
|
102
90
|
|
|
103
|
-
if (os.path.exists(distpath)) {
|
|
91
|
+
if (os.path.exists(distpath := os.path.join(dist, os.path.basename(path)))) {
|
|
104
92
|
if (replace) {
|
|
105
93
|
result._register(remove(distpath))
|
|
106
|
-
if (!result.success)
|
|
94
|
+
if (!result.success)
|
|
107
95
|
return result
|
|
108
|
-
}
|
|
109
96
|
}
|
|
110
|
-
else
|
|
97
|
+
else
|
|
111
98
|
return result._failure(FileExistsError("{!r} already exists".format(distpath)))
|
|
112
|
-
}
|
|
113
99
|
}
|
|
114
100
|
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
if (make_dirs and (dirpath := os.path.dirname(distpath))) {
|
|
102
|
+
result._register(newfolder(dirpath))
|
|
103
|
+
if (!result.success)
|
|
104
|
+
return result
|
|
117
105
|
}
|
|
118
106
|
|
|
107
|
+
with (result)
|
|
108
|
+
shutil.move(path, distpath)
|
|
109
|
+
|
|
119
110
|
return result
|
|
120
111
|
}
|
|
121
112
|
|
|
122
|
-
func copy(path, dist, replace=False, metadata=True) {
|
|
113
|
+
func copy(path, dist, replace=False, metadata=True, make_dirs=True) {
|
|
123
114
|
result = ExplorerResult()
|
|
124
115
|
path = normpath(path, absolute=False)
|
|
125
116
|
dist = normpath(dist, absolute=False)
|
|
126
117
|
|
|
127
|
-
if (!os.path.exists(path))
|
|
118
|
+
if (!os.path.exists(path))
|
|
128
119
|
return result._failure(FileNotFoundError("{!r} not found".format(path)))
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
basename = os.path.basename(path)
|
|
132
|
-
distpath = os.path.join(dist, basename)
|
|
133
120
|
|
|
134
|
-
if (os.path.exists(distpath)) {
|
|
121
|
+
if (os.path.exists(distpath := os.path.join(dist, os.path.basename(path)))) {
|
|
135
122
|
if (replace) {
|
|
136
123
|
result._register(remove(distpath))
|
|
137
|
-
if (!result.success)
|
|
124
|
+
if (!result.success)
|
|
138
125
|
return result
|
|
139
|
-
}
|
|
140
126
|
}
|
|
141
|
-
else
|
|
127
|
+
else
|
|
142
128
|
return result._failure(FileExistsError("{!r} already exists".format(distpath)))
|
|
143
|
-
}
|
|
144
129
|
}
|
|
145
130
|
|
|
146
131
|
copyfunc = metadata ? shutil.copy2 : shutil.copy
|
|
147
132
|
|
|
148
|
-
|
|
149
|
-
|
|
133
|
+
if (make_dirs and (dirpath := os.path.dirname(distpath))) {
|
|
134
|
+
result._register(newfolder(dirpath))
|
|
135
|
+
if (!result.success)
|
|
136
|
+
return result
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
with (result)
|
|
140
|
+
if (os.path.isfile(path))
|
|
150
141
|
copyfunc(path, distpath)
|
|
151
|
-
|
|
152
|
-
elif (os.path.isdir(path)) {
|
|
142
|
+
elif (os.path.isdir(path))
|
|
153
143
|
shutil.copytree(path, distpath, copy_function=copyfunc)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
144
|
|
|
157
145
|
return result
|
|
158
146
|
}
|
|
@@ -161,25 +149,19 @@ func clear(path) {
|
|
|
161
149
|
result = ExplorerResult()
|
|
162
150
|
path = normpath(path, absolute=False)
|
|
163
151
|
|
|
164
|
-
if (!os.path.exists(path))
|
|
152
|
+
if (!os.path.exists(path))
|
|
165
153
|
return result._failure(FileNotFoundError("{!r} not found".format(path)))
|
|
166
|
-
}
|
|
167
154
|
|
|
168
|
-
with (result)
|
|
169
|
-
if (os.path.isfile(path))
|
|
170
|
-
with (open(path, 'w') as file)
|
|
155
|
+
with (result)
|
|
156
|
+
if (os.path.isfile(path))
|
|
157
|
+
with (open(path, 'w') as file)
|
|
171
158
|
file.write('')
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
elif (os.path.isdir(path)) {
|
|
159
|
+
elif (os.path.isdir(path))
|
|
175
160
|
for (child of os.listdir(path)) {
|
|
176
161
|
result._register(remove(os.path.join(path, child)))
|
|
177
|
-
if (!result.success)
|
|
162
|
+
if (!result.success)
|
|
178
163
|
break
|
|
179
|
-
}
|
|
180
164
|
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
165
|
|
|
184
166
|
return result
|
|
185
167
|
}
|
|
@@ -188,21 +170,17 @@ func remove(path) {
|
|
|
188
170
|
result = ExplorerResult()
|
|
189
171
|
path = normpath(path, absolute=False)
|
|
190
172
|
|
|
191
|
-
if (!os.path.exists(path))
|
|
173
|
+
if (!os.path.exists(path))
|
|
192
174
|
return result._failure(FileNotFoundError("{!r} not found".format(path)))
|
|
193
|
-
}
|
|
194
175
|
|
|
195
|
-
with (result)
|
|
196
|
-
if (os.path.isfile(path))
|
|
176
|
+
with (result)
|
|
177
|
+
if (os.path.isfile(path))
|
|
197
178
|
os.remove(path)
|
|
198
|
-
|
|
199
|
-
elif (os.path.isdir(path)) {
|
|
179
|
+
elif (os.path.isdir(path))
|
|
200
180
|
shutil.rmtree(path, onerror=func(fn, path, excinfo) {
|
|
201
181
|
os.chmod(path, stat.S_IWRITE)
|
|
202
182
|
fn(path)
|
|
203
183
|
})
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
184
|
|
|
207
185
|
return result
|
|
208
186
|
}
|
pyscript/lib/getch/__init__.pys
CHANGED
pyscript/lib/getch/py_getch.py
CHANGED
|
@@ -37,7 +37,7 @@ if sys.platform == 'win32':
|
|
|
37
37
|
def getch() -> bytes:
|
|
38
38
|
global INTERRUPT
|
|
39
39
|
if not INITIALIZED:
|
|
40
|
-
raise
|
|
40
|
+
raise RuntimeError('not initialized')
|
|
41
41
|
elif INTERRUPT:
|
|
42
42
|
INTERRUPT = False
|
|
43
43
|
return b'\x03'
|
|
@@ -78,9 +78,12 @@ else:
|
|
|
78
78
|
|
|
79
79
|
def getch() -> bytes:
|
|
80
80
|
if not INITIALIZED:
|
|
81
|
-
raise
|
|
81
|
+
raise RuntimeError('not initialized')
|
|
82
82
|
return os.read(FILE_DESCRIPTOR, 1)
|
|
83
83
|
|
|
84
|
+
def is_initialized() -> bool:
|
|
85
|
+
return INITIALIZED
|
|
86
|
+
|
|
84
87
|
def getwch() -> str:
|
|
85
88
|
codes = getch()
|
|
86
89
|
first = codes[0]
|
pyscript/lib/history.pys
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
from _pyscript import shell
|
|
2
2
|
|
|
3
3
|
if (shell.ADVANCE_LINE_SHELL_SUPPORT) {
|
|
4
|
+
history = shell.PysHistory()
|
|
5
|
+
|
|
4
6
|
HISTORY_PATH = shell.HISTORY_PATH
|
|
5
7
|
HISTORY_LIMIT = shell.HISTORY_LIMIT
|
|
6
8
|
|
|
7
|
-
func load()
|
|
8
|
-
|
|
9
|
+
func load() {
|
|
10
|
+
if (!history._loaded) {
|
|
11
|
+
history._loaded_strings = history.load_history_strings()
|
|
12
|
+
history._loaded = True
|
|
13
|
+
}
|
|
14
|
+
return history.get_strings()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
func append(string)
|
|
18
|
+
history.append_string(string)
|
|
9
19
|
|
|
10
20
|
if (shell.USE_FILE_HISTORY) {
|
|
11
21
|
import explorer
|
|
12
22
|
func clear() {
|
|
13
|
-
|
|
23
|
+
history._loaded_strings.clear()
|
|
14
24
|
explorer.clear(HISTORY_PATH)
|
|
15
25
|
}
|
|
16
26
|
} else {
|
|
17
27
|
func clear() {
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
history._loaded_strings.clear()
|
|
29
|
+
history._storage.clear()
|
|
20
30
|
}
|
|
21
31
|
}
|
|
22
32
|
|
pyscript/lib/site.pys
CHANGED
|
@@ -5,6 +5,8 @@ import explorer
|
|
|
5
5
|
from '_pyscript>utils>module' import get_module_candidate
|
|
6
6
|
from '_pyscript>utils>path' import normpath
|
|
7
7
|
|
|
8
|
+
ENABLE_USER_SITE = pyimport('site').ENABLE_USER_SITE
|
|
9
|
+
|
|
8
10
|
func removeduppaths() {
|
|
9
11
|
path = []
|
|
10
12
|
known_paths = set()
|
|
@@ -21,21 +23,19 @@ func removeduppaths() {
|
|
|
21
23
|
return known_paths
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
func
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
}
|
|
26
|
+
func getusersitepackages() => sys.site_packages_path
|
|
27
|
+
|
|
28
|
+
func getsitepackages() => list(comprehension(
|
|
29
|
+
os.listdir(sys.site_packages_path),
|
|
30
|
+
func(package) => os.path.splitext(package)[0],
|
|
31
|
+
func(package) => get_module_candidate(normpath(sys.site_packages_path, package)) is not None
|
|
32
|
+
))
|
|
33
33
|
|
|
34
34
|
func addpackage(path) {
|
|
35
35
|
valid = get_module_candidate(normpath(path))
|
|
36
36
|
if (valid is None)
|
|
37
37
|
throw ModuleNotFoundError("invalid module")
|
|
38
|
-
result = explorer.copy(path, sys.site_packages_path,
|
|
38
|
+
result = explorer.copy(path, sys.site_packages_path, metadata=False)
|
|
39
39
|
if (!result.success)
|
|
40
40
|
throw result.exception
|
|
41
41
|
}
|
|
@@ -54,6 +54,7 @@ func removepackage(name) {
|
|
|
54
54
|
|
|
55
55
|
__all__ = (
|
|
56
56
|
'removeduppaths',
|
|
57
|
+
'getusersitepackages',
|
|
57
58
|
'getsitepackages',
|
|
58
59
|
'addpackage',
|
|
59
60
|
'removepackage'
|
|
@@ -106,26 +107,25 @@ if (__name__ == '__main__') {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
if (
|
|
110
|
+
if (!ENABLE_USER_SITE)
|
|
111
|
+
error('User site is disabled')
|
|
112
|
+
|
|
113
|
+
elif (args.l)
|
|
110
114
|
print('\n'.join(sorted(getsitepackages())))
|
|
111
115
|
|
|
112
|
-
elif (args.a)
|
|
116
|
+
elif (args.a)
|
|
113
117
|
try {
|
|
114
118
|
addpackage(args.a)
|
|
115
119
|
info('Package added successfully')
|
|
116
|
-
}
|
|
117
|
-
catch (e)
|
|
120
|
+
} catch (e)
|
|
118
121
|
error('-a: {}: {}'.format(typeof e, e))
|
|
119
|
-
}
|
|
120
122
|
|
|
121
|
-
elif (args.r)
|
|
123
|
+
elif (args.r)
|
|
122
124
|
try {
|
|
123
125
|
removepackage(args.r)
|
|
124
126
|
info('Package removed successfully')
|
|
125
|
-
}
|
|
126
|
-
catch (e)
|
|
127
|
+
} catch (e)
|
|
127
128
|
error('-r: {}: {}'.format(typeof e, e))
|
|
128
|
-
}
|
|
129
129
|
|
|
130
130
|
else
|
|
131
131
|
parser.print_help(sys.stdout)
|
pyscript/other/message.txt
CHANGED
|
@@ -59,4 +59,14 @@ eric why don't you come up here?
|
|
|
59
59
|
hey that's bullcrap! how come jimmy doesn't have to do it?
|
|
60
60
|
well, because jimmy's pitching a tent right now
|
|
61
61
|
[shock]
|
|
62
|
-
he's what?
|
|
62
|
+
he's what?
|
|
63
|
+
|
|
64
|
+
oh my god! they killed kenny!
|
|
65
|
+
you bastards!
|
|
66
|
+
|
|
67
|
+
[eng sub by @mccormickery on tiktok]
|
|
68
|
+
my friends are all so mean auntiee (temanku semua pada jahat tantee)
|
|
69
|
+
when i'm down they're never there (aku lagi susah mereka gak ada)
|
|
70
|
+
[kenny died]
|
|
71
|
+
but when i'm living the high life.. (coba kalau lagi jaya..)
|
|
72
|
+
they'll be all over me auntiee (aku dipuja-pujanya tantee)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyscript-programming-language
|
|
3
|
-
Version: 1.15.
|
|
3
|
+
Version: 1.15.2
|
|
4
4
|
Summary: PyScript Programming Language
|
|
5
5
|
Home-page: https://azzammuhyala.github.io/pyscript
|
|
6
6
|
Author: AzzamMuhyala
|
|
@@ -69,8 +69,8 @@ Try [PyScript Shell (_REPL_)](https://azzammuhyala.github.io/pyscript/shell.html
|
|
|
69
69
|
(no installation required).
|
|
70
70
|
|
|
71
71
|
## Installation ⬇️
|
|
72
|
-
First, you'll need to download Python. Make sure you're using the latest version above `3.10
|
|
73
|
-
correctly. Visit the official [Python website](https://python.org) to download it.
|
|
72
|
+
First, you'll need to download Python. Make sure you're using the latest version **above `3.10`**, to ensure the code
|
|
73
|
+
runs correctly. Visit the official [Python website](https://python.org) to download it.
|
|
74
74
|
|
|
75
75
|
Next, after downloading and configuring the Python application, you can download the PyScript from
|
|
76
76
|
[PyScript releases](https://github.com/azzammuhyala/pyscript/releases) or from PIP with this command (_Recommended_):
|
|
@@ -119,11 +119,12 @@ Familiar? There it is!
|
|
|
119
119
|
| 14 | `os` | **required** |
|
|
120
120
|
| 15 | `pkgutil` | **required** |
|
|
121
121
|
| 16 | `re` | **required** |
|
|
122
|
-
| 17 | `
|
|
123
|
-
| 18 | `
|
|
124
|
-
| 19 | `
|
|
125
|
-
| 20 | `
|
|
126
|
-
| 21 | `
|
|
122
|
+
| 17 | `site` | **required** |
|
|
123
|
+
| 18 | `subprocess` | **required** |
|
|
124
|
+
| 19 | `sys` | **required** |
|
|
125
|
+
| 20 | `types` | **required** |
|
|
126
|
+
| 21 | `typing` | **required** |
|
|
127
|
+
| 22 | `unicodedata` | **required** |
|
|
127
128
|
| 1 | `ast` | **required (library)** |
|
|
128
129
|
| 2 | `math` | **required (library)** |
|
|
129
130
|
| 3 | `msvcrt` | **required (library)** |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
pyscript/__init__.py,sha256=XCCxbC21OByJLmd-MzjURWlCZlX5p3nvjGRfle_510o,1542
|
|
2
2
|
pyscript/__init__.pyi,sha256=szsE8t_GIAPz9Wx_DFdEumH6eRrF_MxpDsRFUHTDKXA,3096
|
|
3
|
-
pyscript/__main__.py,sha256=
|
|
3
|
+
pyscript/__main__.py,sha256=qheUe8pyZogsPbEaQqLulnFmzDCQckWi8ri5r0SEPFY,13485
|
|
4
4
|
pyscript/this.py,sha256=aV4HAoWibKhe34uPowyANZRLGCniHamPvnnt8KX0aEA,290
|
|
5
5
|
pyscript/core/__init__.py,sha256=1sqE-oQXVak9zrWYrTrLOzthSQuLFFip3wAnRm76YE0,863
|
|
6
6
|
pyscript/core/analyzer.py,sha256=FXYXmMaqM6Ld95_g0aIwlarZt18mLbD5q5S_j5iHYgo,15586
|
|
@@ -8,25 +8,25 @@ pyscript/core/bases.py,sha256=btBhYS4jLD38mxmf1eY3InchzV3YgwkooFtTkpfc-XE,30
|
|
|
8
8
|
pyscript/core/buffer.py,sha256=wKCwyNcNqr8MqZPr8-MIOBF_MvCRsiJM7SDXLTg9jEY,1140
|
|
9
9
|
pyscript/core/cache.py,sha256=-oYN5ftp5cV6pzV0akhYRU9ytaWhdDqD0uvfLha8aSU,3012
|
|
10
10
|
pyscript/core/checks.py,sha256=6Sv1F_o1vddZ4iYtiaIWgxB5-SXp8ps9bAku7RrGUyY,1752
|
|
11
|
-
pyscript/core/constants.py,sha256=
|
|
11
|
+
pyscript/core/constants.py,sha256=u6Z76pLu_9-5QVGP1qI_Rk1tzpsuq8ZEkb_UNoPyvR4,2102
|
|
12
12
|
pyscript/core/context.py,sha256=WbGamnSy7QoNR2XiG20WM62Lqdf6T3K8OxLT4VALids,1664
|
|
13
13
|
pyscript/core/exceptions.py,sha256=aJhBQGTzbofNrt66GZcgd71W69kyW59_RQvGrFZugwo,4099
|
|
14
|
-
pyscript/core/handlers.py,sha256=
|
|
15
|
-
pyscript/core/highlight.py,sha256=
|
|
16
|
-
pyscript/core/interpreter.py,sha256=
|
|
14
|
+
pyscript/core/handlers.py,sha256=lgYykLlhcDHgylTdcLINvTB-p4dz1XpBAwTxEGafhsc,2407
|
|
15
|
+
pyscript/core/highlight.py,sha256=VmAlHC0bUrCeGhyS9UjZC22fBt-ynTIDit2P8rN3hW0,20934
|
|
16
|
+
pyscript/core/interpreter.py,sha256=UDlgNCx5L4AW6wTGvAboJkxYhpYI3TgBGV1uEm2F35Y,48395
|
|
17
17
|
pyscript/core/lexer.py,sha256=HxS7fevqCNYCz1Q5pCUP9Znr5NCB2BKzDQtpwpcPT0k,28258
|
|
18
18
|
pyscript/core/mapping.py,sha256=5ZlMa-n_0sC0r8ivaLGj1-Onxyz2PZFQzn5kmvTjx6c,6474
|
|
19
|
-
pyscript/core/nodes.py,sha256=
|
|
20
|
-
pyscript/core/parser.py,sha256=
|
|
19
|
+
pyscript/core/nodes.py,sha256=H4dSjG0VAPBJ6o9L5JqO-M3VVi4OKWuMg7bRLq2KEG8,28744
|
|
20
|
+
pyscript/core/parser.py,sha256=zsOlwXCMsiTkagdD7r7vewzfUD6HN4V97MqCCpBq6Ig,86812
|
|
21
21
|
pyscript/core/position.py,sha256=sTsXi0pZLeKf4izK9S1RARhh0GLLGsygqpJGikA2sv4,4455
|
|
22
|
-
pyscript/core/pysbuiltins.py,sha256=
|
|
23
|
-
pyscript/core/pystypes.py,sha256=
|
|
22
|
+
pyscript/core/pysbuiltins.py,sha256=iSKHeij6AFqTCbeq53veSls9mMuXQm9TVkqfDh7bQMs,23909
|
|
23
|
+
pyscript/core/pystypes.py,sha256=OZEb87CWuVV5UykH9ewMIVA3tkm-YO3oYJedUfMofXs,11773
|
|
24
24
|
pyscript/core/results.py,sha256=HLw5KizQ7YTljOZH31LfXhUix27-4kMLJatfJYdmMRM,5966
|
|
25
25
|
pyscript/core/runner.py,sha256=kxO2N1-ZNdGIIN7KzOU2d0uD1THE1qkfIcuPJ59_4eA,13592
|
|
26
|
-
pyscript/core/shell.py,sha256=
|
|
26
|
+
pyscript/core/shell.py,sha256=9jtLLRmdcOVFeuF5FnSmMJoZzaCLv8IADHLnUpwppOA,14897
|
|
27
27
|
pyscript/core/symtab.py,sha256=kUka8t6R7u275MSHua8fF2RxnLggfPlYH9F2nnuz1zY,3922
|
|
28
28
|
pyscript/core/token.py,sha256=smCBhmBzXOZao3nlBMedKuY_1BGhueL5akPUL3-i6H4,4215
|
|
29
|
-
pyscript/core/version.py,sha256=
|
|
29
|
+
pyscript/core/version.py,sha256=Y-aE59XGjVHG-QOldkYRwxY6YT9hmEiY0GDhIZr7b_A,3298
|
|
30
30
|
pyscript/core/editor/__init__.py,sha256=fNSm0C7zsPgYiUiuEjOK05ZfJFdFz6z34wLATpnKbMk,786
|
|
31
31
|
pyscript/core/editor/bases.py,sha256=26FC7K37hupwTY7BLewV7wuv7Dv3uTqb9yrtk6imFEc,2312
|
|
32
32
|
pyscript/core/editor/gui.py,sha256=mGQIyBsKeKhtq1ZQ8EdLANCJxBoFWIMClTX2BF9OSmc,10831
|
|
@@ -34,27 +34,28 @@ pyscript/core/editor/terminal.py,sha256=cNQvtHA4yF3rJcJ2VhaYP63whNApW9DCsuz5Nzxm
|
|
|
34
34
|
pyscript/core/utils/__init__.py,sha256=gBevG7aXEaijEZOW-NCvyCzvhbdRTT6DUr-f0NCaJww,289
|
|
35
35
|
pyscript/core/utils/ansi.py,sha256=4fi-5OxVNMbxvwdHHDC2_9_urv6eLebJDLk9iYnlrmc,4693
|
|
36
36
|
pyscript/core/utils/debug.py,sha256=JQSFK68xGJDdBgg9ty-T6NJQ8EPA0iTypKiKHc-7h0U,3086
|
|
37
|
-
pyscript/core/utils/decorators.py,sha256=
|
|
37
|
+
pyscript/core/utils/decorators.py,sha256=eJfMAuyx-kDT9RR64FJrPb24qv1hkMpnBHPoQ8Gj5ek,1584
|
|
38
38
|
pyscript/core/utils/generic.py,sha256=Cp1N1XZlEN6PJCdaMq_1goLnHk4wBTcjrxHyMbHp5BI,2178
|
|
39
39
|
pyscript/core/utils/module.py,sha256=o8e6gF5OhgDH0O1vOfOEHst4FFaPAxXm5tbdXO11XuY,1729
|
|
40
40
|
pyscript/core/utils/path.py,sha256=YF7zCwgq8zT4szb3gVsaLdSo8MYZHW8HmxPxrTL2umQ,583
|
|
41
41
|
pyscript/core/utils/similarity.py,sha256=Ez2BOU4f0134v9aFcOH6GQFET0LN8apjRxVh_B_PKRk,998
|
|
42
|
-
pyscript/core/utils/string.py,sha256=
|
|
42
|
+
pyscript/core/utils/string.py,sha256=iKVoxQE9rijVCZ9tWJlaBCYTAq3O3GT6xVlOuCRmZs0,1719
|
|
43
43
|
pyscript/lib/__hello__.pys,sha256=FwyWxN8xK6S-kXmJN7yX3nvE-OM5_YYVSS1TunUyyYk,91
|
|
44
44
|
pyscript/lib/ansi.pys,sha256=DskXRN7U3rS8Jx91G_g7MMZJeAl1PMshtaHRfGuTvOY,36
|
|
45
45
|
pyscript/lib/brainfuck.pys,sha256=mWPQIapDPwnBWdzSdtko4DclO0l8281l2eIFYIM43bM,6035
|
|
46
46
|
pyscript/lib/code.pys,sha256=EUuhoaogFX8zKT0OeBXlpJR_qBSylPiW7EQrRv6Eczs,10
|
|
47
47
|
pyscript/lib/dis.pys,sha256=GDFWyh7gpiUnQh-5kFeX3Sctc_gqsFVE6JAknO-Ppmw,163
|
|
48
|
-
pyscript/lib/explorer.pys,sha256=
|
|
49
|
-
pyscript/lib/history.pys,sha256=
|
|
48
|
+
pyscript/lib/explorer.pys,sha256=EP24XYeeTNdsYncesCMcT9ovKZs2jaeXeXkfI-InlKc,5248
|
|
49
|
+
pyscript/lib/history.pys,sha256=036osIZ0eHdUKAJKIgV5ZpBdY7i7ooyH6_c8NLgVtw8,1033
|
|
50
50
|
pyscript/lib/inspect.pys,sha256=5H03yPx6D2NT00hLjXAHbvnmt3cvmm77mSkyaMVkju4,1011
|
|
51
51
|
pyscript/lib/jsdict.pys,sha256=_VOnNuKKVV0ShZ1iTlHG0Fu1JwsFcRTbj-JfKf1lVrI,72
|
|
52
52
|
pyscript/lib/keyword.pys,sha256=aC2dOtWvMyoM2iINK6CQQM5VahR6PGZW82SPtn475Ng,93
|
|
53
53
|
pyscript/lib/opcode.pys,sha256=EUuhoaogFX8zKT0OeBXlpJR_qBSylPiW7EQrRv6Eczs,10
|
|
54
54
|
pyscript/lib/parser.pys,sha256=fSpiibYQbNRvcpLrK3sU7Y3rkqE0WK1aigjqf1NytiE,5560
|
|
55
55
|
pyscript/lib/pdisplay.pys,sha256=K7uzOyMiR363OoZoUjCXQqPSzV_cuOZJxlALZL8FgIw,416
|
|
56
|
-
pyscript/lib/site.pys,sha256=
|
|
56
|
+
pyscript/lib/site.pys,sha256=1xlgH9cAcEJmVsacfK7jyqzTdIUcU8Ef8YjRENcrWzk,3242
|
|
57
57
|
pyscript/lib/symtable.pys,sha256=SzQc2a9oI5OMhCJ_jkwEbk_Ih5UMmF-tjR1Dix9_wpo,98
|
|
58
|
+
pyscript/lib/this.pys,sha256=qX6eBYq5bq2_hvpn76w1D4EvVktwwsr-iXysALroCaw,352
|
|
58
59
|
pyscript/lib/token.pys,sha256=CP6NU3fD9_TrVNiEgmhHmNyqfxv39L31LllqATSNPC4,320
|
|
59
60
|
pyscript/lib/ast/__init__.pys,sha256=zH_Zkv9W0HHaQYwjVciihNo5-1aXFCbPGmZP0XVBav0,823
|
|
60
61
|
pyscript/lib/ast/ast_dump.py,sha256=j16Ze4J_YQkCNDRCtg66N_JReyuJVrFVhtwGLy7Iy8A,13101
|
|
@@ -62,11 +63,11 @@ pyscript/lib/ast/ast_literal_eval.py,sha256=WwjDc6_k1sgUn94vOSDcyfeJ3PMaP_g4jyHT
|
|
|
62
63
|
pyscript/lib/ast/ast_unparse.py,sha256=miEfQyQ5Dw8SnqTOyYix9ke4K01AWYDUb_l2cn5B8JM,15020
|
|
63
64
|
pyscript/lib/ast/ast_walk.py,sha256=Q-Nq5sOm1MEniIgZkglELYX8QjX6GXznJrOoUZngAXU,6947
|
|
64
65
|
pyscript/lib/dual/__init__.pys,sha256=zt2zNiN3KMoRUVpft4HZzMcn8IW9zUE4gv9i2_n3GNI,326
|
|
65
|
-
pyscript/lib/dual/py_dual.py,sha256=
|
|
66
|
+
pyscript/lib/dual/py_dual.py,sha256=MZQxqexZEhKnls6KtLUKqcClO_cvJTklHO8bO1tLepk,9339
|
|
66
67
|
pyscript/lib/fpstimer/__init__.pys,sha256=PcBFQCck80IA64Zr6QrZakz1XbuZ7nHmvlN6gTAi-Xg,93
|
|
67
68
|
pyscript/lib/fpstimer/py_fpstimer.py,sha256=H8AbSakjk_7KNwXEYXimmbzdJV43Z7j6BXUGdxWhvag,1651
|
|
68
|
-
pyscript/lib/getch/__init__.pys,sha256=
|
|
69
|
-
pyscript/lib/getch/py_getch.py,sha256=
|
|
69
|
+
pyscript/lib/getch/__init__.pys,sha256=7RVKJU9hcQ1xYlNsJbEJkrUzGKZhLiTz6T7dehaIIeU,201
|
|
70
|
+
pyscript/lib/getch/py_getch.py,sha256=9SmIF5slVvh6hIx4LSMJFXHLpL0Djfbp1rbw0lermzs,2567
|
|
70
71
|
pyscript/lib/tokenize/__init__.pys,sha256=lJSBSM5YrfrBNoX1Bk-GdkEiMIzlICnWgvW2CfZQcOI,338
|
|
71
72
|
pyscript/lib/tokenize/tok_untokenize.py,sha256=dUH5qsNyGPD69aEGWSSAPA4Qg5xBQlLkjN2wUqZMsD8,2963
|
|
72
73
|
pyscript/other/.nomedia,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -74,9 +75,8 @@ pyscript/other/PyScript.ico,sha256=8I6gC9ZB3iY5un5tQUZ_chj1XYj24XsIEJzqoXBLI48,8
|
|
|
74
75
|
pyscript/other/copyright,sha256=Ov5gxRKrwwRweaYgYiFTP-rVGGgiWEDCJCi2SSpLYSA,54
|
|
75
76
|
pyscript/other/credits,sha256=c49yrwp4dLyLtlrfAED7PJJ3aElkbRXz7Innu2x-Auc,159
|
|
76
77
|
pyscript/other/license,sha256=ORU3AMOH_uOwOcEe1yAt6r56mvlYjZhvCDKBNB7SU0c,1088
|
|
77
|
-
pyscript/other/message.txt,sha256=
|
|
78
|
-
|
|
79
|
-
pyscript_programming_language-1.15.
|
|
80
|
-
pyscript_programming_language-1.15.
|
|
81
|
-
pyscript_programming_language-1.15.
|
|
82
|
-
pyscript_programming_language-1.15.1.dist-info/RECORD,,
|
|
78
|
+
pyscript/other/message.txt,sha256=24pKZRoB12uZT7mcEKeCgRvV8BBvVfIjDAavqJlnMzo,2224
|
|
79
|
+
pyscript_programming_language-1.15.2.dist-info/METADATA,sha256=Nza8J30P-TrgHpzf-IzY7OXFYmy8E3EjQGy2crpbB48,20142
|
|
80
|
+
pyscript_programming_language-1.15.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
81
|
+
pyscript_programming_language-1.15.2.dist-info/top_level.txt,sha256=17-G0eqhWERkkD2m3ZGUqOtJl9SoqFVyR3rdbImxyZI,9
|
|
82
|
+
pyscript_programming_language-1.15.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|