dekshell 0.2.19__tar.gz → 0.2.21__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 (40) hide show
  1. {dekshell-0.2.19 → dekshell-0.2.21}/PKG-INFO +1 -1
  2. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/contexts/methods.py +3 -2
  3. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/__init__.py +1 -1
  4. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/base/__init__.py +1 -0
  5. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/base/core.py +27 -2
  6. dekshell-0.2.19/dekshell/core/markers/empty.py → dekshell-0.2.21/dekshell/core/markers/base/shell.py +3 -14
  7. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/commands.py +25 -0
  8. dekshell-0.2.21/dekshell/core/markers/empty.py +5 -0
  9. dekshell-0.2.21/dekshell/core/markers/redirect.py +45 -0
  10. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/shell.py +2 -1
  11. {dekshell-0.2.19 → dekshell-0.2.21}/pyproject.toml +1 -1
  12. dekshell-0.2.19/dekshell/core/markers/redirect.py +0 -43
  13. {dekshell-0.2.19 → dekshell-0.2.21}/README.md +0 -0
  14. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/__init__.py +0 -0
  15. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/click/__entry__.py +0 -0
  16. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/click/__init__.py +0 -0
  17. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/__init__.py +0 -0
  18. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/contexts/__init__.py +0 -0
  19. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/contexts/properties.py +0 -0
  20. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/comment.py +0 -0
  21. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/define.py +0 -0
  22. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/echo.py +0 -0
  23. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/env.py +0 -0
  24. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/exec.py +0 -0
  25. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/for_.py +0 -0
  26. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/function.py +0 -0
  27. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/if_.py +0 -0
  28. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/input.py +0 -0
  29. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/invoke.py +0 -0
  30. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/pip_.py +0 -0
  31. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/var.py +0 -0
  32. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/markers/while_.py +0 -0
  33. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/plugin/__init__.py +0 -0
  34. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/core/redirect.py +0 -0
  35. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/utils/__init__.py +0 -0
  36. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/utils/beep.py +0 -0
  37. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/utils/cmd.py +0 -0
  38. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/utils/pkg.py +0 -0
  39. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/utils/serializer.py +0 -0
  40. {dekshell-0.2.19 → dekshell-0.2.21}/dekshell/utils/shell.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dekshell
3
- Version: 0.2.19
3
+ Version: 0.2.21
4
4
  Author-Email: sanzenwin <sanzenwin@gmail.com>
5
5
  License: MIT
6
6
  Requires-Python: >=3.8
@@ -11,7 +11,7 @@ from pathlib import Path
11
11
  from io import BytesIO, StringIO
12
12
  from dektools.file import sure_dir, write_file, read_text, remove_path, sure_parent_dir, normal_path, \
13
13
  format_path_desc, read_file, split_ext, path_ext, clear_dir, copy_recurse_ignore, path_is_empty, \
14
- read_lines, seek_py_module_path, come_real_path, status_of_dir, diff_of_dir,\
14
+ read_lines, seek_py_module_path, come_real_path, status_of_dir, diff_of_dir, \
15
15
  split_file, combine_split_files, remove_split_files, meta_split_file, tree, iglob, \
16
16
  where, where_list, which, which_list
17
17
  from dektools.hash import hash_file
@@ -19,7 +19,7 @@ from dektools.zip import compress_files, decompress_files
19
19
  from dektools.output import pprint, obj2str
20
20
  from dektools.net import get_available_port
21
21
  from dektools.func import FuncAnyArgs
22
- from dektools.fetch import download_file
22
+ from dektools.fetch import download_file, download_content
23
23
  from dektools.download import download_from_http
24
24
  from dektools.ps.process import process_detail, process_kill, process_list_all
25
25
  from dektools.time import now
@@ -320,6 +320,7 @@ default_methods = {
320
320
  'port': get_available_port,
321
321
  'fetch': download_file,
322
322
  'download': download_from_http,
323
+ 'content': download_content,
323
324
  },
324
325
 
