meerschaum 2.4.12__py3-none-any.whl → 2.4.13__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.
@@ -43,6 +43,7 @@ if (_STATIC_CONFIG['environment']['systemd_log_path']) in os.environ:
43
43
  if _systemd_stdin_path:
44
44
  sys.stdin = _StdinFile(_systemd_stdin_path)
45
45
 
46
+
46
47
  def entry(
47
48
  sysargs: Optional[List[str]] = None,
48
49
  _patch_args: Optional[Dict[str, Any]] = None,
@@ -19,7 +19,7 @@ def bootstrap(
19
19
  ) -> SuccessTuple:
20
20
  """
21
21
  Launch an interactive wizard to bootstrap pipes or connectors.
22
-
22
+
23
23
  Example:
24
24
  `bootstrap pipes`
25
25
 
@@ -462,7 +462,6 @@ def _bootstrap_jobs(
462
462
  if not action:
463
463
  action = [prompt("What is the name of the job you'd like to create?")]
464
464
 
465
- new_jobs = {}
466
465
  for name in action:
467
466
  clear_screen(debug=debug)
468
467
  job = mrsm.Job(name, executor_keys=executor_keys)
@@ -473,13 +472,14 @@ def _bootstrap_jobs(
473
472
  continue
474
473
 
475
474
  info(
476
- "Press [Esc + Enter] to submit, [CTRL + C] to exit.\n"
475
+ f"Editing arguments for job '{name}'.\n"
476
+ " Press [Esc + Enter] to submit, [CTRL + C] to exit.\n\n"
477
477
  " Tip: join multiple actions with `+`, add pipeline arguments with `:`.\n"
478
478
  " https://meerschaum.io/reference/actions/#chaining-actions\n"
479
479
  )
480
480
  try:
481
481
  new_sysargs_str = prompt(
482
- f"Arguments for job '{name}':",
482
+ "",
483
483
  multiline=True,
484
484
  icon=False,
485
485
  completer=ShellCompleter(),
@@ -491,6 +491,7 @@ def _bootstrap_jobs(
491
491
  new_sysargs, pipeline_args = split_pipeline_sysargs(new_sysargs)
492
492
  chained_sysargs = split_chained_sysargs(new_sysargs)
493
493
 
494
+ clear_screen(debug=debug)
494
495
  if len(chained_sysargs) > 1:
495
496
  print_options(
496
497
  [
@@ -508,6 +509,7 @@ def _bootstrap_jobs(
508
509
  if pipeline_args:
509
510
  print('\n' + make_header("Pipeline Arguments:"))
510
511
  print(shlex.join(pipeline_args))
512
+ print()
511
513
 
512
514
  if not yes_no(
513
515
  (
@@ -524,15 +526,11 @@ def _bootstrap_jobs(
524
526
  if not start_success:
525
527
  return start_success, start_msg
526
528
 
527
- new_jobs[name] = new_job
528
-
529
- if not new_jobs:
530
- return False, "No new jobs were created."
531
-
532
529
  msg = (
533
530
  "Successfully bootstrapped job"
534
- + ('s' if len(new_jobs) != 1 else '')
535
- + items_str(list(new_jobs.keys()))
531
+ + ('s' if len(action) != 1 else '')
532
+ + ' '
533
+ + items_str(action)
536
534
  + '.'
537
535
  )
538
536
  return True, msg
@@ -498,7 +498,7 @@ def _complete_delete_jobs(
498
498
  action: Optional[List[str]] = None,
499
499
  executor_keys: Optional[str] = None,
500
500
  line: str = '',
501
- _get_job_method: Optional[str, List[str]] = None,
501
+ _get_job_method: Union[str, List[str], None] = None,
502
502
  **kw
503
503
  ) -> List[str]:
504
504
  from meerschaum._internal.shell.Shell import shell_attrs
@@ -38,10 +38,17 @@ def _complete_edit(
38
38
  """
39
39
  Override the default Meerschaum `complete_` function.
40
40
  """
41
+ from meerschaum.actions.delete import _complete_delete_jobs
42
+
43
+ if action is None:
44
+ action = []
45
+
41
46
  options = {
42
47
  'config': _complete_edit_config,
43
48
  'plugin': _complete_edit_plugins,
44
49
  'plugins': _complete_edit_plugins,
50
+ 'job': _complete_delete_jobs,
51
+ 'jobs': _complete_delete_jobs,
45
52
  }
46
53
 
47
54
  if action is None:
@@ -133,7 +140,7 @@ def _edit_pipes(
133
140
 
134
141
  pipes = get_pipes(debug=debug, as_list=True, **kw)
135
142
  if pipes:
136
- print_options(pipes, header=f'Pipes to be edited:')
143
+ print_options(pipes, header='Pipes to be edited:')
137
144
  else:
138
145
  return False, "No pipes to edit."
139
146
 
@@ -144,10 +151,10 @@ def _edit_pipes(
144
151
  f"Press [Enter] to begin editing the above {len(pipes)} pipe"
145
152
  + ("s" if len(pipes) != 1 else "")
146
153
  + " or [CTRL-C] to cancel:",
147
- icon = False,
154
+ icon=False,
148
155
  )
149
156
  except KeyboardInterrupt:
150
- return False, f"No pipes changed."
157
+ return False, "No pipes changed."
151
158
 
152
159
  interactive = (not bool(params))
153
160
  success, msg = True, ""
@@ -393,41 +400,51 @@ def _edit_jobs(
393
400
  )
394
401
  from meerschaum.utils.formatting import make_header, print_options
395
402
  from meerschaum.utils.warnings import info
396
- from meerschaum.actions import actions
403
+ from meerschaum._internal.shell.ShellCompleter import ShellCompleter
404
+ from meerschaum.utils.misc import items_str
405
+ from meerschaum.utils.formatting._shell import clear_screen
406
+
397
407
  jobs = get_filtered_jobs(executor_keys, action, debug=debug)
398
408
  if not jobs:
399
409
  return False, "No jobs to edit."
400
410
 
401
- info(
402
- "Press [Esc + Enter] to submit, [CTRL + C] to exit.\n"
403
- " Tip: join multiple actions with `+`, add pipeline arguments with `:`.\n"
404
- " https://meerschaum.io/reference/actions/#chaining-actions\n"
405
- )
406
-
411
+ num_edited = 0
407
412
  for name, job in jobs.items():
408
413
  sysargs_str = shlex.join(job.sysargs)
414
+ clear_screen(debug=debug)
415
+ info(
416
+ f"Editing arguments for job '{name}'.\n"
417
+ " Press [Esc + Enter] to submit, [CTRL + C] to exit.\n\n"
418
+ " Tip: join actions with `+`, manage pipeline with `:`.\n"
419
+ " https://meerschaum.io/reference/actions/#chaining-actions\n"
420
+ )
409
421
 
410
422
  try:
411
423
  new_sysargs_str = prompt(
412
- f"Arguments for job '{name}':",
413
- default_editable=sysargs_str.lstrip().rstrip(),
424
+ "",
425
+ default_editable=sysargs_str.lstrip().rstrip().replace(' + ', '\n+ '),
414
426
  multiline=True,
415
427
  icon=False,
428
+ completer=ShellCompleter(),
416
429
  )
417
430
  except KeyboardInterrupt:
418
431
  return True, "Nothing was changed."
419
432
 
433
+ if new_sysargs_str.strip() == sysargs_str.strip():
434
+ continue
435
+
420
436
  new_sysargs = shlex.split(new_sysargs_str)
421
437
  new_sysargs, pipeline_args = split_pipeline_sysargs(new_sysargs)
422
438
  chained_sysargs = split_chained_sysargs(new_sysargs)
423
439
 
440
+ clear_screen(debug=debug)
424
441
  if len(chained_sysargs) > 1:
425
442
  print_options(
426
443
  [
427
444
  shlex.join(step_sysargs)
428
445
  for step_sysargs in chained_sysargs
429
446
  ],
430
- header=f"Steps in Job '{name}':",
447
+ header=f"\nSteps in Job '{name}':",
431
448
  number_options=True,
432
449
  **kwargs
433
450
  )
@@ -438,6 +455,7 @@ def _edit_jobs(
438
455
  if pipeline_args:
439
456
  print('\n' + make_header("Pipeline Arguments:"))
440
457
  print(shlex.join(pipeline_args))
458
+ print()
441
459
 
442
460
  if not yes_no(
443
461
  (
@@ -457,8 +475,16 @@ def _edit_jobs(
457
475
  start_success, start_msg = new_job.start()
458
476
  if not start_success:
459
477
  return start_success, start_msg
478
+ num_edited += 1
460
479
 
461
- return True, "Success"
480
+ msg = (
481
+ "Successfully edit job"
482
+ + ('s' if len(jobs) != 1 else '')
483
+ + ' '
484
+ + items_str(list(jobs.keys()))
485
+ + '.'
486
+ ) if num_edited > 0 else "Nothing was edited."
487
+ return True, msg
462
488
 
463
489
 
464
490
  ### NOTE: This must be the final statement of the module.
meerschaum/actions/sh.py CHANGED
@@ -9,14 +9,15 @@ NOTE: This action may be a huge security vulnerability
9
9
 
10
10
  from meerschaum.utils.typing import SuccessTuple, List, Any, Optional
11
11
 
12
+
12
13
  def sh(
13
- action: Optional[List[str]] = None,
14
- sub_args: Optional[List[str]] = None,
15
- filtered_sysargs: Optional[List[str]] = None,
16
- use_bash: bool = True,
17
- debug: bool = False,
18
- **kw: Any
19
- ) -> SuccessTuple:
14
+ action: Optional[List[str]] = None,
15
+ sub_args: Optional[List[str]] = None,
16
+ filtered_sysargs: Optional[List[str]] = None,
17
+ use_bash: bool = True,
18
+ debug: bool = False,
19
+ **kw: Any
20
+ ) -> SuccessTuple:
20
21
  """
21
22
  Execute system commands.
22
23
  """
@@ -50,7 +51,7 @@ def sh(
50
51
  if len(action) != 0:
51
52
  try:
52
53
  command_list += ["-c", shlex.join(cmd_list)]
53
- except Exception as e:
54
+ except Exception:
54
55
  command_list += ["-c", ' '.join(cmd_list)]
55
56
  else:
56
57
  if len(action) == 0:
@@ -64,8 +65,8 @@ def sh(
64
65
  try:
65
66
  process = subprocess.Popen(
66
67
  command_list,
67
- shell = False,
68
- env = os.environ,
68
+ shell=False,
69
+ env=os.environ,
69
70
  )
70
71
  exit_code = process.wait()
71
72
  except FileNotFoundError:
@@ -541,6 +541,7 @@ def _start_pipeline(
541
541
  action: Optional[List[str]] = None,
542
542
  loop: bool = False,
543
543
  min_seconds: Union[float, int, None] = 1.0,
544
+ timeout_seconds: Optional[int] = None,
544
545
  params: Optional[Dict[str, Any]] = None,
545
546
  **kwargs
546
547
  ) -> SuccessTuple:
@@ -557,10 +558,39 @@ def _start_pipeline(
557
558
  `show version + show arguments :: --loop`
558
559
 
559
560
  """
561
+ import json
560
562
  import time
563
+ import sys
561
564
  from meerschaum._internal.entry import entry
562
565
  from meerschaum.utils.warnings import info, warn
563
566
  from meerschaum.utils.misc import is_int
567
+ from meerschaum.utils.venv import venv_exec
568
+ from meerschaum.utils.process import poll_process
569
+ fence_begin, fence_end = '<MRSM_RESULT>', '</MRSM_RESULT>'
570
+
571
+ success, msg = False, "Did not run pipeline."
572
+ def write_line(line):
573
+ nonlocal success, msg
574
+ decoded = line.decode('utf-8')
575
+ begin_index, end_index = decoded.find(fence_begin), decoded.find(fence_end)
576
+
577
+ ### Found the beginning of the return value.
578
+ ### Don't write the parsed success tuple message.
579
+ if begin_index >= 0:
580
+ success, msg = tuple(json.loads(
581
+ decoded[begin_index + len(fence_begin):end_index]
582
+ ))
583
+ return
584
+
585
+ print(decoded)
586
+
587
+ def timeout_handler(*args, **kw):
588
+ nonlocal success, msg
589
+ success, msg = False, (
590
+ f"Failed to execute pipeline within {timeout_seconds} second"
591
+ + ('s' if timeout_seconds != 1 else '') + '.'
592
+ )
593
+ write_line((fence_begin + json.dumps((success, msg)) + fence_end).encode('utf-8'))
564
594
 
565
595
  do_n_times = (
566
596
  int(action[0].lstrip('x'))
@@ -578,12 +608,38 @@ def _start_pipeline(
578
608
  if min_seconds is None:
579
609
  min_seconds = 1.0
580
610
 
611
+ def do_entry() -> None:
612
+ nonlocal success, msg
613
+ if timeout_seconds is None:
614
+ success, msg = entry(sub_args_line, _patch_args=patch_args)
615
+ return
616
+
617
+ sub_args_line_escaped = sub_args_line.replace("'", "<QUOTE>")
618
+ patch_args_escaped_str = json.dumps(patch_args).replace("'", "<QUOTE>")
619
+ src = (
620
+ "import json\n"
621
+ "from meerschaum._internal.entry import entry\n\n"
622
+ f"sub_args_line = '{sub_args_line_escaped}'.replace(\"<QUOTE>\", \"'\")\n"
623
+ f"patch_args = json.loads('{patch_args_escaped_str}'.replace('<QUOTE>', \"'\"))\n"
624
+ "success, msg = entry(sub_args_line, _patch_args=patch_args)\n"
625
+ f"print('{fence_begin}' + json.dumps((success, msg)) + '{fence_end}')"
626
+ )
627
+ proc = venv_exec(src, venv=None, as_proc=True)
628
+ poll_process(
629
+ proc,
630
+ write_line,
631
+ timeout_seconds,
632
+ timeout_handler,
633
+ )
634
+
581
635
  ran_n_times = 0
582
- success, msg = False, "Did not run pipeline."
583
636
  def run_loop():
584
637
  nonlocal ran_n_times, success, msg
585
638
  while True:
586
- success, msg = entry(sub_args_line, _patch_args=patch_args)
639
+ try:
640
+ do_entry()
641
+ except Exception as e:
642
+ warn(e)
587
643
  ran_n_times += 1
588
644
 
589
645
  if not loop and do_n_times == 1:
@@ -129,7 +129,6 @@ def _pipes_lap(
129
129
  stack=False,
130
130
  )
131
131
 
132
-
133
132
  def _task_label(count: int):
134
133
  return f"[cyan]Syncing {count} pipe{'s' if count != 1 else ''}..."
135
134
 
@@ -137,7 +136,6 @@ def _pipes_lap(
137
136
  _progress.add_task(_task_label(len(pipes)), start=True, total=len(pipes))
138
137
  ) if _progress is not None else None
139
138
 
140
-
141
139
  def worker_fn():
142
140
  while not stop_event.is_set():
143
141
  try:
@@ -188,7 +186,7 @@ def _pipes_lap(
188
186
  decoded[begin_index + len(fence_begin):end_index]
189
187
  ))
190
188
  return
191
- sys.stdout.buffer.write(line)
189
+ print(decoded)
192
190
 
193
191
  def timeout_handler(p, *args, **kw):
194
192
  success, msg = False, (
@@ -227,7 +225,7 @@ def _pipes_lap(
227
225
  write_line,
228
226
  timeout_seconds,
229
227
  timeout_handler,
230
- (p,)
228
+ (p,),
231
229
  )
232
230
  return _success_tuple
233
231
 
@@ -249,18 +247,18 @@ def _pipes_lap(
249
247
 
250
248
 
251
249
  def _sync_pipes(
252
- loop: bool = False,
253
- min_seconds: int = 1,
254
- unblock: bool = False,
255
- verify: bool = False,
256
- deduplicate: bool = False,
257
- bounded: Optional[bool] = None,
258
- chunk_interval: Union[timedelta, int, None] = None,
259
- shell: bool = False,
260
- nopretty: bool = False,
261
- debug: bool = False,
262
- **kw: Any
263
- ) -> SuccessTuple:
250
+ loop: bool = False,
251
+ min_seconds: int = 1,
252
+ unblock: bool = False,
253
+ verify: bool = False,
254
+ deduplicate: bool = False,
255
+ bounded: Optional[bool] = None,
256
+ chunk_interval: Union[timedelta, int, None] = None,
257
+ shell: bool = False,
258
+ nopretty: bool = False,
259
+ debug: bool = False,
260
+ **kw: Any
261
+ ) -> SuccessTuple:
264
262
  """
265
263
  Fetch and sync new data for pipes.
266
264
 
@@ -9,16 +9,17 @@ Upgrade your current Meerschaum environment
9
9
  from __future__ import annotations
10
10
  from meerschaum.utils.typing import SuccessTuple, Any, List, Optional, Union
11
11
 
12
+
12
13
  def upgrade(
13
14
  action: Optional[List[str]] = None,
14
15
  **kw: Any
15
16
  ) -> SuccessTuple:
16
17
  """
17
18
  Upgrade Meerschaum, plugins, or packages.
18
-
19
+
19
20
  Command:
20
21
  `upgrade {option}`
21
-
22
+
22
23
  Example:
23
24
  `upgrade meerschaum`
24
25
  """
@@ -77,7 +78,7 @@ def _upgrade_meerschaum(
77
78
  if force:
78
79
  answer = True
79
80
  else:
80
- answer = yes_no(f"Take down the stack?", default='y', yes=yes, noask=noask)
81
+ answer = yes_no("Take down the stack?", default='n', yes=yes, noask=noask)
81
82
 
82
83
  if answer:
83
84
  if debug:
@@ -95,7 +96,7 @@ def _upgrade_meerschaum(
95
96
  if debug:
96
97
  dprint('Upgrade meerschaum with dependencies: \"' + f'{dependencies}' + '\"')
97
98
  if not pip_install(install_name, venv=None, debug=debug):
98
- return False, f"Failed to upgrade Meerschaum via pip."
99
+ return False, "Failed to upgrade Meerschaum via pip."
99
100
 
100
101
  if debug:
101
102
  dprint("Pulling new Docker images...")
@@ -2,4 +2,4 @@
2
2
  Specify the Meerschaum release version.
3
3
  """
4
4
 
5
- __version__ = "2.4.12"
5
+ __version__ = "2.4.13"
@@ -309,6 +309,8 @@ def _simple_fetch_query(
309
309
  """Build a fetch query from a pipe's definition."""
310
310
  from meerschaum.utils.sql import format_cte_subquery
311
311
  definition = get_pipe_query(pipe)
312
+ if definition is None:
313
+ raise ValueError(f"No SQL definition could be found for {pipe}.")
312
314
  return format_cte_subquery(definition, flavor, 'definition')
313
315
 
314
316
 
@@ -316,7 +316,11 @@ def sync_plugins_symlinks(debug: bool = False, warn: bool = True) -> None:
316
316
 
317
317
  ### NOTE: Allow plugins to be installed via `pip`.
318
318
  packaged_plugin_paths = []
319
- discovered_packaged_plugins_eps = entry_points(group='meerschaum.plugins')
319
+ try:
320
+ discovered_packaged_plugins_eps = entry_points(group='meerschaum.plugins')
321
+ except TypeError:
322
+ discovered_packaged_plugins_eps = []
323
+
320
324
  for ep in discovered_packaged_plugins_eps:
321
325
  module_name = ep.name
322
326
  for package_file_path in ep.dist.files:
@@ -330,7 +334,7 @@ def sync_plugins_symlinks(debug: bool = False, warn: bool = True) -> None:
330
334
  if is_symlink(PLUGINS_RESOURCES_PATH) or not PLUGINS_RESOURCES_PATH.exists():
331
335
  try:
332
336
  PLUGINS_RESOURCES_PATH.unlink()
333
- except Exception as e:
337
+ except Exception:
334
338
  pass
335
339
 
336
340
  PLUGINS_RESOURCES_PATH.mkdir(exist_ok=True)
@@ -47,7 +47,6 @@ IMPORTS_LINES: Dict[str, str] = {
47
47
  ),
48
48
  }
49
49
 
50
- ### TODO: Add feature for custom connectors.
51
50
  FEATURE_LINES: Dict[str, str] = {
52
51
  'header': (
53
52
  "#! /usr/bin/env python3\n"
@@ -94,7 +93,7 @@ FEATURE_LINES: Dict[str, str] = {
94
93
  "class {plugin_name_capitalized}Connector(Connector):\n"
95
94
  " \"\"\"Implement '{plugin_name_lower}' connectors.\"\"\"\n\n"
96
95
  " REQUIRED_ATTRIBUTES: list[str] = []\n"
97
- " \n"
96
+ "\n"
98
97
  " def fetch(\n"
99
98
  " self,\n"
100
99
  " pipe: mrsm.Pipe,\n"
@@ -149,11 +148,12 @@ FEATURE_LINES: Dict[str, str] = {
149
148
  ),
150
149
  }
151
150
 
151
+
152
152
  def bootstrap_plugin(
153
- plugin_name: str,
154
- debug: bool = False,
155
- **kwargs: Any
156
- ) -> SuccessTuple:
153
+ plugin_name: str,
154
+ debug: bool = False,
155
+ **kwargs: Any
156
+ ) -> SuccessTuple:
157
157
  """
158
158
  Prompt the user for features and create a plugin file.
159
159
  """
@@ -177,9 +177,9 @@ def bootstrap_plugin(
177
177
  features: List[str] = choose(
178
178
  "Which of the following features would you like to add to your plugin?",
179
179
  list(FEATURE_CHOICES.items()),
180
- default = 'fetch',
181
- multiple = True,
182
- as_indices = True,
180
+ default='fetch',
181
+ multiple=True,
182
+ as_indices=True,
183
183
  **kwargs
184
184
  )
185
185
 
@@ -256,7 +256,7 @@ def bootstrap_plugin(
256
256
  _ = prompt(
257
257
  f"Press [Enter] to edit plugin '{plugin_name}',"
258
258
  + " [CTRL+C] to skip.",
259
- icon = False,
259
+ icon=False,
260
260
  )
261
261
  except (KeyboardInterrupt, Exception):
262
262
  return True, "Success"
@@ -267,7 +267,7 @@ def bootstrap_plugin(
267
267
 
268
268
  def _get_plugins_dir_path() -> pathlib.Path:
269
269
  from meerschaum.config.paths import PLUGINS_DIR_PATHS
270
-
270
+
271
271
  if not PLUGINS_DIR_PATHS:
272
272
  raise EnvironmentError("No plugin dir path could be found.")
273
273
 
@@ -278,9 +278,9 @@ def _get_plugins_dir_path() -> pathlib.Path:
278
278
  choose(
279
279
  "In which directory do you want to write your plugin?",
280
280
  [path.as_posix() for path in PLUGINS_DIR_PATHS],
281
- numeric = True,
282
- multiple = False,
283
- default = PLUGINS_DIR_PATHS[0].as_posix(),
281
+ numeric=True,
282
+ multiple=False,
283
+ default=PLUGINS_DIR_PATHS[0].as_posix(),
284
284
  )
285
285
  )
286
286
 
@@ -290,7 +290,7 @@ def _ask_to_uninstall(plugin: mrsm.Plugin, **kwargs: Any) -> SuccessTuple:
290
290
  warn(f"Plugin '{plugin}' is already installed!", stack=False)
291
291
  uninstall_plugin = yes_no(
292
292
  f"Do you want to first uninstall '{plugin}'?",
293
- default = 'n',
293
+ default='n',
294
294
  **kwargs
295
295
  )
296
296
  if not uninstall_plugin:
@@ -178,22 +178,32 @@ def run_process(
178
178
 
179
179
  return ret
180
180
 
181
+
181
182
  def poll_process(
182
- proc: subprocess.Popen,
183
- line_callback: Callable[[bytes], Any],
184
- timeout_seconds: Union[int, float, None] = None,
185
- timeout_callback: Optional[Callable[[Any], Any]] = None,
186
- timeout_callback_args: Optional[Tuple[Any]] = None,
187
- timeout_callback_kwargs: Optional[Dict[str, Any]] = None,
188
- ) -> int:
183
+ proc: subprocess.Popen,
184
+ line_callback: Callable[[bytes], Any],
185
+ timeout_seconds: Union[int, float, None] = None,
186
+ timeout_callback: Optional[Callable[[Any], Any]] = None,
187
+ timeout_callback_args: Optional[Tuple[Any]] = None,
188
+ timeout_callback_kwargs: Optional[Dict[str, Any]] = None,
189
+ ) -> int:
189
190
  """
190
191
  Poll a process and execute a callback function for each line printed to the process's `stdout`.
191
192
  """
192
193
  from meerschaum.utils.threading import Timer
194
+ from meerschaum.utils.warnings import warn
193
195
 
194
196
  def timeout_handler():
195
197
  nonlocal timeout_callback_args, timeout_callback_kwargs
196
- proc.terminate()
198
+ try:
199
+ if platform.system() != 'Windows':
200
+ ### The process being killed may have children.
201
+ os.killpg(os.getpgid(proc.pid), signal.SIGKILL)
202
+ else:
203
+ proc.send_signal(signal.CTRL_BREAK_EVENT)
204
+ proc.terminate()
205
+ except Exception as e:
206
+ warn(f"Failed to kill process:\n{e}")
197
207
  if timeout_callback_args is None:
198
208
  timeout_callback_args = []
199
209
  if timeout_callback_kwargs is None:
@@ -29,15 +29,16 @@ active_venvs = set()
29
29
  active_venvs_counts: Dict[str, int] = {}
30
30
  active_venvs_order: List[Optional[str]] = []
31
31
  threads_active_venvs: Dict[int, 'set[str]'] = {}
32
+ CREATE_NEW_PROCESS_GROUP = 0x00000200
32
33
 
33
34
 
34
35
  def activate_venv(
35
- venv: Optional[str] = 'mrsm',
36
- color: bool = True,
37
- force: bool = False,
38
- debug: bool = False,
39
- **kw
40
- ) -> bool:
36
+ venv: Optional[str] = 'mrsm',
37
+ color: bool = True,
38
+ force: bool = False,
39
+ debug: bool = False,
40
+ **kw
41
+ ) -> bool:
41
42
  """
42
43
  Create a virtual environment (if it doesn't exist) and add it to `sys.path` if necessary.
43
44
 
@@ -102,13 +103,13 @@ def activate_venv(
102
103
 
103
104
 
104
105
  def deactivate_venv(
105
- venv: str = 'mrsm',
106
- color: bool = True,
107
- debug: bool = False,
108
- previously_active_venvs: Union['set[str]', List[str], None] = None,
109
- force: bool = False,
110
- **kw
111
- ) -> bool:
106
+ venv: str = 'mrsm',
107
+ color: bool = True,
108
+ debug: bool = False,
109
+ previously_active_venvs: Union['set[str]', List[str], None] = None,
110
+ force: bool = False,
111
+ **kw
112
+ ) -> bool:
112
113
  """
113
114
  Remove a virtual environment from `sys.path` (if it's been activated).
114
115
 
@@ -498,14 +499,14 @@ def venv_executable(venv: Optional[str] = 'mrsm') -> str:
498
499
 
499
500
 
500
501
  def venv_exec(
501
- code: str,
502
- venv: Optional[str] = 'mrsm',
503
- env: Optional[Dict[str, str]] = None,
504
- with_extras: bool = False,
505
- as_proc: bool = False,
506
- capture_output: bool = True,
507
- debug: bool = False,
508
- ) -> Union[bool, Tuple[int, bytes, bytes]]:
502
+ code: str,
503
+ venv: Optional[str] = 'mrsm',
504
+ env: Optional[Dict[str, str]] = None,
505
+ with_extras: bool = False,
506
+ as_proc: bool = False,
507
+ capture_output: bool = True,
508
+ debug: bool = False,
509
+ ) -> Union[bool, Tuple[int, bytes, bytes]]:
509
510
  """
510
511
  Execute Python code in a subprocess via a virtual environment's interpeter.
511
512
  Return `True` if the code successfully executes, `False` on failure.
@@ -538,6 +539,7 @@ def venv_exec(
538
539
  """
539
540
  import os
540
541
  import subprocess
542
+ import platform
541
543
  from meerschaum.utils.debug import dprint
542
544
  executable = venv_executable(venv=venv)
543
545
  cmd_list = [executable, '-c', code]
@@ -549,11 +551,20 @@ def venv_exec(
549
551
  return subprocess.call(cmd_list, env=env) == 0
550
552
 
551
553
  stdout, stderr = (None, None) if not capture_output else (subprocess.PIPE, subprocess.PIPE)
554
+ group_kwargs = (
555
+ {
556
+ 'preexec_fn': os.setsid,
557
+ } if platform.system() != 'Windows'
558
+ else {
559
+ 'creationflags': CREATE_NEW_PROCESS_GROUP,
560
+ }
561
+ )
552
562
  process = subprocess.Popen(
553
563
  cmd_list,
554
- stdout = stdout,
555
- stderr = stderr,
556
- env = env,
564
+ stdout=stdout,
565
+ stderr=stderr,
566
+ env=env,
567
+ **group_kwargs
557
568
  )
558
569
  if as_proc:
559
570
  return process
@@ -154,13 +154,13 @@ def exception_with_traceback(
154
154
 
155
155
 
156
156
  def error(
157
- message: str,
158
- exception_class = Exception,
159
- nopretty: bool = False,
160
- silent: bool = True,
161
- stack: bool = True,
162
- raise_: bool = True,
163
- ):
157
+ message: str,
158
+ exception_class = Exception,
159
+ nopretty: bool = False,
160
+ silent: bool = True,
161
+ stack: bool = True,
162
+ raise_: bool = True,
163
+ ):
164
164
  """
165
165
  Raise an exception with supressed traceback.
166
166
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: meerschaum
3
- Version: 2.4.12
3
+ Version: 2.4.13
4
4
  Summary: Sync Time-Series Pipes with Meerschaum
5
5
  Home-page: https://meerschaum.io
6
6
  Author: Bennett Meares
@@ -1,7 +1,7 @@
1
1
  meerschaum/__init__.py,sha256=6bn5zz7VInDP4fE_FGBMzJYrM6rQhBMJNQqsf1pU7eI,1701
2
2
  meerschaum/__main__.py,sha256=r5UjYxH1WA6dGG9YGBPul5xOdgF3Iwl0X4dWDtXU-30,2646
3
3
  meerschaum/_internal/__init__.py,sha256=ilC7utfKtin7GAvuN34fKyUQYfPyqH0Mm3MJF5iyEf4,169
4
- meerschaum/_internal/entry.py,sha256=5vBZxQbtN0l9lia9HcvvLVWDCpSeThg-505dGhKiOBo,12234
4
+ meerschaum/_internal/entry.py,sha256=6attwMETUtFUtWq17asaSaNoeEvrwSLIVV_e5RX0pCc,12235
5
5
  meerschaum/_internal/arguments/__init__.py,sha256=_nSKKVLXNsJeSv-buxEZsx8_c0BAbkhRyE4nT6Bv6q0,541
6
6
  meerschaum/_internal/arguments/_parse_arguments.py,sha256=H492J571CetGVIEzOZhwQVS3bcm4t6hjWg8Gsf6dw0Y,16340
7
7
  meerschaum/_internal/arguments/_parser.py,sha256=l2RYIn-1MEpjyUz2yczkeeuwg2liYaO2MNvEZ4Amk1o,16364
@@ -24,13 +24,13 @@ meerschaum/_internal/term/tools.py,sha256=dXVAimKD-Yv2fg2WOTr0YGBY7XDKjQqw-RizcS
24
24
  meerschaum/actions/__init__.py,sha256=MHPs8aRBhbZQXnqd_6tVtisTrNCgPAPgnNcXYbn0zP8,11640
25
25
  meerschaum/actions/api.py,sha256=xeqkf4S-DEzFR8roIF1mzy-i_mAnUPkF7y3nIu8twCo,12593
26
26
  meerschaum/actions/attach.py,sha256=UV19d9W_2WYcrf7BRz7k3mriDoX1V4rA4AKvbLdor0o,3106
27
- meerschaum/actions/bootstrap.py,sha256=XmWv1UP2cGb28GRKSVKywAV6_9pk3HQR-Ad8hjnMcK8,18280
27
+ meerschaum/actions/bootstrap.py,sha256=9y4HU1uqjbkAg_706pOOJUMzl196pU7ghfGDCWg0vPE,18234
28
28
  meerschaum/actions/clear.py,sha256=tMacHFv8btWpkNnXHtKDOMiCDNhGb5S6CJhCDIrrNDk,4914
29
29
  meerschaum/actions/copy.py,sha256=NwTwj3IMdK1TFRuJXCxsbIEFNVeoNGoMkvE6H1ZQZzo,6838
30
30
  meerschaum/actions/deduplicate.py,sha256=puYyxeFYEUy1Sd2IOcZB2e6MrNxAZl2bTLmNzFDkCiw,1167
31
- meerschaum/actions/delete.py,sha256=DnEdkt_H4OYoee2DG-1mSDpTBp_Ay2aI1euRa4twPJU,19029
31
+ meerschaum/actions/delete.py,sha256=7hW4Ff_WSczW8If-EEDbEUU0U0XzV3fVbFb9gED4S9Q,19032
32
32
  meerschaum/actions/drop.py,sha256=Hd5h4rrWd7qL2rTqglsTonUsEoH7qQlsfqNFSHGeqr0,2453
33
- meerschaum/actions/edit.py,sha256=f51kHaVu2hMllAszVJtfLh7uKDrZ5OViSQcg12tSsl4,14598
33
+ meerschaum/actions/edit.py,sha256=bJ9DaPXGOySjq_rGFPVlbK99Ls9ajbQ5q5MksX_3WVY,15440
34
34
  meerschaum/actions/install.py,sha256=jdhOrR_KlvinTKr0YJNkUHsnh5EY6OzA7cRq0Vnp1oU,7494
35
35
  meerschaum/actions/login.py,sha256=fNgsgkrFCn9wBQJY50SQhz2PwsN_TvEYYHnXK3JG4ig,4206
36
36
  meerschaum/actions/os.py,sha256=dtoppoBhLzW3rLNF0SFovEfNxA4WJWt_9WrOGlS5KbA,2251
@@ -40,16 +40,16 @@ meerschaum/actions/register.py,sha256=By4eCJn-nvrWKs8dPG5GqMClUMm9y_yvIwU_FwRqJX
40
40
  meerschaum/actions/reload.py,sha256=gMXeFBGVfyQ7uhKhYf6bLaDMD0fLPcA9BrLBSiuvWIc,508
41
41
  meerschaum/actions/restart.py,sha256=6ffp3-X9eTEgunVSdD41HnOwqp71yjuSAmXJ5j39ONI,3038
42
42
  meerschaum/actions/setup.py,sha256=KkAGWcgwzl_L6A19fTmTX1KtBjW2FwD8QenLjPy0mQQ,3205
43
- meerschaum/actions/sh.py,sha256=fLfTJaacKu4sjLTRqEzzYlT2WbbdZBEczsKb6F-qAek,2026
43
+ meerschaum/actions/sh.py,sha256=hSkGNTVqP5dNjhJ64zy3V3VCFPTKnDlH3PxdKdxtkGQ,1990
44
44
  meerschaum/actions/show.py,sha256=T8Ol1o-762cI9rlUzd-8svvwgT4slYXYfOPQETh9Koo,28446
45
45
  meerschaum/actions/sql.py,sha256=8BSvlnccfEqLrscLq67Toa5D4FJ7I598IdxEe_yzmV8,4263
46
46
  meerschaum/actions/stack.py,sha256=ZwrCTGJ0x3jjZkRieWcvqasQHYCqNtB1HYvTX-r3Z3g,5996
47
- meerschaum/actions/start.py,sha256=PTYk-EzsSHnPyG5dEF0LHSLLNrJBaN6B9UuJGPhfRbM,19205
47
+ meerschaum/actions/start.py,sha256=26i2Pqg3c_Ltw3lgYzl3sZL2wG0XBgOuJrPK8qPPHdI,21281
48
48
  meerschaum/actions/stop.py,sha256=5fdUw70YN-yuUWrC-NhA88cxr9FZ5NbssbQ8xXO8nFU,4632
49
- meerschaum/actions/sync.py,sha256=DTWDIx7QGwh9zCxwG9L1k3k598h_ePPkrVkybwWUt4w,17225
49
+ meerschaum/actions/sync.py,sha256=uXneLSykNH0LapE4kn_9fzwUQ-kJcRUzJ42pyuoFNaI,17161
50
50
  meerschaum/actions/tag.py,sha256=SJf5qFW0ccLXjqlTdkK_0MCcrCMdg6xhYrhKdco0hdA,3053
51
51
  meerschaum/actions/uninstall.py,sha256=tBXhdXggSieGEQe4EPGxpgMK0MZTJCweNvAJ9-59El0,5776
52
- meerschaum/actions/upgrade.py,sha256=uhFhAPmguGDgxLa1UkVZnPQ-JRcbmOdExE38v-HrLvo,6471
52
+ meerschaum/actions/upgrade.py,sha256=1oXzK05WH-l8wq8Dxidr7c0hn7UQa3SuwRk0yyQH5vI,6462
53
53
  meerschaum/actions/verify.py,sha256=tY5slGpHiWiE0v9TDnjbmxSKn86zBnu9WBpixUgKNQU,4885
54
54
  meerschaum/api/__init__.py,sha256=5q2XelZvqZSyfCyGIf1mlrWVxrsDaG2_I4L5ACeqMso,8456
55
55
  meerschaum/api/_chain.py,sha256=h8-WXUGXX6AqzdALfsBC5uv0FkAcLdHJXCGzqzuq89k,875
@@ -143,7 +143,7 @@ meerschaum/config/_preprocess.py,sha256=-AEA8m_--KivZwTQ1sWN6LTn5sio_fUr2XZ51BO6
143
143
  meerschaum/config/_read_config.py,sha256=oxnLjuhy6JBBld886FkBX07wUdkpzEzTItYMUa9qw1Q,14688
144
144
  meerschaum/config/_shell.py,sha256=46_m49Txc5q1rGfCgO49ca48BODx45DQJi8D0zz1R18,4245
145
145
  meerschaum/config/_sync.py,sha256=jHcWRkxd82_BgX8Xo8agsWvf7BSbv3qHLWmYl6ehp_0,4242
146
- meerschaum/config/_version.py,sha256=xIXlWHgz3jJoMBNfzTMSvX_D7PqRAasEI5rlJLcWiyA,72
146
+ meerschaum/config/_version.py,sha256=kz1QZdlaaIVseDrdmhCpAtbsywLZfvnZsEoYBk9hyyE,72
147
147
  meerschaum/config/paths.py,sha256=JjibeGN3YAdSNceRwsd42aNmeUrIgM6ndzC8qZAmNI0,621
148
148
  meerschaum/config/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
149
149
  meerschaum/config/stack/__init__.py,sha256=gGVxXgNnGb9u25iF__IiNPlZt1BLUVmHmFJ0jvnJg3Q,10548
@@ -174,7 +174,7 @@ meerschaum/connectors/sql/_SQLConnector.py,sha256=QlC2Af7AM7bIlPHjUO57mTyzot3zU7
174
174
  meerschaum/connectors/sql/__init__.py,sha256=3cqYiDkVasn7zWdtOTAZbT4bo95AuvGOmDD2TkaAxtw,205
175
175
  meerschaum/connectors/sql/_cli.py,sha256=1SgnWeMIAihoxp4FzbNrcq1npXf0dSOQnCntpU9hUXA,4405
176
176
  meerschaum/connectors/sql/_create_engine.py,sha256=pZPjy-ne8DtVfu-wqMJopIGkgm8vul-y3E9d4tUyTgM,10215
177
- meerschaum/connectors/sql/_fetch.py,sha256=pReFEPwwS2UuDn4A-EkAm6O2IpekM88pLujCkby9fyc,12913
177
+ meerschaum/connectors/sql/_fetch.py,sha256=4-Bc4X8dFo6bikVGE5X16s4qmdqbN7NpGPeYB3MlqAA,13014
178
178
  meerschaum/connectors/sql/_instance.py,sha256=zXPZnEqvOAeOUPMeh6CcfkB1pOjjwJxdUOwXccRbuwk,6465
179
179
  meerschaum/connectors/sql/_pipes.py,sha256=-jbuBjZ8EET2bkhgAWQmqci5FNcBCZUqnOcF_tuHq8M,101055
180
180
  meerschaum/connectors/sql/_plugins.py,sha256=wbxcNxqTtjfDsxPvdVGTllasYf6NHHzODaQ72hEUSBQ,8135
@@ -215,8 +215,8 @@ meerschaum/jobs/_Job.py,sha256=hkjHqG5YPej5rC4nwdU7Ay_mjep9Fy4HO5B-eqdBdfo,31984
215
215
  meerschaum/jobs/__init__.py,sha256=q0f_2zWw91sAyafP50IgMM06abe-BIYSR_SCWmI4W3E,12177
216
216
  meerschaum/jobs/systemd.py,sha256=Rq-tsDPslG17ZhpKMrVJ5r8Z0IPr6DEc9APObfIoXCg,24614
217
217
  meerschaum/plugins/_Plugin.py,sha256=rTiGNQ9nIQeVSG_P9C6DHCMLW0K-J7zzuu3FjNXUOlE,34056
218
- meerschaum/plugins/__init__.py,sha256=trMQ53qgP7ikJhhV_uXzqJw6X1NDz2rPOGXFk40bb1Y,26190
219
- meerschaum/plugins/bootstrap.py,sha256=qg9MQ1YAU8ShwGqWDl38WjiXLIxDPl95pSIGDLN9rOw,11423
218
+ meerschaum/plugins/__init__.py,sha256=6krcqaMKyzuVqesXMqEL0XEy2SJQ4xfNt2-oI_fJ6v0,26278
219
+ meerschaum/plugins/bootstrap.py,sha256=VwjpZAuYdqPJW0YoVgAoM_taHkdQHqP902-8T7OWWCI,11339
220
220
  meerschaum/utils/__init__.py,sha256=QrK1K9hIbPCRCM5k2nZGFqGnrqhA0Eh-iSmCU7FG6Cs,612
221
221
  meerschaum/utils/_get_pipes.py,sha256=tu4xKPoDn79Dz2kWM13cXTP4DSCkn-3G9M8KiLftopw,11073
222
222
  meerschaum/utils/dataframe.py,sha256=qV_6ecpxMIZOoiUb0pIk8u5ZPBn-h6O1yS_DtdLFX_U,41937
@@ -225,13 +225,13 @@ meerschaum/utils/interactive.py,sha256=t-6jWozXSqL7lYGDHuwiOjTgr-UKhdcg61q_eR5mi
225
225
  meerschaum/utils/misc.py,sha256=OijhS1TMjlqkDvahbxhqfUdo0Myeor-kTKrvqqG8wN0,46349
226
226
  meerschaum/utils/networking.py,sha256=Sr_eYUGW8_UV9-k9LqRFf7xLtbUcsDucODyLCRsFRUc,1006
227
227
  meerschaum/utils/pool.py,sha256=vkE42af4fjrTEJTxf6Ek3xGucm1MtEkpsSEiaVzNKHs,2655
228
- meerschaum/utils/process.py,sha256=o7UtTQX87YGkg2dItPhlvN7gNQPkElXTYSzKf5Ro8Uc,7474
228
+ meerschaum/utils/process.py,sha256=9O8PPPJjY9Q5W2f39I3B3lFU6TlSiRiI3bgrzdOOyOw,7843
229
229
  meerschaum/utils/prompt.py,sha256=6J--mZJ_NcEdSX6KMjtY4fXXezyILLHP24VdxFFqOIc,18985
230
230
  meerschaum/utils/schedule.py,sha256=6I2TFGa1aPRU9wTdd3YFrJq-DCPpnl-sTWeFEnrINYA,10886
231
231
  meerschaum/utils/sql.py,sha256=R_hX92brvZDqID7c85-PNUVVR6RWXGXEgn1vFpHmi88,49869
232
232
  meerschaum/utils/threading.py,sha256=3N8JXPAnwqJiSjuQcbbJg3Rv9-CCUMJpeQRfKFR7MaA,2489
233
233
  meerschaum/utils/typing.py,sha256=U3MC347sh1umpa3Xr1k71eADyDmk4LB6TnVCpq8dVzI,2830
234
- meerschaum/utils/warnings.py,sha256=IDiwYspsfjIi1gtk3V9cSo9vNLckB9bCsHhRClpPJTc,6639
234
+ meerschaum/utils/warnings.py,sha256=n-phr3BftNNgyPnvnXC_VMSjtCvjiCZ-ewmVfcROhkc,6611
235
235
  meerschaum/utils/yaml.py,sha256=PoC1du0pn2hLwTHwL-zuOf_EBWZSbCGOz-P-AZ4BWN0,3901
236
236
  meerschaum/utils/daemon/Daemon.py,sha256=rLUjJTGwKVUGVTHyz_A_lUJ_Wb2CgzT1ZFLhLwvGiNk,42142
237
237
  meerschaum/utils/daemon/FileDescriptorInterceptor.py,sha256=MJKMO0Syf3d8yWUs6xXcQzg8Ptsuvh2aCRRoglOjusA,5257
@@ -250,12 +250,12 @@ meerschaum/utils/packages/__init__.py,sha256=m3HLTkKJxXco1g-h75q2l5skBwKXWaJtNmf
250
250
  meerschaum/utils/packages/_packages.py,sha256=8Ox9fiQTVmmKAmlxZBV-7Wtq_jhPnnf3AMXvktGE-KY,8319
251
251
  meerschaum/utils/packages/lazy_loader.py,sha256=VHnph3VozH29R4JnSSBfwtA5WKZYZQFT_GeQSShCnuc,2540
252
252
  meerschaum/utils/venv/_Venv.py,sha256=sBnlmxHdAh2bx8btfVoD79-H9-cYsv5lP02IIXkyECs,3553
253
- meerschaum/utils/venv/__init__.py,sha256=G3KXL4ByWNqVxBRLs_RaJbO3h3tOKXkazkAYuoUW568,24420
254
- meerschaum-2.4.12.dist-info/LICENSE,sha256=jG2zQEdRNt88EgHUWPpXVWmOrOduUQRx7MnYV9YIPaw,11359
255
- meerschaum-2.4.12.dist-info/METADATA,sha256=rVQS3Zz8YZeAYGAa3AEkifTMrDyvBW2B-epRjrf7xc8,24820
256
- meerschaum-2.4.12.dist-info/NOTICE,sha256=OTA9Fcthjf5BRvWDDIcBC_xfLpeDV-RPZh3M-HQBRtQ,114
257
- meerschaum-2.4.12.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
258
- meerschaum-2.4.12.dist-info/entry_points.txt,sha256=5YBVzibw-0rNA_1VjB16z5GABsOGf-CDhW4yqH8C7Gc,88
259
- meerschaum-2.4.12.dist-info/top_level.txt,sha256=bNoSiDj0El6buocix-FRoAtJOeq1qOF5rRm2u9i7Q6A,11
260
- meerschaum-2.4.12.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
261
- meerschaum-2.4.12.dist-info/RECORD,,
253
+ meerschaum/utils/venv/__init__.py,sha256=f3oi67lXYPLKJrnRW9lae7M3A8SFiC7DzaMoBdCVUFs,24609
254
+ meerschaum-2.4.13.dist-info/LICENSE,sha256=jG2zQEdRNt88EgHUWPpXVWmOrOduUQRx7MnYV9YIPaw,11359
255
+ meerschaum-2.4.13.dist-info/METADATA,sha256=y0OKNCTNx9iyL9PI80-yYa_Yg9SYcSK8Td172EBl5Fo,24820
256
+ meerschaum-2.4.13.dist-info/NOTICE,sha256=OTA9Fcthjf5BRvWDDIcBC_xfLpeDV-RPZh3M-HQBRtQ,114
257
+ meerschaum-2.4.13.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
258
+ meerschaum-2.4.13.dist-info/entry_points.txt,sha256=5YBVzibw-0rNA_1VjB16z5GABsOGf-CDhW4yqH8C7Gc,88
259
+ meerschaum-2.4.13.dist-info/top_level.txt,sha256=bNoSiDj0El6buocix-FRoAtJOeq1qOF5rRm2u9i7Q6A,11
260
+ meerschaum-2.4.13.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
261
+ meerschaum-2.4.13.dist-info/RECORD,,