pyscript-programming-language 1.7.1__tar.gz → 1.7.2__tar.gz

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.
Files changed (72) hide show
  1. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/PKG-INFO +1 -1
  2. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/__init__.pyi +3 -9
  3. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/cache.py +4 -4
  4. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/exceptions.py +1 -1
  5. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/highlight.py +20 -2
  6. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/lexer.py +19 -20
  7. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/mapping.py +0 -61
  8. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/parser.py +16 -1
  9. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/position.py +2 -2
  10. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/pysbuiltins.py +18 -7
  11. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/results.py +1 -1
  12. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/runner.py +6 -5
  13. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/symtab.py +1 -3
  14. pyscript_programming_language-1.7.2/pyscript/core/utils/ansi.py +64 -0
  15. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/debug.py +7 -6
  16. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/decorators.py +1 -1
  17. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/generic.py +6 -3
  18. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/module.py +9 -4
  19. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/string.py +7 -1
  20. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/version.py +23 -5
  21. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript_programming_language.egg-info/PKG-INFO +1 -1
  22. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/setup.py +1 -1
  23. pyscript_programming_language-1.7.1/pyscript/core/utils/ansi.py +0 -37
  24. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/MANIFEST.in +0 -0
  25. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/README.md +0 -0
  26. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/__init__.py +0 -0
  27. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/__main__.py +0 -0
  28. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/__init__.py +0 -0
  29. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/analyzer.py +0 -0
  30. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/bases.py +0 -0
  31. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/buffer.py +0 -0
  32. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/checks.py +0 -0
  33. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/constants.py +0 -0
  34. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/context.py +0 -0
  35. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/handlers.py +0 -0
  36. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/interpreter.py +0 -0
  37. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/nodes.py +0 -0
  38. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/objects.py +0 -0
  39. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/token.py +0 -0
  40. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/__init__.py +0 -0
  41. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/path.py +0 -0
  42. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/shell.py +0 -0
  43. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/core/utils/similarity.py +0 -0
  44. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/__hello__.pys +0 -0
  45. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/ansi.pys +0 -0
  46. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/ast/__init__.pys +0 -0
  47. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/ast/ast_dump.py +0 -0
  48. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/ast/ast_unparse.py +0 -0
  49. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/ast/ast_walk.py +0 -0
  50. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/brainfuck.pys +0 -0
  51. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/dis.pys +0 -0
  52. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/explorer.pys +0 -0
  53. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/fpstimer.pys +0 -0
  54. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/getch.pys +0 -0
  55. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/inspect.pys +0 -0
  56. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/jsdict.pys +0 -0
  57. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/keyword.pys +0 -0
  58. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/parser.pys +0 -0
  59. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/site.pys +0 -0
  60. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/symtable.pys +0 -0
  61. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/sys.pys +0 -0
  62. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/this.pys +0 -0
  63. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/token.pys +0 -0
  64. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/tokenize/__init__.pys +0 -0
  65. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/lib/tokenize/tok_untokenize.py +0 -0
  66. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/site-packages/67.pys +0 -0
  67. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript/this.py +0 -0
  68. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript_programming_language.egg-info/SOURCES.txt +0 -0
  69. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript_programming_language.egg-info/dependency_links.txt +0 -0
  70. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript_programming_language.egg-info/requires.txt +0 -0
  71. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/pyscript_programming_language.egg-info/top_level.txt +0 -0
  72. {pyscript_programming_language-1.7.1 → pyscript_programming_language-1.7.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyscript-programming-language
3
- Version: 1.7.1
3
+ Version: 1.7.2
4
4
  Summary: PyScript Programming Language
5
5
  Home-page: https://github.com/azzammuhyala/pyscript
6
6
  Author: azzammuhyala
@@ -1,5 +1,3 @@
1
- from .core.highlight import PygmentsPyScriptLexer as PygmentsPyScriptLexer
2
-
3
1
  from typing import TYPE_CHECKING, Any, Callable, Iterator, Literal, Optional
4
2
 
5
3
  if TYPE_CHECKING:
@@ -15,6 +13,7 @@ if TYPE_CHECKING:
15
13
  from types import ModuleType
16
14
 
17
15
  from . import core as core
16
+ from .core.highlight import PygmentsPyScriptLexer as PygmentsPyScriptLexer
18
17
 
19
18
  DEFAULT: int
20
19
  DEBUG: int
@@ -37,13 +36,8 @@ def pys_highlight(
37
36
  Callable[
38
37
  [
39
38
  str | Literal[
40
- 'start',
41
- 'invalid',
42
- 'identifier', 'identifier-constant', 'identifier-function', 'identifier-type',
43
- 'keyword', 'keyword-constant',
44
- 'number', 'string', 'comment', 'newline',
45
- 'default',
46
- 'end'
39
+ 'start', 'invalid', 'identifier', 'identifier-constant', 'identifier-function', 'identifier-type',
40
+ 'keyword', 'keyword-constant', 'number', 'string', 'comment', 'newline', 'default', 'end'
47
41
  ],
48
42
  PysPosition,
49
43
  str
@@ -71,7 +71,7 @@ class PysHook(Pys):
71
71
  @display.setter
72
72
  def display(self, value):
73
73
  if value is not None and not callable(value):
74
- raise TypeError("sys.hook.display: must be callable")
74
+ raise TypeError("hook.display: must be callable")
75
75
  singletons['hook.display'] = value
76
76
 
77
77
  @property
@@ -81,7 +81,7 @@ class PysHook(Pys):
81
81
  @exception.setter
82
82
  def exception(self, value):
83
83
  if value is not None and not callable(value):
84
- raise TypeError("sys.hook.exception: must be callable")
84
+ raise TypeError("hook.exception: must be callable")
85
85
  singletons['hook.exception'] = value
86
86
 
87
87
  @property
@@ -91,7 +91,7 @@ class PysHook(Pys):
91
91
  @ps1.setter
92
92
  def ps1(self, value):
93
93
  if not isinstance(value, str):
94
- raise TypeError("sys.hook.ps1: must be a string")
94
+ raise TypeError("hook.ps1: must be a string")
95
95
  singletons['hook.ps1'] = value
96
96
 
97
97
  @property
@@ -101,7 +101,7 @@ class PysHook(Pys):
101
101
  @ps2.setter
102
102
  def ps2(self, value):
103
103
  if not isinstance(value, str):
104
- raise TypeError("sys.hook.ps2: must be a string")
104
+ raise TypeError("hook.ps2: must be a string")
105
105
  singletons['hook.ps2'] = value
106
106
 
107
107
  PysUndefined()
@@ -27,7 +27,7 @@ class PysTraceback(Pys):
27
27
  if colored := not (context.flags & NO_COLOR):
28
28
  reset = acolor('reset')
29
29
  magenta = acolor('magenta')
30
- bmagenta = acolor('magenta', BOLD)
30
+ bmagenta = acolor('magenta', style=BOLD)
31
31
  else:
32
32
  reset = ''
33
33
  magenta = ''
@@ -3,15 +3,33 @@ from .buffer import PysFileBuffer
3
3
  from .checks import is_left_bracket, is_right_bracket, is_bracket, is_constant_keywords, is_public_attribute
4
4
  from .constants import TOKENS, KEYWORDS, CONSTANT_KEYWORDS, HIGHLIGHT
5
5
  from .lexer import PysLexer
6
- from .mapping import BRACKETS_MAP, HIGHLIGHT_MAP
6
+ from .mapping import BRACKETS_MAP
7
7
  from .position import PysPosition
8
8
  from .pysbuiltins import pys_builtins
9
9
  from .utils.ansi import acolor
10
10
  from .utils.decorators import typechecked
11
11
 
12
12
  from html import escape as html_escape
13
+ from types import MappingProxyType
13
14
  from typing import Callable, Optional
14
15
 
16
+ HIGHLIGHT_MAP = MappingProxyType({
17
+ 'default': '#D4D4D4',
18
+ 'keyword': '#C586C0',
19
+ 'keyword-constant': '#307CD6',
20
+ 'identifier': '#8CDCFE',
21
+ 'identifier-constant': '#2EA3FF',
22
+ 'identifier-function': '#DCDCAA',
23
+ 'identifier-type': '#4EC9B0',
24
+ 'number': '#B5CEA8',
25
+ 'string': '#CE9178',
26
+ 'brackets-0': '#FFD705',
27
+ 'brackets-1': '#D45DBA',
28
+ 'brackets-2': '#1A9FFF',
29
+ 'comment': '#549952',
30
+ 'invalid': '#B51819'
31
+ })
32
+
15
33
  _builtin_types = tuple(
16
34
  name
17
35
  for name, object in pys_builtins.__dict__.items()
@@ -221,7 +239,7 @@ except ImportError:
221
239
  class PygmentsPyScriptLexer(Pys):
222
240
 
223
241
  def __new__(cls, *args, **kwargs):
224
- raise ModuleNotFoundError("pygments is not found")
242
+ raise ModuleNotFoundError("module pygments is not found")
225
243
 
226
244
  @typechecked
227
245
  class _PysHighlightFormatter(Pys):
@@ -9,8 +9,23 @@ from .token import PysToken
9
9
  from .utils.decorators import typechecked
10
10
 
11
11
  from unicodedata import lookup as unicode_lookup
12
+ from types import MappingProxyType
12
13
  from typing import Optional
13
- from sys import stderr
14
+
15
+ import sys
16
+
17
+ ESCAPE_CHARACTERS_MAP = MappingProxyType({
18
+ '\\': '\\',
19
+ "'": "'",
20
+ '"': '"',
21
+ 'n': '\n',
22
+ 'r': '\r',
23
+ 't': '\t',
24
+ 'b': '\b',
25
+ 'f': '\f',
26
+ 'a': '\a',
27
+ 'v': '\v'
28
+ })
14
29
 
15
30
  class PysLexer(Pys):
16
31
 
@@ -415,24 +430,8 @@ class PysLexer(Pys):
415
430
  self.advance()
416
431
 
417
432
  elif self.character_in('\\\'"nrtbfav\n'):
418
-
419
- if self.character_in('\\\'"'):
420
- string += self.current_character
421
- elif self.current_character == 'n':
422
- string += '\n'
423
- elif self.current_character == 'r':
424
- string += '\r'
425
- elif self.current_character == 't':
426
- string += '\t'
427
- elif self.current_character == 'b':
428
- string += '\b'
429
- elif self.current_character == 'f':
430
- string += '\f'
431
- elif self.current_character == 'a':
432
- string += '\a'
433
- elif self.current_character == 'v':
434
- string += '\v'
435
-
433
+ if escape_character := ESCAPE_CHARACTERS_MAP.get(self.current_character):
434
+ string += escape_character
436
435
  self.advance()
437
436
 
438
437
  elif decoded_error_message is None:
@@ -521,7 +520,7 @@ class PysLexer(Pys):
521
520
  warning_displayed = True
522
521
  print(
523
522
  f"SyntaxWarning: invalid escape sequence '\\{self.current_character}'",
524
- file=stderr
523
+ file=sys.stderr
525
524
  )
526
525
 
527
526
  string += '\\' + self.current_character
@@ -1,5 +1,4 @@
1
1
  from .constants import TOKENS, KEYWORDS
2
- from .nodes import PysDictionaryNode, PysSetNode, PysListNode, PysTupleNode
3
2
 
4
3
  from operator import (
5
4
  is_not, eq, ne, lt, gt, le, ge, add, sub, mul, truediv, floordiv, pow, matmul, mod, and_, or_, xor, lshift, rshift,
@@ -65,64 +64,4 @@ BRACKETS_MAP = MappingProxyType({
65
64
  TOKENS['LEFT-CURLY']: TOKENS['RIGHT-CURLY']
66
65
  })
67
66
 
68
- BRACKETS_ITERABLE_MAP = MappingProxyType({
69
- 'dict': TOKENS['LEFT-CURLY'],
70
- 'set': TOKENS['LEFT-CURLY'],
71
- 'list': TOKENS['LEFT-SQUARE'],
72
- 'tuple': TOKENS['LEFT-PARENTHESIS']
73
- })
74
-
75
- NODE_ITERABLE_MAP = MappingProxyType({
76
- 'dict': PysDictionaryNode,
77
- 'set': PysSetNode,
78
- 'list': PysListNode,
79
- 'tuple': PysTupleNode
80
- })
81
-
82
- ANSI_NAMES_MAP = MappingProxyType({
83
- 'reset': 0,
84
- 'black': 30,
85
- 'red': 31,
86
- 'green': 32,
87
- 'yellow': 33,
88
- 'blue': 34,
89
- 'magenta': 35,
90
- 'cyan': 36,
91
- 'white': 37,
92
- 'gray': 90,
93
- 'bright-black': 90,
94
- 'bright-red': 91,
95
- 'bright-green': 92,
96
- 'bright-yellow': 93,
97
- 'bright-blue': 94,
98
- 'bright-magenta': 95,
99
- 'bright-cyan': 96,
100
- 'bright-white': 97
101
- })
102
-
103
- HIGHLIGHT_MAP = MappingProxyType({
104
- 'default': '#D4D4D4',
105
- 'keyword': '#C586C0',
106
- 'keyword-constant': '#307CD6',
107
- 'identifier': '#8CDCFE',
108
- 'identifier-constant': '#2EA3FF',
109
- 'identifier-function': '#DCDCAA',
110
- 'identifier-type': '#4EC9B0',
111
- 'number': '#B5CEA8',
112
- 'string': '#CE9178',
113
- 'brackets-0': '#FFD705',
114
- 'brackets-1': '#D45DBA',
115
- 'brackets-2': '#1A9FFF',
116
- 'comment': '#549952',
117
- 'invalid': '#B51819'
118
- })
119
-
120
- TAG_VERSION_MAP = MappingProxyType({
121
- 'a': 'alpha',
122
- 'b': 'beta',
123
- 'rc': 'release candidate',
124
- 'dev': 'development',
125
- 'post': 'post'
126
- })
127
-
128
67
  EMPTY_MAP = MappingProxyType({})
@@ -3,7 +3,7 @@ from .checks import is_right_bracket
3
3
  from .constants import TOKENS, KEYWORDS, DEFAULT, REVERSE_POW_XOR
4
4
  from .context import PysContext
5
5
  from .exceptions import PysTraceback
6
- from .mapping import BRACKETS_ITERABLE_MAP, NODE_ITERABLE_MAP, BRACKETS_MAP
6
+ from .mapping import BRACKETS_MAP
7
7
  from .nodes import *
8
8
  from .position import PysPosition
9
9
  from .results import PysParserResult
@@ -11,8 +11,23 @@ from .token import PysToken
11
11
  from .utils.decorators import typechecked
12
12
  from .utils.generic import setimuattr
13
13
 
14
+ from types import MappingProxyType
14
15
  from typing import Optional, Callable
15
16
 
17
+ BRACKETS_ITERABLE_MAP = MappingProxyType({
18
+ 'dict': TOKENS['LEFT-CURLY'],
19
+ 'set': TOKENS['LEFT-CURLY'],
20
+ 'list': TOKENS['LEFT-SQUARE'],
21
+ 'tuple': TOKENS['LEFT-PARENTHESIS']
22
+ })
23
+
24
+ NODE_ITERABLE_MAP = MappingProxyType({
25
+ 'dict': PysDictionaryNode,
26
+ 'set': PysSetNode,
27
+ 'list': PysListNode,
28
+ 'tuple': PysTupleNode
29
+ })
30
+
16
31
  class PysParser(Pys):
17
32
 
18
33
  @typechecked
@@ -11,7 +11,7 @@ class PysPosition(Pys):
11
11
 
12
12
  @typechecked
13
13
  def __init__(self, file: PysFileBuffer, start: int, end: int) -> None:
14
- is_positionless = start < 0 or end < 0 or start > end
14
+ is_positionless = start < 0 or end < 0 or start > end or end > len(file.text) + 1
15
15
 
16
16
  setimuattr(self, 'file', file)
17
17
  setimuattr(self, 'start', -1 if is_positionless else start)
@@ -31,7 +31,7 @@ class PysPosition(Pys):
31
31
 
32
32
  if colored:
33
33
  reset = acolor('reset')
34
- bred = acolor('red', BOLD)
34
+ bred = acolor('red', style=BOLD)
35
35
  else:
36
36
  reset = ''
37
37
  bred = ''
@@ -7,7 +7,7 @@ from .objects import PysPythonFunction
7
7
  from .results import PysRunTimeResult
8
8
  from .symtab import new_symbol_table
9
9
  from .utils.generic import get_any, is_object_of as isobjectof, import_readline
10
- from .utils.module import get_module_name_from_path, get_module_path, set_python_path
10
+ from .utils.module import get_module_name_from_path, get_module_path, set_python_path, remove_python_path
11
11
  from .utils.path import getcwd, normpath
12
12
  from .utils.shell import PysCommandLineShell
13
13
  from .utils.string import normstr
@@ -18,6 +18,7 @@ from os.path import dirname
18
18
  from types import ModuleType
19
19
 
20
20
  import builtins
21
+ import sys
21
22
 
22
23
  def _supported_method(pyfunc, object, name, *args, **kwargs):
23
24
  method = getattr(object, name, undefined)
@@ -83,13 +84,14 @@ def require(pyfunc, name):
83
84
  name, *other_components = normstr(name).split('>')
84
85
  code = pyfunc.__code__
85
86
  context = code.context
87
+ filename = context.file.name
86
88
 
87
89
  for p in path:
88
90
  module_path = get_module_path(normpath(p, name, absolute=False))
89
91
  if module_path is not None:
90
92
  break
91
93
  else:
92
- module_path = get_module_path(normpath(dirname(context.file.name) or getcwd(), name, absolute=False))
94
+ module_path = get_module_path(normpath(dirname(filename) or getcwd(), name, absolute=False))
93
95
 
94
96
  if module_path is None:
95
97
  if name == '_pyscript':
@@ -104,7 +106,7 @@ def require(pyfunc, name):
104
106
  if module_path in loading_modules:
105
107
  raise ImportError(
106
108
  f"cannot import module name {name!r} "
107
- f"from partially initialized module {context.file.name!r}, "
109
+ f"from partially initialized module {filename!r}, "
108
110
  "mostly during circular import"
109
111
  )
110
112
 
@@ -154,8 +156,12 @@ def require(pyfunc, name):
154
156
 
155
157
  @PysPythonFunction
156
158
  def pyimport(pyfunc, name):
157
- set_python_path(dirname(pyfunc.__code__.context.file.name))
158
- return import_module(normstr(name))
159
+ dirpath = dirname(pyfunc.__code__.context.file.name)
160
+ try:
161
+ set_python_path(dirpath)
162
+ return import_module(normstr(name))
163
+ finally:
164
+ remove_python_path(dirpath)
159
165
 
160
166
  @PysPythonFunction
161
167
  def breakpoint(pyfunc):
@@ -165,12 +171,17 @@ def breakpoint(pyfunc):
165
171
  from .runner import pys_runner
166
172
 
167
173
  code = pyfunc.__code__
168
- symtab = code.context.symbol_table
174
+ context = code.context
175
+ position = code.position
176
+ symtab = context.symbol_table
177
+
169
178
  shell = PysCommandLineShell('(Pdb) ', '... ')
170
179
  scopes = []
171
180
 
172
181
  import_readline()
173
182
 
183
+ print(f"> {context.file.name}({position.start_line}){context.name}")
184
+
174
185
  try:
175
186
  hook.running_breakpoint = True
176
187
 
@@ -233,7 +244,7 @@ def breakpoint(pyfunc):
233
244
 
234
245
  except KeyboardInterrupt:
235
246
  shell.reset()
236
- print('\r--keyboardIterrupt--')
247
+ print('\r--KeyboardInterrupt--', file=sys.stderr)
237
248
 
238
249
  except EOFError as e:
239
250
  raise SystemExit from e
@@ -51,7 +51,7 @@ class PysParserResult(PysResult):
51
51
  class PysRunTimeResult(PysResult):
52
52
 
53
53
  __slots__ = (
54
- 'should_continue', 'should_break', 'func_return_value', 'func_should_return', 'value', 'error',
54
+ 'should_continue', 'should_break', 'func_should_return', 'func_return_value', 'value', 'error',
55
55
  '_context', '_position'
56
56
  )
57
57
 
@@ -18,10 +18,11 @@ from .utils.generic import setimuattr, get_frame, get_locals, import_readline
18
18
  from .utils.shell import PysCommandLineShell
19
19
  from .version import version
20
20
 
21
- from sys import stderr, version as pyversion
22
21
  from types import ModuleType
23
22
  from typing import Any, Literal, Optional
24
23
 
24
+ import sys
25
+
25
26
  def _normalize_globals(file, globals):
26
27
  if globals is None:
27
28
  symtab, _ = new_symbol_table(symbols=get_locals(3 if _TYPECHECK else 2))
@@ -235,13 +236,13 @@ def pys_shell(
235
236
  bmagenta = ''
236
237
  else:
237
238
  reset = acolor('reset')
238
- bmagenta = acolor('magenta', BOLD)
239
+ bmagenta = acolor('magenta', style=BOLD)
239
240
 
240
241
  import_readline()
241
242
 
242
243
  print(f'PyScript {version}')
243
- print(f'Python {pyversion}')
244
- print('Type "help" or "license" for more information; "exit" or "/exit" to exit the shell.')
244
+ print(f'Python {sys.version}')
245
+ print('Type "help" or "license" for more information; Type "exit" or "/exit" to exit the shell')
245
246
 
246
247
  try:
247
248
  hook.running_shell = True
@@ -271,7 +272,7 @@ def pys_shell(
271
272
 
272
273
  except KeyboardInterrupt:
273
274
  shell.reset()
274
- print(f'\r{bmagenta}KeyboardInterrupt{reset}', file=stderr)
275
+ print(f'\r{bmagenta}KeyboardInterrupt{reset}', file=sys.stderr)
275
276
 
276
277
  except EOFError:
277
278
  print()
@@ -29,9 +29,7 @@ class PysSymbolTable(Pys):
29
29
  builtins = self.symbols.get('__builtins__', undefined)
30
30
  if builtins is not undefined:
31
31
  return (
32
- builtins
33
- if isinstance(builtins, dict) else
34
- getattr(builtins, '__dict__', EMPTY_MAP)
32
+ builtins if isinstance(builtins, dict) else getattr(builtins, '__dict__', EMPTY_MAP)
35
33
  ).get(name, undefined)
36
34
 
37
35
  return value
@@ -0,0 +1,64 @@
1
+ from collections.abc import Iterable
2
+ from types import MappingProxyType
3
+
4
+ ANSI_NAMES_MAP = MappingProxyType({
5
+ 'reset': 0,
6
+ 'black': 30,
7
+ 'red': 31,
8
+ 'green': 32,
9
+ 'yellow': 33,
10
+ 'blue': 34,
11
+ 'magenta': 35,
12
+ 'cyan': 36,
13
+ 'white': 37,
14
+ 'gray': 90,
15
+ 'bright-black': 90,
16
+ 'bright-red': 91,
17
+ 'bright-green': 92,
18
+ 'bright-yellow': 93,
19
+ 'bright-blue': 94,
20
+ 'bright-magenta': 95,
21
+ 'bright-cyan': 96,
22
+ 'bright-white': 97
23
+ })
24
+
25
+ DEFAULT = 0
26
+ BACKGROUND = 1 << 0
27
+ BOLD = 1 << 1
28
+ ITALIC = 1 << 2
29
+ UNDER = 1 << 3
30
+ STRIKET = 1 << 4
31
+
32
+ def acolor(*args, style=DEFAULT):
33
+ if not args:
34
+ raise TypeError("acolor(): need at least 1 argument")
35
+ elif len(args) == 1:
36
+ arg = args[0]
37
+ else:
38
+ arg = args
39
+
40
+ styles = ''
41
+
42
+ if style & BOLD:
43
+ styles += '1'
44
+ if style & ITALIC:
45
+ styles += '3'
46
+ if style & UNDER:
47
+ styles += '4'
48
+ if style & STRIKET:
49
+ styles += '9'
50
+
51
+ offset = 10 if style & BACKGROUND else 0
52
+ style = f'\x1b[{";".join(styles)}m' if styles else ''
53
+
54
+ if isinstance(arg, str):
55
+ if (color := arg.strip().lower().replace(' ', '-').replace('_', '-')) in ANSI_NAMES_MAP:
56
+ return f'{style}\x1b[{ANSI_NAMES_MAP[color] + offset}m'
57
+ arg = arg.split()
58
+
59
+ if isinstance(arg, Iterable):
60
+ color = tuple(map(int, arg))
61
+ if len(color) == 3 and all(0 <= c <= 255 for c in color):
62
+ return f'{style}\x1b[{38 + offset};2;{";".join(map(str, color))}m'
63
+
64
+ raise TypeError("acolor(): the argument is invalid for ansi color")
@@ -2,7 +2,9 @@ from ..constants import ENV_PYSCRIPT_NO_EXCEPTHOOK
2
2
  from ..exceptions import PysSignal
3
3
 
4
4
  from os import environ
5
- from sys import excepthook, stderr
5
+ from sys import excepthook
6
+
7
+ import sys
6
8
 
7
9
  def print_display(value):
8
10
  if value is not None:
@@ -10,19 +12,18 @@ def print_display(value):
10
12
 
11
13
  def print_traceback(exc_type, exc_value, exc_tb):
12
14
  for line in exc_tb.string_traceback().splitlines():
13
- print(line, file=stderr)
15
+ print(line, file=sys.stderr)
14
16
 
15
17
  def sys_excepthook(exc_type, exc_value, exc_tb):
16
- if exc_type is PysSignal and exc_value.result.error is not None:
17
- print_traceback(None, None, exc_value.result.error)
18
- print('\nThe above PyScript exception was the direct cause of the following exception:\n', file=stderr)
18
+ if exc_type is PysSignal and (traceback := exc_value.result.error) is not None:
19
+ print_traceback(None, None, traceback)
20
+ print('\nThe above PyScript exception was the direct cause of the following exception:\n', file=sys.stderr)
19
21
  excepthook(exc_type, exc_value, exc_tb)
20
22
 
21
23
  def thread_excepthook(args):
22
24
  sys_excepthook(args.exc_type, args.exc_value, args.exc_traceback)
23
25
 
24
26
  if environ.get(ENV_PYSCRIPT_NO_EXCEPTHOOK) is None:
25
- import sys
26
27
  import threading
27
28
 
28
29
  sys.excepthook = sys_excepthook
@@ -24,7 +24,7 @@ class _PysNameSpaceUtilities(Pys):
24
24
  __slots__ = ()
25
25
 
26
26
  def __new__(cls):
27
- raise TypeError("cannot create namespace object")
27
+ raise TypeError("cannot create namespace class instances")
28
28
 
29
29
  def new_singleton(cls, *args, **kwargs):
30
30
  from ..cache import singletons
@@ -41,13 +41,16 @@ def is_object_of(obj, class_or_tuple):
41
41
 
42
42
  _READLINE = environ.get(ENV_PYSCRIPT_NO_READLINE) is None
43
43
 
44
- def import_readline():
45
- if platform != 'win32' and _READLINE:
44
+ if platform != 'win32' and _READLINE:
45
+ def import_readline():
46
46
  try:
47
47
  import readline
48
+ return True
48
49
  except:
49
50
  return False
50
- return True
51
+ else:
52
+ def import_readline():
53
+ return False
51
54
 
52
55
  def get_error_args(exception):
53
56
  if exception is None:
@@ -1,7 +1,8 @@
1
+ from .path import normpath, base, extension
2
+
1
3
  from os.path import isdir, isfile, join
2
- from sys import path as pypath
3
4
 
4
- from .path import normpath, base, extension
5
+ import sys
5
6
 
6
7
  def get_module_name_from_path(path):
7
8
  return base(normpath(path, absolute=False))
@@ -21,5 +22,9 @@ def get_module_path(path):
21
22
  return candidate
22
23
 
23
24
  def set_python_path(path):
24
- if path not in pypath:
25
- pypath.insert(0, path)
25
+ if path not in sys.path:
26
+ sys.path.insert(0, path)
27
+
28
+ def remove_python_path(path):
29
+ if path in sys.path:
30
+ sys.path.remove(path)
@@ -18,7 +18,13 @@ def normstr(obj):
18
18
  elif isinstance(obj, Iterator):
19
19
  return '\n'.join(map(normstr, obj))
20
20
 
21
- elif isinstance(obj, BuiltinMethodType) and isinstance(getattr(obj, '__self__', None), TextIOWrapper):
21
+ elif isinstance(obj, BuiltinMethodType) and \
22
+ isinstance(self := getattr(obj, '__self__', None), TextIOWrapper) and \
23
+ obj.__name__ == 'readline':
24
+
25
+ if not self.readable():
26
+ raise TypeError("unreadable IO")
27
+
22
28
  lines = []
23
29
  while True:
24
30
  if not (line := obj()):
@@ -1,13 +1,22 @@
1
1
  from .bases import Pys
2
- from .mapping import TAG_VERSION_MAP
3
2
  from .utils.decorators import immutable, inheritable, singleton
4
3
  from .utils.generic import version_match
5
4
 
6
- __version__ = '1.7.1'
7
- __date__ = '13 December 2025, 15:45 UTC+7'
5
+ from types import MappingProxyType
6
+
7
+ __version__ = '1.7.2'
8
+ __date__ = '19 December 2025, 13:00 UTC+7'
8
9
 
9
10
  version = f'{__version__} ({__date__})'
10
11
 
12
+ TAG_VERSION_MAP = MappingProxyType({
13
+ 'a': 'alpha',
14
+ 'b': 'beta',
15
+ 'rc': 'release candidate',
16
+ 'dev': 'development',
17
+ 'post': 'post'
18
+ })
19
+
11
20
  @singleton
12
21
  @immutable
13
22
  @inheritable
@@ -87,8 +96,17 @@ class PysVersionInfo(Pys, tuple):
87
96
 
88
97
  def __repr__(self):
89
98
  return (
90
- f'VersionInfo(major={self.major!r}, minor={self.minor!r}, micro={self.micro!r}' +
91
- ('' if self.pre_tag is None else f', pre_tag={self.pre_tag!r}, pre_num={self.pre_num!r}') +
99
+ 'VersionInfo('
100
+ f'major={self.major!r}, '
101
+ f'minor={self.minor!r}, '
102
+ f'micro={self.micro!r}' +
103
+ (
104
+ ''
105
+ if self.pre_tag is None else
106
+ ', '
107
+ f'pre_tag={self.pre_tag!r}, '
108
+ f'pre_num={self.pre_num!r}'
109
+ ) +
92
110
  ')'
93
111
  )
94
112
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyscript-programming-language
3
- Version: 1.7.1
3
+ Version: 1.7.2
4
4
  Summary: PyScript Programming Language
5
5
  Home-page: https://github.com/azzammuhyala/pyscript
6
6
  Author: azzammuhyala
@@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as file:
5
5
 
6
6
  setup(
7
7
  name='pyscript-programming-language',
8
- version='1.7.1',
8
+ version='1.7.2',
9
9
  description='PyScript Programming Language',
10
10
  long_description=long_description,
11
11
  long_description_content_type='text/markdown',
@@ -1,37 +0,0 @@
1
- from collections.abc import Iterable
2
-
3
- DEFAULT = 0
4
- BACKGROUND = 1 << 0
5
- BOLD = 1 << 1
6
- ITALIC = 1 << 2
7
- UNDER = 1 << 3
8
- STRIKET = 1 << 4
9
-
10
- def acolor(arg, style=DEFAULT):
11
- from ..mapping import ANSI_NAMES_MAP
12
-
13
- styles = ''
14
-
15
- if style & BOLD:
16
- styles += '1'
17
- if style & ITALIC:
18
- styles += '3'
19
- if style & UNDER:
20
- styles += '4'
21
- if style & STRIKET:
22
- styles += '9'
23
-
24
- offset = 10 if style & BACKGROUND else 0
25
- style = f'\x1b[{";".join(styles)}m' if styles else ''
26
-
27
- if isinstance(arg, str):
28
- arg = arg.strip().replace(' ', '-').replace('_', '-').lower()
29
- if arg in ANSI_NAMES_MAP:
30
- return f'{style}\x1b[{ANSI_NAMES_MAP[arg] + offset}m'
31
-
32
- elif isinstance(arg, Iterable):
33
- arg = tuple(map(int, arg))
34
- if len(arg) == 3 and all(0 <= c <= 255 for c in arg):
35
- return f'{style}\x1b[{38 + offset};2;{";".join(map(str, arg))}m'
36
-
37
- raise TypeError("acolor(): arg is invalid for ansi color")