325
326
  'git': {
@@ -44,7 +44,7 @@ def generate_markers(*args, **kwargs):
44
44
  RedirectMarker, ShiftMarker,
45
45
  TimeoutMarker, RetryMarker,
46
46
  IgnoreMarker,
47
- PrefixShellMarker,
47
+ IgnoreErrorShellMarker, PrefixShellMarker,
48
48
  AssignCallMarker, AssignInvokerMarker, AssignGotoMarker, AssignTimeoutMarker, AssignRetryMarker,
49
49
  AssignExecMarker, AssignEvalMarker, AssignCmdcallMarker, AssignCmdcallChainMarker,
50
50
  AssignMultiLineRawStrMarker, AssignMultiLineStrMarker, AssignRawStrMarker, AssignStrMarker,
@@ -20,6 +20,7 @@ class MarkerBase:
20
20
  tag_head_re = None
21
21
  tag_head_re_args = None
22
22
  tag_tail = None
23
+ stack_check = True
23
24
  branch_set = set()
24
25
 
25
26
  var_name_anonymous = '_'
@@ -140,7 +140,7 @@ class MarkerNode:
140
140
  self.payload = payload
141
141
 
142
142
  def __repr__(self):
143
- return f'Node({self.marker.__class__.__name__})'
143
+ return f'Node({self.marker.__class__.__name__},line={self.line_number})'
144
144
 
145
145
  @property
146
146
  def debug_info(self):
@@ -154,6 +154,18 @@ class MarkerNode:
154
154
 
155
155
  return obj2str(walk(self))
156
156
 
157
+ @property
158
+ def ignore_stack_check(self):
159
+ def walk(node):
160
+ if not node.marker.stack_check:
161
+ return node
162
+ for child in node.children:
163
+ r = walk(child)
164
+ if r:
165
+ return r
166
+
167
+ return walk(self)
168
+
157
169
  def is_type(self, *markers_cls):
158
170
  return isinstance(self.marker, markers_cls)
159
171
 
@@ -282,6 +294,12 @@ class MarkerSet:
282
294
  self.markers = self.transformer_cls.inject(markers)
283
295
  self.shell_exec = shell_exec
284
296
  self.shell_cmd = shell_cmd
297
+ self.stack_errors = {}
298
+
299
+ def check_stack_error(self, node):
300
+ error = self.stack_errors.get(node.index)
301
+ if error:
302
+ raise error
285
303
 
286
304
  def is_marker_branch(self, marker):
287
305
  return marker.__class__ in self.markers_branch_set
@@ -318,7 +336,14 @@ class MarkerSet:
318
336
  if marker.tag_tail is not None: # block command
319
337
  stack.append(node)
320
338
  if len(stack) != 1:
321
- raise ValueError(f'Stack should have just a root node in final: {stack}')
339
+ node = stack[0].ignore_stack_check
340
+ error = ValueError(
341
+ f'Stack should have just one root node in final, your scripts contains syntax errors: {stack}')
342
+ if node:
343
+ print(error)
344
+ self.stack_errors[node.index] = error
345
+ else:
346
+ raise error
322
347
  return stack[0]
323
348
 
324
349
  def execute(self, commands, context, ln=None):
@@ -1,8 +1,10 @@
1
1
  from dektools.shell import shell_command
2
- from .base import MarkerShellBase
2
+ from . import MarkerShellBase
3
3
 
4
4
 
5
5
  class ShellCommand:
6
+ shell_call = shell_command
7
+
6
8
  def __init__(self, kwargs):
7
9
  self.kwargs = kwargs
8
10
 
@@ -17,16 +19,3 @@ class ShellCommand:
17
19
  class MarkerShell(MarkerShellBase):
18
20
  tag_head = ""
19
21
  shell_cls = ShellCommand
20
-
21
-
22
- class PrefixShellMarker(MarkerShell):
23
- tag_head = "@"
24
-
25
- def execute(self, context, command, marker_node, marker_set):
26
- _, command = self.split_raw(command, 1, self.tag_head)
27
- if command:
28
- self.execute_core(context, command, marker_node, marker_set)
29
-
30
-
31
- class EmptyMarker(MarkerShell):
32
- pass
@@ -1,7 +1,32 @@
1
+ import subprocess
2
+ from dektools.shell import shell_wrapper
1
3
  from .base import MarkerWithEnd
4
+ from .base.shell import MarkerShell, ShellCommand
2
5
  from .empty import EmptyMarker
3
6
 
4
7
 
8
+ class PrefixShellMarker(MarkerShell):
9
+ tag_head = "@"
10
+
11
+ def execute(self, context, command, marker_node, marker_set):
12
+ _, command = self.split_raw(command, 1, self.tag_head)
13
+ if command:
14
+ self.execute_core(context, command, marker_node, marker_set)
15
+
16
+
17
+ class IgnoreErrorShellCommand(ShellCommand):
18
+ def shell(self, *args, **kwargs):
19
+ try:
20
+ shell_wrapper(*args, **kwargs)
21
+ except subprocess.SubprocessError:
22
+ return None
23
+
24
+
25
+ class IgnoreErrorShellMarker(PrefixShellMarker):
26
+ tag_head = "!"
27
+ shell_cls = IgnoreErrorShellCommand
28
+
29
+
5
30
  class CommandsMarker(MarkerWithEnd):
6
31
  tag_head = "@@"
7
32
  target_marker_cls = EmptyMarker
@@ -0,0 +1,5 @@
1
+ from .base.shell import MarkerShell
2
+
3
+
4
+ class EmptyMarker(MarkerShell):
5
+ pass
@@ -0,0 +1,45 @@
1
+ import os
2
+ from dektools.shell import shell_wrapper
3
+ from dektools.attr import DeepObject
4
+ from ...core.redirect import redirect_shell_by_path_tree
5
+ from ...utils.cmd import ak2cmd, key_args, key_kwargs
6
+ from ..contexts.properties import make_shell_properties, current_shell
7
+ from .base import MarkerBase
8
+
9
+
10
+ class MarkerRedirect(MarkerBase):
11
+ def execute(self, context, command, marker_node, marker_set):
12
+ filepath = self.split_raw(command, 1, self.tag_head)[1]
13
+ if not filepath:
14
+ filepath = self.eval(context, 'fp')
15
+ path_shell = redirect_shell_by_path_tree(filepath)
16
+ self.execute_core(context, marker_node, marker_set, path_shell)
17
+
18
+ def execute_core(self, context, marker_node, marker_set, path_shell):
19
+ raise NotImplementedError
20
+
21
+
22
+ class RedirectMarker(MarkerRedirect):
23
+ tag_head = "redirect"
24
+ stack_check = False
25
+
26
+ def execute_core(self, context, marker_node, marker_set, path_shell):
27
+ if path_shell:
28
+ shell_properties = make_shell_properties(path_shell)
29
+ if shell_properties['shell'] != current_shell:
30
+ fp = self.eval(context, "fp")
31
+ fpp = os.path.dirname(fp).replace('/', os.sep)
32
+ shell = shell_properties['sh']['rfc' if os.getcwd() == fpp else 'rf']
33
+ args, kwargs = self.eval(context, f'({key_args}, {key_kwargs})')
34
+ argv = ak2cmd(args, kwargs)
35
+ shell_wrapper(f'{shell} {fp} {argv}', env=context.environ_full())
36
+ return self.exit()
37
+ marker_set.check_stack_error(marker_node)
38
+
39
+
40
+ class ShiftMarker(MarkerRedirect):
41
+ tag_head = "shift"
42
+
43
+ def execute_core(self, context, marker_node, marker_set, path_shell):
44
+ if path_shell:
45
+ context.update_variables(DeepObject(make_shell_properties(path_shell)).__dict__)
@@ -1,6 +1,7 @@
1
1
  import subprocess
2
2
  from dektools.shell import shell_timeout, shell_wrapper, shell_retry
3
- from .empty import MarkerShell, ShellCommand
3
+ from .base.shell import ShellCommand
4
+ from .empty import MarkerShell
4
5
 
5
6
 
6
7
  class TimeoutShellCommand(ShellCommand):
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dekshell"
3
- version = "0.2.19"
3
+ version = "0.2.21"
4
4
  description = ""
5
5
  authors = [
6
6
  { name = "sanzenwin", email = "sanzenwin@gmail.com" },
@@ -1,43 +0,0 @@
1
- import os
2
-
3
- from dektools.shell import shell_wrapper
4
- from dektools.attr import DeepObject
5
- from ...core.redirect import redirect_shell_by_path_tree
6
- from ...utils.cmd import ak2cmd, key_args, key_kwargs
7
- from ..contexts.properties import make_shell_properties, current_shell
8
- from .base import MarkerBase
9
-
10
-
11
- class MarkerRedirect(MarkerBase):
12
- def execute(self, context, command, marker_node, marker_set):
13
- filepath = self.split_raw(command, 1, self.tag_head)[1]
14
- if not filepath:
15
- filepath = self.eval(context, 'fp')
16
- path_shell = redirect_shell_by_path_tree(filepath)
17
- if path_shell:
18
- self.execute_core(context, path_shell)
19
-
20
- def execute_core(self, context, path_shell):
21
- raise NotImplementedError
22
-
23
-
24
- class RedirectMarker(MarkerRedirect):
25
- tag_head = "redirect"
26
-
27
- def execute_core(self, context, path_shell):
28
- shell_properties = make_shell_properties(path_shell)
29
- if shell_properties['shell'] != current_shell:
30
- fp = self.eval(context, "fp")
31
- fpp = os.path.dirname(fp).replace('/', os.sep)
32
- shell = shell_properties['sh']['rfc' if os.getcwd() == fpp else 'rf']
33
- args, kwargs = self.eval(context, f'({key_args}, {key_kwargs})')
34
- argv = ak2cmd(args, kwargs)
35
- shell_wrapper(f'{shell} {fp} {argv}', env=context.environ_full())
36
- self.exit()
37
-
38
-
39
- class ShiftMarker(MarkerRedirect):
40
- tag_head = "shift"
41
-
42
- def execute_core(self, context, path_shell):
43
- context.update_variables(DeepObject(make_shell_properties(path_shell)).__dict__)
File without changes