pyscript-programming-language 1.13.4__py3-none-any.whl → 1.14.0__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/__init__.py +2 -1
- pyscript/__init__.pyi +1 -0
- pyscript/__main__.py +87 -48
- pyscript/core/constants.py +1 -1
- pyscript/core/context.py +7 -10
- pyscript/core/editor/__init__.py +27 -11
- pyscript/core/editor/bases.py +16 -16
- pyscript/core/editor/gui.py +23 -22
- pyscript/core/editor/terminal.py +3 -3
- pyscript/core/exceptions.py +8 -13
- pyscript/core/handlers.py +34 -32
- pyscript/core/interpreter.py +21 -18
- pyscript/core/lexer.py +5 -8
- pyscript/core/mapping.py +8 -8
- pyscript/core/parser.py +99 -45
- pyscript/core/position.py +86 -81
- pyscript/core/pysbuiltins.py +39 -46
- pyscript/core/pystypes.py +16 -5
- pyscript/core/runner.py +5 -5
- pyscript/core/shell.py +10 -12
- pyscript/core/symtab.py +14 -15
- pyscript/core/token.py +3 -4
- pyscript/core/utils/ansi.py +70 -45
- pyscript/core/utils/debug.py +18 -5
- pyscript/core/utils/generic.py +22 -3
- pyscript/core/utils/similarity.py +8 -6
- pyscript/core/utils/string.py +6 -11
- pyscript/core/version.py +2 -2
- pyscript/lib/ansi.pys +1 -14
- pyscript/lib/brainfuck.pys +3 -6
- pyscript/lib/parser.pys +6 -4
- {pyscript_programming_language-1.13.4.dist-info → pyscript_programming_language-1.14.0.dist-info}/METADATA +27 -25
- {pyscript_programming_language-1.13.4.dist-info → pyscript_programming_language-1.14.0.dist-info}/RECORD +35 -36
- pyscript/site-packages/anniversary.pys +0 -4
- {pyscript_programming_language-1.13.4.dist-info → pyscript_programming_language-1.14.0.dist-info}/WHEEL +0 -0
- {pyscript_programming_language-1.13.4.dist-info → pyscript_programming_language-1.14.0.dist-info}/top_level.txt +0 -0
pyscript/__init__.py
CHANGED
|
@@ -12,7 +12,7 @@ from .core.constants import (
|
|
|
12
12
|
DEFAULT, NO_COLOR, NO_WARNING, SILENT, DEBUG, RETURN_RESULT, DONT_SHOW_BANNER_ON_SHELL, CLASSIC_LINE_SHELL,
|
|
13
13
|
NO_COLOR_PROMPT, NOTEBOOK, LEXER_HIGHLIGHT, DICT_TO_JSDICT
|
|
14
14
|
)
|
|
15
|
-
from .core.cache import undefined
|
|
15
|
+
from .core.cache import pys_sys, undefined
|
|
16
16
|
from .core.highlight import (
|
|
17
17
|
HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight, PygmentsPyScriptStyle, PygmentsPyScriptLexer,
|
|
18
18
|
PygmentsPyScriptShellLexer
|
|
@@ -38,6 +38,7 @@ __all__ = (
|
|
|
38
38
|
'HLFMT_ANSI',
|
|
39
39
|
'HLFMT_BBCODE',
|
|
40
40
|
'undefined',
|
|
41
|
+
'pys_sys',
|
|
41
42
|
'version',
|
|
42
43
|
'version_info',
|
|
43
44
|
'pys_highlight',
|
pyscript/__init__.pyi
CHANGED
pyscript/__main__.py
CHANGED
|
@@ -4,8 +4,7 @@ from .core.constants import (
|
|
|
4
4
|
ENV_PYSCRIPT_NO_COLOR_PROMPT, ENV_PYSCRIPT_CLASSIC_LINE_SHELL, DEFAULT, NO_COLOR, NO_WARNING, DEBUG,
|
|
5
5
|
DONT_SHOW_BANNER_ON_SHELL, CLASSIC_LINE_SHELL, NO_COLOR_PROMPT, NOTEBOOK
|
|
6
6
|
)
|
|
7
|
-
from .core
|
|
8
|
-
from .core.editor.terminal import PysTerminalEditor, TERMINAL_SUPPORT
|
|
7
|
+
from .core import editor
|
|
9
8
|
from .core.highlight import (
|
|
10
9
|
PYGMENTS, HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight, PygmentsPyScriptStyle, PygmentsPyScriptLexer
|
|
11
10
|
)
|
|
@@ -33,24 +32,29 @@ if PYGMENTS:
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
from argparse import OPTIONAL, REMAINDER, ArgumentParser
|
|
35
|
+
from re import compile as compile_regex
|
|
36
36
|
|
|
37
37
|
import sys
|
|
38
38
|
|
|
39
|
+
if sys.version_info >= (3, 13):
|
|
40
|
+
try:
|
|
41
|
+
from _colorize import can_colorize
|
|
42
|
+
COLORIZE = can_colorize()
|
|
43
|
+
except:
|
|
44
|
+
# respect for NO_COLOR, see more here: https://no-color.org
|
|
45
|
+
COLORIZE = not is_environ('NO_COLOR')
|
|
46
|
+
else:
|
|
47
|
+
COLORIZE = True
|
|
48
|
+
|
|
39
49
|
FORMATER_HIGHLIGHT_MAP = {
|
|
40
50
|
'html': HLFMT_HTML,
|
|
41
51
|
'ansi': HLFMT_ANSI,
|
|
42
52
|
'bbcode': HLFMT_BBCODE
|
|
43
53
|
}
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
(GUI_SUPPORT, 'gui', PysGUIEditor),
|
|
49
|
-
(TERMINAL_SUPPORT, 'terminal', PysTerminalEditor)
|
|
50
|
-
] if support
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
arguments_requiring_value = {'-l', '--highlight', '-r', '--py-recursion'}
|
|
55
|
+
editors = tuple(editor for editor in editor.__all__ if editor != 'bases')
|
|
56
|
+
arguments_requiring_argv = {'-c', '--command', '-m', '--module'}
|
|
57
|
+
arguments_requiring_value = {'-e', '--editor', '-l', '--highlight', '-r', '--py-recursion'}
|
|
54
58
|
|
|
55
59
|
parser = ArgumentParser(
|
|
56
60
|
prog=f'{base(sys.executable)} -m pyscript',
|
|
@@ -77,14 +81,12 @@ parser.add_argument(
|
|
|
77
81
|
help="set a debug flag, this will ignore assert statement. Check the flag is active with the __debug__ keyword"
|
|
78
82
|
)
|
|
79
83
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
)
|
|
87
|
-
arguments_requiring_value.update({'-e', '--editor'})
|
|
84
|
+
parser.add_argument(
|
|
85
|
+
'-e', '--editor',
|
|
86
|
+
choices=editors,
|
|
87
|
+
default=None,
|
|
88
|
+
help="open the editor panel from a 'file'",
|
|
89
|
+
)
|
|
88
90
|
|
|
89
91
|
parser.add_argument(
|
|
90
92
|
'-i', '--inspect',
|
|
@@ -185,23 +187,27 @@ argv = sys.argv[1:]
|
|
|
185
187
|
argc = len(argv)
|
|
186
188
|
index = 0
|
|
187
189
|
arg_index = -1
|
|
190
|
+
parser_color = COLORIZE
|
|
188
191
|
|
|
189
192
|
while index < argc:
|
|
190
193
|
arg = argv[index]
|
|
191
|
-
if not arg.startswith('-') or arg == '--':
|
|
192
|
-
break
|
|
193
194
|
|
|
194
|
-
if arg
|
|
195
|
-
arg_index = index + 2
|
|
195
|
+
if not arg.startswith('-') or arg == '--':
|
|
196
196
|
break
|
|
197
|
-
elif arg in
|
|
197
|
+
elif arg in arguments_requiring_argv:
|
|
198
198
|
arg_index = index + 2
|
|
199
199
|
break
|
|
200
|
+
elif arg in ('-n', '--no-color'):
|
|
201
|
+
parser_color = False
|
|
200
202
|
|
|
201
203
|
index += 1
|
|
202
204
|
if arg in arguments_requiring_value:
|
|
203
205
|
index += 1
|
|
204
206
|
|
|
207
|
+
if sys.version_info >= (3, 14):
|
|
208
|
+
parser.color = parser_color
|
|
209
|
+
parser.suggest_on_error = True
|
|
210
|
+
|
|
205
211
|
args = parser.parse_args(argv if arg_index == -1 else argv[:arg_index])
|
|
206
212
|
arg = args.arg if arg_index == -1 else argv[arg_index:]
|
|
207
213
|
|
|
@@ -226,7 +232,7 @@ if args.terminal:
|
|
|
226
232
|
pass
|
|
227
233
|
|
|
228
234
|
if args.file is None:
|
|
229
|
-
if
|
|
235
|
+
if args.editor:
|
|
230
236
|
argument_error('-e/--editor', "argument 'file' is required")
|
|
231
237
|
elif args.highlight:
|
|
232
238
|
argument_error('-l/--highlight', "argument 'file' is required")
|
|
@@ -237,13 +243,17 @@ if args.py_recursion is not None:
|
|
|
237
243
|
except BaseException as e:
|
|
238
244
|
argument_error('-r/--py-recursion', e)
|
|
239
245
|
|
|
246
|
+
if args.P:
|
|
247
|
+
for cwd in {'', '.', getcwd()}:
|
|
248
|
+
remove_python_path(cwd)
|
|
249
|
+
|
|
240
250
|
code = 0
|
|
241
251
|
flags = DEFAULT
|
|
242
252
|
|
|
243
253
|
for condition, flag in [
|
|
244
254
|
(args.notebook or USE_NOTEBOOK, NOTEBOOK),
|
|
245
255
|
(args.classic_line_shell or is_environ(ENV_PYSCRIPT_CLASSIC_LINE_SHELL), CLASSIC_LINE_SHELL),
|
|
246
|
-
(args.no_color or
|
|
256
|
+
(args.no_color or not COLORIZE, NO_COLOR),
|
|
247
257
|
(args.no_color_prompt or is_environ(ENV_PYSCRIPT_NO_COLOR_PROMPT), NO_COLOR_PROMPT),
|
|
248
258
|
(args.debug, DEBUG),
|
|
249
259
|
(args.no_warning, NO_WARNING),
|
|
@@ -252,52 +262,78 @@ for condition, flag in [
|
|
|
252
262
|
if condition:
|
|
253
263
|
flags |= flag
|
|
254
264
|
|
|
255
|
-
if args.P:
|
|
256
|
-
for cwd in {'', '.', getcwd()}:
|
|
257
|
-
remove_python_path(cwd)
|
|
258
|
-
|
|
259
265
|
pys_sys.argv = argv = ['', *arg]
|
|
260
266
|
|
|
261
267
|
def clean_up() -> None:
|
|
262
268
|
g = globals()
|
|
263
269
|
|
|
264
270
|
for name in {
|
|
265
|
-
'ArgumentParser', 'BBCodeFormatter', 'CLASSIC_LINE_SHELL', 'DEBUG', 'DEFAULT', '
|
|
266
|
-
'ENV_PYSCRIPT_CLASSIC_LINE_SHELL', 'ENV_PYSCRIPT_NO_COLOR_PROMPT', 'FORMATER_HIGHLIGHT_MAP',
|
|
267
|
-
'FORMATER_PYGMENTS_MAP', '
|
|
268
|
-
'LatexFormatter', 'NOTEBOOK', 'NO_COLOR', 'NO_WARNING', 'NO_COLOR_PROMPT', '
|
|
269
|
-
'
|
|
270
|
-
'
|
|
271
|
-
'USE_NOTEBOOK', '__version__', '_namespace_to_symbol_table', 'arg', 'arg_index', 'argc', 'args',
|
|
271
|
+
'ArgumentParser', 'BBCodeFormatter', 'CLASSIC_LINE_SHELL', 'DEBUG', 'DEFAULT', 'i', 'index', 'is_environ', 'fd',
|
|
272
|
+
'kernel32', 'ENV_PYSCRIPT_CLASSIC_LINE_SHELL', 'ENV_PYSCRIPT_NO_COLOR_PROMPT', 'FORMATER_HIGHLIGHT_MAP', 'arg',
|
|
273
|
+
'FORMATER_PYGMENTS_MAP', 'HLFMT_ANSI', 'HLFMT_BBCODE', 'HLFMT_HTML', 'HtmlFormatter', 'OPTIONAL', 'PYGMENTS',
|
|
274
|
+
'LatexFormatter', 'NOTEBOOK', 'NO_COLOR', 'NO_WARNING', 'NO_COLOR_PROMPT', 'PygmentsPyScriptLexer', 'args',
|
|
275
|
+
'PygmentsPyScriptStyle', 'PysFileBuffer', 'REMAINDER', 'Terminal256Formatter', 'TerminalFormatter', 'flag',
|
|
276
|
+
'TerminalTrueColorFormatter', 'USE_NOTEBOOK', '__version__', '_namespace_to_symbol_table', 'arg_index', 'argc',
|
|
272
277
|
'argument_error', 'arguments_requiring_value', 'argv', 'base', 'clean_up', 'condition', 'ctypes', 'execute',
|
|
273
|
-
'
|
|
274
|
-
'
|
|
278
|
+
'file', 'find_module_path', 'getcwd', 'highlight', 'load_editor_module', 'load_file', 'module_path', 'parser',
|
|
279
|
+
'pys_highlight', 'pys_sys', 'remove_python_path', 'editors', 'editor', 'compile_regex', 'can_colorize',
|
|
280
|
+
'arguments_requiring_argv', 'COLORIZE', 'parser_color'
|
|
275
281
|
}:
|
|
276
282
|
try:
|
|
277
283
|
del g[name]
|
|
278
284
|
except:
|
|
279
285
|
continue
|
|
280
286
|
|
|
287
|
+
def load_editor_module(name: str) -> tuple[type | None, bool]:
|
|
288
|
+
if name not in editors:
|
|
289
|
+
return None, False
|
|
290
|
+
|
|
291
|
+
module = getattr(editor, name, None)
|
|
292
|
+
if module is None:
|
|
293
|
+
return None, False
|
|
294
|
+
|
|
295
|
+
class_name = compile_regex(r'Pys[A-Za-z0-9_]+Editor').fullmatch
|
|
296
|
+
support_name = compile_regex(r'[A-Z0-9_]+_SUPPORT').fullmatch
|
|
297
|
+
|
|
298
|
+
cls = None
|
|
299
|
+
support = None
|
|
300
|
+
for name in dir(module):
|
|
301
|
+
if not (cls is None or support is None):
|
|
302
|
+
break
|
|
303
|
+
elif class_name(name) and cls is None:
|
|
304
|
+
cls = getattr(module, name)
|
|
305
|
+
elif support_name(name) and support is None:
|
|
306
|
+
support = getattr(module, name)
|
|
307
|
+
else:
|
|
308
|
+
return None, False
|
|
309
|
+
|
|
310
|
+
return cls, support
|
|
311
|
+
|
|
281
312
|
def load_file(path) -> PysFileBuffer:
|
|
282
313
|
normalized = normpath(path)
|
|
314
|
+
|
|
315
|
+
def open_error(message: str) -> None:
|
|
316
|
+
argument_error('file', f"can't open file \"{normalized}\": {message}")
|
|
317
|
+
|
|
283
318
|
try:
|
|
284
319
|
with open(normalized, 'r', encoding=pys_sys.encoding) as file:
|
|
285
320
|
return PysFileBuffer(file, normalized)
|
|
286
321
|
except FileNotFoundError:
|
|
287
|
-
if not
|
|
288
|
-
|
|
322
|
+
if not args.editor:
|
|
323
|
+
open_error("No such file or directory")
|
|
289
324
|
except PermissionError:
|
|
290
|
-
|
|
325
|
+
open_error("Permission denied")
|
|
291
326
|
except IsADirectoryError:
|
|
292
|
-
|
|
327
|
+
open_error("Path is not a file")
|
|
293
328
|
except NotADirectoryError:
|
|
294
|
-
|
|
329
|
+
open_error("Attempting to access directory from file")
|
|
295
330
|
except (OSError, IOError):
|
|
296
|
-
|
|
331
|
+
open_error("Attempting to access a system directory or file")
|
|
297
332
|
except UnicodeDecodeError:
|
|
298
|
-
|
|
333
|
+
open_error("Bad file")
|
|
299
334
|
except BaseException as e:
|
|
300
335
|
argument_error('file', f"file \"{normalized}\": Unexpected error: {e}")
|
|
336
|
+
|
|
301
337
|
return PysFileBuffer('', path)
|
|
302
338
|
|
|
303
339
|
def execute(file: PysFileBuffer) -> None:
|
|
@@ -334,9 +370,12 @@ if args.file is not None:
|
|
|
334
370
|
argv[0] = args.file
|
|
335
371
|
file = load_file(args.file)
|
|
336
372
|
|
|
337
|
-
if
|
|
373
|
+
if args.editor:
|
|
374
|
+
cls, supported = load_editor_module(args.editor)
|
|
375
|
+
if not supported:
|
|
376
|
+
argument_error('-e/--editor', f"'{args.editor}' mode not supported")
|
|
338
377
|
try:
|
|
339
|
-
|
|
378
|
+
cls(file, colored=not (flags & NO_COLOR)).run()
|
|
340
379
|
except BaseException as e:
|
|
341
380
|
argument_error('-e/--editor', e)
|
|
342
381
|
|
pyscript/core/constants.py
CHANGED
|
@@ -10,7 +10,7 @@ GLOBAL_HISTORY_PATH = os.path.join(os.path.expanduser('~'), '.pyscript_history')
|
|
|
10
10
|
CONFIGURATIONS_PATH = os.path.join(OTHER_PATH, 'configurations.json')
|
|
11
11
|
|
|
12
12
|
ENV_PYSCRIPT_NO_EXCEPTHOOK = 'PYSCRIPT_NO_EXCEPTHOOK'
|
|
13
|
-
|
|
13
|
+
ENV_PYSCRIPT_WITH_GIL = 'PYSCRIPT_WITH_GIL'
|
|
14
14
|
ENV_PYSCRIPT_NO_READLINE = 'PYSCRIPT_NO_READLINE'
|
|
15
15
|
ENV_PYSCRIPT_NO_TYPECHECK = 'PYSCRIPT_NO_TYPECHECK'
|
|
16
16
|
ENV_PYSCRIPT_NO_COLOR_PROMPT = 'PYSCRIPT_NO_COLOR_PROMPT'
|
pyscript/core/context.py
CHANGED
|
@@ -3,12 +3,9 @@ from .buffer import PysFileBuffer
|
|
|
3
3
|
from .constants import DEFAULT
|
|
4
4
|
from .position import PysPosition
|
|
5
5
|
from .symtab import PysSymbolTable, PysClassSymbolTable
|
|
6
|
-
from .utils.decorators import immutable
|
|
7
|
-
from .utils.generic import setimuattr
|
|
8
6
|
|
|
9
7
|
from typing import Optional
|
|
10
8
|
|
|
11
|
-
@immutable
|
|
12
9
|
class PysContext(Pys):
|
|
13
10
|
|
|
14
11
|
__slots__ = ('file', 'name', 'qualname', 'flags', 'symbol_table', 'parent', 'parent_entry_position')
|
|
@@ -28,13 +25,13 @@ class PysContext(Pys):
|
|
|
28
25
|
if flags is None and parent:
|
|
29
26
|
flags = parent.flags
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
self.file = file
|
|
29
|
+
self.name = name
|
|
30
|
+
self.qualname = qualname
|
|
31
|
+
self.flags = DEFAULT if flags is None else flags
|
|
32
|
+
self.symbol_table = symbol_table
|
|
33
|
+
self.parent = parent
|
|
34
|
+
self.parent_entry_position = parent_entry_position
|
|
38
35
|
|
|
39
36
|
class PysClassContext(PysContext):
|
|
40
37
|
|
pyscript/core/editor/__init__.py
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
"""
|
|
2
2
|
All Editor Application Implementations for PyScript.
|
|
3
|
+
|
|
4
|
+
Not all editors are loaded (lazy import).
|
|
3
5
|
"""
|
|
4
6
|
|
|
5
|
-
from . import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
__all__ = (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
from ..utils.path import normpath
|
|
8
|
+
|
|
9
|
+
from importlib import import_module as _import
|
|
10
|
+
from os.path import dirname
|
|
11
|
+
from pkgutil import iter_modules
|
|
12
|
+
|
|
13
|
+
__all__ = tuple(frozenset(
|
|
14
|
+
name for _, name, _ in
|
|
15
|
+
iter_modules((dirname(normpath(__file__)),))
|
|
16
|
+
))
|
|
17
|
+
|
|
18
|
+
def __getattr__(name: str):
|
|
19
|
+
g = globals()
|
|
20
|
+
if name in g:
|
|
21
|
+
return g[name]
|
|
22
|
+
elif name in __all__:
|
|
23
|
+
module = _import(f'{__name__}.{name}')
|
|
24
|
+
g[name] = module
|
|
25
|
+
return module
|
|
26
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
27
|
+
|
|
28
|
+
def __dir__() -> list[str]:
|
|
29
|
+
return sorted(tuple(globals().keys()) + __all__)
|
|
30
|
+
|
|
31
|
+
del normpath, iter_modules, dirname
|
pyscript/core/editor/bases.py
CHANGED
|
@@ -3,24 +3,25 @@ from ..buffer import PysFileBuffer
|
|
|
3
3
|
from ..cache import pys_sys
|
|
4
4
|
from ..constants import CONFIGURATIONS_PATH
|
|
5
5
|
from ..utils.decorators import typecheck, inheritable
|
|
6
|
-
from ..utils.generic import
|
|
6
|
+
from ..utils.generic import delimuattr
|
|
7
7
|
from ..utils.string import normstr
|
|
8
8
|
|
|
9
9
|
from json import dump, load
|
|
10
|
+
from os.path import basename
|
|
10
11
|
from typing import Any
|
|
11
12
|
|
|
12
|
-
import os
|
|
13
|
-
|
|
14
13
|
class PysEditor(Pys):
|
|
15
14
|
|
|
16
15
|
@typecheck
|
|
17
16
|
def __init__(self, file: PysFileBuffer, colored: bool = True) -> None:
|
|
18
17
|
self.file = file
|
|
19
18
|
self.colored = bool(colored)
|
|
20
|
-
self.basename =
|
|
19
|
+
self.basename = basename(self.file.name)
|
|
21
20
|
self.used = False
|
|
22
21
|
self.modified = False
|
|
23
22
|
|
|
23
|
+
self.load_configuration()
|
|
24
|
+
|
|
24
25
|
def __init_subclass__(cls, **kwargs) -> None:
|
|
25
26
|
super().__init_subclass__(**kwargs)
|
|
26
27
|
inheritable(cls)
|
|
@@ -29,20 +30,17 @@ class PysEditor(Pys):
|
|
|
29
30
|
try:
|
|
30
31
|
with open(CONFIGURATIONS_PATH, 'r', encoding=pys_sys.encoding) as file:
|
|
31
32
|
result = load(file)
|
|
32
|
-
|
|
33
|
+
if not isinstance(result, dict):
|
|
34
|
+
raise ValueError
|
|
35
|
+
for key in result:
|
|
36
|
+
if not isinstance(key, str):
|
|
33
37
|
raise ValueError
|
|
34
|
-
|
|
35
|
-
if not isinstance(key, str):
|
|
36
|
-
raise ValueError
|
|
37
|
-
self.configurations = result
|
|
38
|
+
self.configurations = result
|
|
38
39
|
except:
|
|
39
40
|
self.configurations = {}
|
|
40
41
|
|
|
41
42
|
def get_configuration(self, configuration: str, default: Any) -> Any:
|
|
42
|
-
|
|
43
|
-
return self.configurations[configuration]
|
|
44
|
-
self.configurations[configuration] = default
|
|
45
|
-
return default
|
|
43
|
+
return self.configurations.setdefault(configuration, default)
|
|
46
44
|
|
|
47
45
|
def set_configuration(self, configuration: str, value: Any) -> None:
|
|
48
46
|
self.configurations[configuration] = value
|
|
@@ -55,11 +53,12 @@ class PysEditor(Pys):
|
|
|
55
53
|
pass
|
|
56
54
|
|
|
57
55
|
def save(self, text) -> None:
|
|
56
|
+
if not self.modified:
|
|
57
|
+
return
|
|
58
|
+
|
|
58
59
|
try:
|
|
59
|
-
text = normstr(text)
|
|
60
60
|
with open(self.file.name, 'w', encoding=pys_sys.encoding) as file:
|
|
61
|
-
file.write(text)
|
|
62
|
-
setimuattr(self.file, 'text', text)
|
|
61
|
+
file.write(normstr(text))
|
|
63
62
|
except:
|
|
64
63
|
pass
|
|
65
64
|
else:
|
|
@@ -68,4 +67,5 @@ class PysEditor(Pys):
|
|
|
68
67
|
def run(self) -> None:
|
|
69
68
|
if self.used:
|
|
70
69
|
raise RuntimeError("one application object can only be used once")
|
|
70
|
+
delimuattr(self.file, 'text')
|
|
71
71
|
self.used = True
|
pyscript/core/editor/gui.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from .bases import PysEditor
|
|
2
2
|
from ..buffer import PysFileBuffer
|
|
3
3
|
from ..constants import ICON_PATH
|
|
4
|
-
from ..highlight import PygmentsPyScriptStyle, PygmentsPyScriptLexer
|
|
4
|
+
from ..highlight import PYGMENTS, PygmentsPyScriptStyle, PygmentsPyScriptLexer
|
|
5
5
|
from ..utils.generic import boundary
|
|
6
6
|
from ..version import __version__
|
|
7
7
|
|
|
@@ -15,7 +15,8 @@ try:
|
|
|
15
15
|
PysEditor.__init__(self, file, colored)
|
|
16
16
|
Tk.__init__(self)
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
def update_tab_size():
|
|
19
|
+
self.text.configure(tabs=(self.font.measure(' '),))
|
|
19
20
|
|
|
20
21
|
def on_save(event=None):
|
|
21
22
|
text = self.text.get('1.0', 'end')
|
|
@@ -26,46 +27,40 @@ try:
|
|
|
26
27
|
def on_close():
|
|
27
28
|
if self.modified:
|
|
28
29
|
answer = messagebox.askyesnocancel('Unsaved changes', 'File has been modified. Save before exit?')
|
|
29
|
-
if answer is
|
|
30
|
+
if answer is None:
|
|
31
|
+
return
|
|
32
|
+
elif answer:
|
|
30
33
|
on_save()
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
elif answer is False:
|
|
34
|
-
self.save_configuration()
|
|
35
|
-
self.destroy()
|
|
36
|
-
else:
|
|
37
|
-
self.save_configuration()
|
|
38
|
-
self.destroy()
|
|
34
|
+
self.save_configuration()
|
|
35
|
+
self.destroy()
|
|
39
36
|
|
|
40
37
|
def on_configure(event):
|
|
41
38
|
if event.widget == self:
|
|
42
39
|
zoom = self.wm_state() == 'zoomed'
|
|
43
40
|
self.set_configuration('zoom', zoom)
|
|
44
41
|
if not zoom:
|
|
45
|
-
self.set_configuration(
|
|
46
|
-
'gui-geometry',
|
|
47
|
-
f'{event.width}x{event.height}+{event.x}+{event.y}'
|
|
48
|
-
)
|
|
42
|
+
self.set_configuration('gui-geometry', f'{event.width}x{event.height}+{event.x}+{event.y}')
|
|
49
43
|
|
|
50
44
|
def on_modified(event=None):
|
|
51
|
-
|
|
52
|
-
if text.edit_modified():
|
|
45
|
+
if self.text.edit_modified():
|
|
53
46
|
self.modified = True
|
|
54
47
|
update()
|
|
55
|
-
text.edit_modified(False)
|
|
48
|
+
self.text.edit_modified(False)
|
|
56
49
|
|
|
57
50
|
def on_change_font(value):
|
|
58
51
|
def wrapper(event=None):
|
|
59
52
|
font = self.font
|
|
60
53
|
size = boundary(font.cget('size') + value, 1, 127)
|
|
61
54
|
font.config(size=size)
|
|
55
|
+
update_tab_size()
|
|
62
56
|
self.set_configuration('gui-size-font', size)
|
|
63
57
|
return 'break'
|
|
64
58
|
return wrapper
|
|
65
59
|
|
|
66
60
|
def on_toggle_wrap(event=None):
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
text = self.text
|
|
62
|
+
wrap = text.cget('wrap') != 'char'
|
|
63
|
+
text.configure(wrap='char' if wrap else 'none')
|
|
69
64
|
self.set_configuration('wrap', wrap)
|
|
70
65
|
return 'break'
|
|
71
66
|
|
|
@@ -83,8 +78,12 @@ try:
|
|
|
83
78
|
|
|
84
79
|
def on_enter(event=None):
|
|
85
80
|
text = self.text
|
|
81
|
+
if text.tag_ranges('sel'):
|
|
82
|
+
text.delete('sel.first', 'sel.last')
|
|
83
|
+
|
|
86
84
|
line = text.get('insert linestart', 'insert lineend')
|
|
87
85
|
text.insert('insert', '\n' + line[:len(line) - len(line.lstrip())])
|
|
86
|
+
text.see('insert')
|
|
88
87
|
return 'break'
|
|
89
88
|
|
|
90
89
|
self.lexer = PygmentsPyScriptLexer()
|
|
@@ -102,6 +101,8 @@ try:
|
|
|
102
101
|
yscrollcommand=self.scrollbar.set
|
|
103
102
|
)
|
|
104
103
|
|
|
104
|
+
update_tab_size()
|
|
105
|
+
|
|
105
106
|
self.scrollbar.pack_configure(side='right', fill='y')
|
|
106
107
|
self.scrollbar.configure(command=self.text.yview)
|
|
107
108
|
|
|
@@ -140,10 +141,10 @@ try:
|
|
|
140
141
|
)
|
|
141
142
|
)
|
|
142
143
|
|
|
143
|
-
self.wm_minsize(
|
|
144
|
+
self.wm_minsize(250, 200)
|
|
144
145
|
self.wm_protocol('WM_DELETE_WINDOW', on_close)
|
|
145
146
|
|
|
146
|
-
if colored:
|
|
147
|
+
if PYGMENTS and colored:
|
|
147
148
|
tag_configure = self.text.tag_configure
|
|
148
149
|
for token, style in PygmentsPyScriptStyle.list_styles():
|
|
149
150
|
color = style['color']
|
pyscript/core/editor/terminal.py
CHANGED
|
@@ -22,8 +22,6 @@ try:
|
|
|
22
22
|
def __init__(self, file: PysFileBuffer, colored: bool = True) -> None:
|
|
23
23
|
PysEditor.__init__(self, file, colored)
|
|
24
24
|
|
|
25
|
-
self.load_configuration()
|
|
26
|
-
|
|
27
25
|
self.show_exit_window = False
|
|
28
26
|
|
|
29
27
|
on_edit = Condition(lambda: not self.show_exit_window)
|
|
@@ -47,6 +45,9 @@ try:
|
|
|
47
45
|
'style': style_from_pygments_cls(PygmentsPyScriptStyle)
|
|
48
46
|
})
|
|
49
47
|
|
|
48
|
+
text_other_keyword.update({
|
|
49
|
+
'scrollbar': True
|
|
50
|
+
})
|
|
50
51
|
close_window_keyword.update({
|
|
51
52
|
'content': FormattedTextControl(
|
|
52
53
|
" File has been modified. Save before exit? \n"
|
|
@@ -86,7 +87,6 @@ try:
|
|
|
86
87
|
|
|
87
88
|
self.text = TextArea(
|
|
88
89
|
multiline=True,
|
|
89
|
-
scrollbar=True,
|
|
90
90
|
wrap_lines=on_wrap,
|
|
91
91
|
input_processors=[TabsProcessor(tabstop=4)],
|
|
92
92
|
**text_other_keyword
|
pyscript/core/exceptions.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
from .bases import Pys
|
|
2
2
|
from .constants import NO_COLOR
|
|
3
|
-
from .utils.decorators import immutable
|
|
4
|
-
from .utils.generic import setimuattr
|
|
5
3
|
from .utils.string import indent
|
|
6
4
|
|
|
7
5
|
from typing import TYPE_CHECKING, Optional
|
|
@@ -12,7 +10,6 @@ if TYPE_CHECKING:
|
|
|
12
10
|
from .position import PysPosition
|
|
13
11
|
from .results import PysRunTimeResult
|
|
14
12
|
|
|
15
|
-
@immutable
|
|
16
13
|
class PysTraceback(Pys):
|
|
17
14
|
|
|
18
15
|
__slots__ = ('exception', 'context', 'position', 'primary', 'implicit')
|
|
@@ -26,25 +23,23 @@ class PysTraceback(Pys):
|
|
|
26
23
|
implicit: bool = False
|
|
27
24
|
) -> None:
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
self.exception = exception
|
|
27
|
+
self.context = context
|
|
28
|
+
self.position = position
|
|
29
|
+
self.primary = primary
|
|
30
|
+
self.implicit = implicit
|
|
34
31
|
|
|
35
32
|
def __repr__(self) -> str:
|
|
36
33
|
return f'<traceback of {self.exception!r}>'
|
|
37
34
|
|
|
38
35
|
def string_traceback(self) -> str:
|
|
39
|
-
# circular import problem solved
|
|
40
|
-
from .mapping import GET_ACOLOR
|
|
41
|
-
from .position import format_error_arrow
|
|
42
|
-
|
|
43
36
|
context = self.context
|
|
44
37
|
position = self.position
|
|
45
38
|
colored = not (context.flags & NO_COLOR)
|
|
46
39
|
|
|
47
40
|
if colored:
|
|
41
|
+
# circular import problem solved
|
|
42
|
+
from .mapping import GET_ACOLOR
|
|
48
43
|
reset = GET_ACOLOR('reset')
|
|
49
44
|
magenta = GET_ACOLOR('magenta')
|
|
50
45
|
bmagenta = GET_ACOLOR('bold-magenta')
|
|
@@ -63,7 +58,7 @@ class PysTraceback(Pys):
|
|
|
63
58
|
f' File {magenta}"{position.file.name}"{reset}' +
|
|
64
59
|
('' if is_positionless else f', line {magenta}{position.start_line}{reset}') +
|
|
65
60
|
('' if context_name is None else f', in {magenta}{context_name}{reset}') +
|
|
66
|
-
('' if is_positionless else f'\n{indent(format_error_arrow(
|
|
61
|
+
('' if is_positionless else f'\n{indent(position.format_error_arrow(colored), 4)}')
|
|
67
62
|
)
|
|
68
63
|
|
|
69
64
|
position = context.parent_entry_position
|