dekshell 0.1.97__py3-none-any.whl → 0.1.99__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.
- dekshell/click/__init__.py +1 -2
- dekshell/core/__init__.py +1 -1
- dekshell/core/contexts/methods.py +17 -1
- dekshell/core/markers/base/__init__.py +15 -11
- dekshell/core/markers/base/core.py +32 -10
- dekshell/core/markers/function.py +2 -2
- {dekshell-0.1.97.dist-info → dekshell-0.1.99.dist-info}/METADATA +1 -1
- {dekshell-0.1.97.dist-info → dekshell-0.1.99.dist-info}/RECORD +10 -10
- {dekshell-0.1.97.dist-info → dekshell-0.1.99.dist-info}/WHEEL +0 -0
- {dekshell-0.1.97.dist-info → dekshell-0.1.99.dist-info}/entry_points.txt +0 -0
dekshell/click/__init__.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import sys
|
|
3
2
|
import typer
|
|
4
3
|
from dektools.file import normal_path
|
|
5
4
|
from dektools.output import pprint
|
|
6
|
-
from dektools.
|
|
5
|
+
from dektools.escape import str_escaped
|
|
7
6
|
from dektools.shell import associate_console_script, get_current_sys_exe
|
|
8
7
|
from dektools.typer import command_mixin, command_version
|
|
9
8
|
from dektools.plugin import iter_plugins
|
dekshell/core/__init__.py
CHANGED
|
@@ -8,7 +8,7 @@ from dektools.time import get_tz
|
|
|
8
8
|
from dektools.format import format_duration
|
|
9
9
|
from dektools.shell import shell_command, shell_wrapper
|
|
10
10
|
from dektools.file import normal_path
|
|
11
|
-
from dektools.
|
|
11
|
+
from dektools.escape import str_escape_wrap
|
|
12
12
|
from .contexts import get_all_context
|
|
13
13
|
from .markers import generate_markers, CommentConfigMarker
|
|
14
14
|
from .markers.base.core import MarkerBase, MarkerSet
|
|
@@ -17,6 +17,7 @@ from dektools.download import download_from_http
|
|
|
17
17
|
from dektools.time import now
|
|
18
18
|
from dektools.str import shlex_split, shlex_quote
|
|
19
19
|
from ...utils.beep import sound_notify
|
|
20
|
+
from ..markers.base.core import MarkerBase, get_inner_vars
|
|
20
21
|
from ..markers.invoke import InvokeMarker, GotoMarker
|
|
21
22
|
from ..redirect import search_bin_by_path_tree
|
|
22
23
|
|
|
@@ -87,6 +88,20 @@ def _remove_path(path):
|
|
|
87
88
|
_remove_path(item)
|
|
88
89
|
|
|
89
90
|
|
|
91
|
+
_xeval_default = object()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _xeval(expression, default=_xeval_default, translate=False):
|
|
95
|
+
context = get_inner_vars('__inner_context__', full=True)
|
|
96
|
+
try:
|
|
97
|
+
return MarkerBase.eval_mixin(context, expression, translate)
|
|
98
|
+
except NameError:
|
|
99
|
+
if default is _xeval_default:
|
|
100
|
+
raise
|
|
101
|
+
else:
|
|
102
|
+
return default
|
|
103
|
+
|
|
104
|
+
|
|
90
105
|
path_common_methods = {
|
|
91
106
|
'cd': os.chdir,
|
|
92
107
|
'cwd': lambda: os.getcwd(),
|
|
@@ -98,11 +113,12 @@ path_common_methods = {
|
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
default_methods = {
|
|
116
|
+
'xeval': _xeval,
|
|
101
117
|
'echo': lambda *x, **y: print(*x, **dict(flush=True) | y),
|
|
102
118
|
'echos': lambda *x, **y: print(*x, **dict(end='', flush=True) | y),
|
|
103
119
|
'echox': lambda *x, **y: print(*x, **dict(file=sys.stderr, flush=True) | y),
|
|
104
120
|
'pprint': pprint,
|
|
105
|
-
'
|
|
121
|
+
'o2s': obj2str,
|
|
106
122
|
'now': now,
|
|
107
123
|
'getpass': getpass.getpass,
|
|
108
124
|
'Path': Path,
|
|
@@ -123,6 +123,13 @@ class MarkerBase:
|
|
|
123
123
|
func = cls.eval(context, func)
|
|
124
124
|
return func(*args, **kwargs)
|
|
125
125
|
|
|
126
|
+
@classmethod
|
|
127
|
+
def translate_case(cls, context, s, case=None):
|
|
128
|
+
if case is None:
|
|
129
|
+
return cls.translate(context, s)
|
|
130
|
+
else:
|
|
131
|
+
return cls._translate(context, s) if case else s
|
|
132
|
+
|
|
126
133
|
@classmethod
|
|
127
134
|
def translate(cls, context, s):
|
|
128
135
|
return cls._translate(context, s)
|
|
@@ -221,10 +228,10 @@ class MarkerBase:
|
|
|
221
228
|
|
|
222
229
|
@classmethod
|
|
223
230
|
def eval_mixin(cls, context, expression, translate=True):
|
|
231
|
+
__inner_context__ = context # noqa
|
|
224
232
|
expression = expression.lstrip()
|
|
225
233
|
if expression.startswith(cmd_call_prefix_chain):
|
|
226
|
-
|
|
227
|
-
expression = cls._translate(context, expression)
|
|
234
|
+
expression = cls.translate_case(context, expression, translate)
|
|
228
235
|
expression = expression[len(cmd_call_prefix_chain):]
|
|
229
236
|
index = re.search(
|
|
230
237
|
r"%s|%s" % (re.escape(cmd_call_prefix_simple), re.escape(cmd_call_eval_prefix)), expression).span()[0]
|
|
@@ -235,12 +242,10 @@ class MarkerBase:
|
|
|
235
242
|
value = cls.eval(context, func)(value)
|
|
236
243
|
return value
|
|
237
244
|
elif expression.startswith(cmd_call_prefix):
|
|
238
|
-
|
|
239
|
-
expression = cls._translate(context, expression)
|
|
245
|
+
expression = cls.translate_case(context, expression, translate)
|
|
240
246
|
return cls.cmd_call(context, expression[len(cmd_call_prefix):], False)
|
|
241
247
|
elif expression.startswith(cmd_call_prefix_simple):
|
|
242
|
-
|
|
243
|
-
expression = cls._translate(context, expression)
|
|
248
|
+
expression = cls.translate_case(context, expression, translate)
|
|
244
249
|
return cls.cmd_call(context, expression[len(cmd_call_prefix_simple):], True)
|
|
245
250
|
else:
|
|
246
251
|
if expression.startswith(cmd_call_eval_prefix):
|
|
@@ -328,10 +333,7 @@ class MarkerWithEnd(MarkerBase):
|
|
|
328
333
|
commands = []
|
|
329
334
|
marker_node.walk(lambda node, depth: commands.extend([] if depth == 0 else [node.command]))
|
|
330
335
|
text = sep.join(commands)
|
|
331
|
-
|
|
332
|
-
return self.translate(context, text)
|
|
333
|
-
else:
|
|
334
|
-
return self._translate(context, text) if translate else text
|
|
336
|
+
return self.translate_case(context, text, translate)
|
|
335
337
|
|
|
336
338
|
def eval_codes(self, context, code):
|
|
337
339
|
if not code:
|
|
@@ -360,7 +362,9 @@ class MarkerWithEnd(MarkerBase):
|
|
|
360
362
|
|
|
361
363
|
|
|
362
364
|
class MarkerNoTranslator(MarkerBase):
|
|
363
|
-
|
|
365
|
+
|
|
366
|
+
@classmethod
|
|
367
|
+
def translate(cls, context, s):
|
|
364
368
|
return s
|
|
365
369
|
|
|
366
370
|
|
|
@@ -7,16 +7,37 @@ from dektools.dict import MapChainContext
|
|
|
7
7
|
from . import MarkerBase, TransformerMarker, ExitException, QuitContextException
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def get_inner_vars(*var_name_list):
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
def get_inner_vars(*var_name_list, full=False):
|
|
11
|
+
def walk(attr):
|
|
12
|
+
depth = 1
|
|
13
|
+
while True:
|
|
14
|
+
try:
|
|
15
|
+
frame = sys._getframe(depth)
|
|
16
|
+
except ValueError:
|
|
17
|
+
return
|
|
18
|
+
scope = getattr(frame, attr)
|
|
19
|
+
for i, name in enumerate(var_name_list):
|
|
20
|
+
if result[i] is unset:
|
|
21
|
+
if name in scope:
|
|
22
|
+
result[i] = scope[name]
|
|
23
|
+
if not list_unset():
|
|
24
|
+
break
|
|
25
|
+
depth += 1
|
|
26
|
+
|
|
27
|
+
def list_unset():
|
|
28
|
+
return [var_name_list[i] for i, x in enumerate(result) if x is unset]
|
|
29
|
+
|
|
30
|
+
unset = object()
|
|
31
|
+
result = [unset] * len(var_name_list)
|
|
32
|
+
walk('f_globals')
|
|
33
|
+
if full and list_unset():
|
|
34
|
+
walk('f_locals')
|
|
35
|
+
lu = list_unset()
|
|
36
|
+
if lu:
|
|
37
|
+
raise ValueError(f"Can't find: {lu}")
|
|
38
|
+
if len(result) == 1:
|
|
39
|
+
return result[0]
|
|
40
|
+
return tuple(result)
|
|
20
41
|
|
|
21
42
|
|
|
22
43
|
class MarkerContext:
|
|
@@ -154,6 +175,7 @@ class MarkerNode:
|
|
|
154
175
|
|
|
155
176
|
@classmethod
|
|
156
177
|
def execute_nodes(cls, context, marker_set, nodes):
|
|
178
|
+
__inner_marker_set__ = marker_set # noqa
|
|
157
179
|
while nodes:
|
|
158
180
|
node = nodes.pop(0)
|
|
159
181
|
result = node.bubble_continue(context, marker_set, node)
|
|
@@ -12,10 +12,10 @@ class CallMarker(MarkerNoTranslator):
|
|
|
12
12
|
|
|
13
13
|
def execute_core(self, context, expression):
|
|
14
14
|
if expression.startswith(cmd_call_prefix):
|
|
15
|
-
expression = self.
|
|
15
|
+
expression = self.translate_case(context, expression, True)
|
|
16
16
|
name, args, kwargs = self.cmd_call_parse(context, expression[len(cmd_call_prefix):], False)
|
|
17
17
|
elif expression.startswith(cmd_call_prefix_simple):
|
|
18
|
-
expression = self.
|
|
18
|
+
expression = self.translate_case(context, expression, True)
|
|
19
19
|
name, args, kwargs = self.cmd_call_parse(context, expression[len(cmd_call_prefix_simple):], True)
|
|
20
20
|
else:
|
|
21
21
|
name = expression[:expression.find('(')]
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
dekshell-0.1.
|
|
2
|
-
dekshell-0.1.
|
|
3
|
-
dekshell-0.1.
|
|
1
|
+
dekshell-0.1.99.dist-info/METADATA,sha256=kR4kKG9cp430mZvPzV9siPtyhzs-gSw8QXR6ftrq8r0,521
|
|
2
|
+
dekshell-0.1.99.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
|
|
3
|
+
dekshell-0.1.99.dist-info/entry_points.txt,sha256=d-kbfULiUTZWIBBsrQF3J_-wESncF-4K2rwHT08grlI,75
|
|
4
4
|
dekshell/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
dekshell/click/__entry__.py,sha256=CMuxUzXoEe4TcHFZwv-MNFwHnu1HSZCDpXFpqQ814uM,42
|
|
6
|
-
dekshell/click/__init__.py,sha256=
|
|
7
|
-
dekshell/core/__init__.py,sha256=
|
|
6
|
+
dekshell/click/__init__.py,sha256=rFzB_exzPQaIcbbms5PdHAU3NGdl2MBaYbq9v7g7BOI,1870
|
|
7
|
+
dekshell/core/__init__.py,sha256=Cp--1j2jpJzchXR98HiRp2QAiOHz8HXm8iy6ZChIWmc,5207
|
|
8
8
|
dekshell/core/contexts/__init__.py,sha256=ynsfv37azOKfI2UKd0iPl2M6iBW-k5cb1BqSLOWuJpI,482
|
|
9
|
-
dekshell/core/contexts/methods.py,sha256=
|
|
9
|
+
dekshell/core/contexts/methods.py,sha256=SXuLpAjVv272TZE2_Dwmf7hX4fvS9MSHpaIEsTHPTok,5494
|
|
10
10
|
dekshell/core/contexts/properties.py,sha256=aLHtyUWedbFPQw33V5vQZTc4TeLMTC-AO6e7PhBZKbk,1570
|
|
11
11
|
dekshell/core/markers/__init__.py,sha256=bmGMbZRqsOohMKjH0AReFxZ-nIPFF6YgPJMFT6gTJEw,1725
|
|
12
|
-
dekshell/core/markers/base/__init__.py,sha256=
|
|
13
|
-
dekshell/core/markers/base/core.py,sha256=
|
|
12
|
+
dekshell/core/markers/base/__init__.py,sha256=AQYr7H0F06izu5jhu8EgLYJ2ERzJh0eS38h9gtl6OZs,13067
|
|
13
|
+
dekshell/core/markers/base/core.py,sha256=99aRcSXohpfTW5OSO1CUyvnptr21ueKjizCk-FK6rcM,10830
|
|
14
14
|
dekshell/core/markers/comment.py,sha256=28iccgLs_0bRdXLhHyQR2I_kzlWdeMSqqNUFW-2vkes,818
|
|
15
15
|
dekshell/core/markers/define.py,sha256=LpMSfz9ziXq2aFJ6oMpUFFo93TpBx7GxKYNzCeht4fQ,516
|
|
16
16
|
dekshell/core/markers/echo.py,sha256=1H61qQbY9tZnrKsdTI_shTmDY5ZaSGipDuBSRptAuZw,660
|
|
@@ -18,7 +18,7 @@ dekshell/core/markers/empty.py,sha256=xMYoZIxn7Tt1RjFtLhJERisra8jqsGjJ0G7OID0oD3
|
|
|
18
18
|
dekshell/core/markers/env.py,sha256=6ZtiMNdKFbGR_DBjG6C7A8L_lJsiymN5Y5AbnTzyMrE,1158
|
|
19
19
|
dekshell/core/markers/exec.py,sha256=zT3mI7bBSgOpBICCjeb-vhAWbra9i8rABuUAVNnuMns,2032
|
|
20
20
|
dekshell/core/markers/for_.py,sha256=uNOEwyDsjffttEBtUYasdlj7FP_sGnQzWuTV5d5esHY,2142
|
|
21
|
-
dekshell/core/markers/function.py,sha256=
|
|
21
|
+
dekshell/core/markers/function.py,sha256=RPh56_rYbWXCTkNPiJu8zNEj-OE6txKgEw7Im9fBM3c,3592
|
|
22
22
|
dekshell/core/markers/if_.py,sha256=bBG1fDCZd5alE5FSm0QhgHl6ZJn5awiqZAXnPnO-thc,1112
|
|
23
23
|
dekshell/core/markers/input.py,sha256=HpqE1_PxrmeAVbWxACu0O7SeBVQpBw-aAmNIX5uWWYs,659
|
|
24
24
|
dekshell/core/markers/invoke.py,sha256=sXXg0p8Dyg4HQwnWFzWgcyhZYGWvNfhDgUumrrUoWkM,1431
|
|
@@ -36,4 +36,4 @@ dekshell/utils/cmd.py,sha256=_WG7K-CO-WQkI9ERyrhI2d4yT-DX3OjjJWbNzhmsPus,1197
|
|
|
36
36
|
dekshell/utils/pkg.py,sha256=TgYqRqawoJfjkxt6UAHnp9ttmpjuHiWRFbqxADOS1VE,1337
|
|
37
37
|
dekshell/utils/serializer.py,sha256=aIdF2Wzo-qHmIshv46jn1XD0X66vQ1JFdU-g3ZFbH2w,386
|
|
38
38
|
dekshell/utils/shell.py,sha256=0NoA2-SOOMinbmZZipwzL-npBbzPOdWEfdPVYqq5G5g,92
|
|
39
|
-
dekshell-0.1.
|
|
39
|
+
dekshell-0.1.99.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|