meerschaum 3.0.0rc4__py3-none-any.whl → 3.0.0rc8__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.
Files changed (117) hide show
  1. meerschaum/_internal/arguments/_parser.py +14 -2
  2. meerschaum/_internal/cli/__init__.py +6 -0
  3. meerschaum/_internal/cli/daemons.py +103 -0
  4. meerschaum/_internal/cli/entry.py +220 -0
  5. meerschaum/_internal/cli/workers.py +435 -0
  6. meerschaum/_internal/docs/index.py +1 -2
  7. meerschaum/_internal/entry.py +44 -8
  8. meerschaum/_internal/shell/Shell.py +115 -24
  9. meerschaum/_internal/shell/__init__.py +4 -1
  10. meerschaum/_internal/static.py +4 -1
  11. meerschaum/_internal/term/TermPageHandler.py +1 -2
  12. meerschaum/_internal/term/__init__.py +40 -6
  13. meerschaum/_internal/term/tools.py +33 -8
  14. meerschaum/actions/__init__.py +6 -4
  15. meerschaum/actions/api.py +39 -11
  16. meerschaum/actions/attach.py +1 -0
  17. meerschaum/actions/delete.py +4 -2
  18. meerschaum/actions/edit.py +27 -8
  19. meerschaum/actions/login.py +8 -8
  20. meerschaum/actions/register.py +13 -7
  21. meerschaum/actions/reload.py +22 -5
  22. meerschaum/actions/restart.py +14 -0
  23. meerschaum/actions/show.py +69 -4
  24. meerschaum/actions/start.py +135 -14
  25. meerschaum/actions/stop.py +36 -3
  26. meerschaum/actions/sync.py +6 -1
  27. meerschaum/api/__init__.py +35 -13
  28. meerschaum/api/_events.py +2 -2
  29. meerschaum/api/_oauth2.py +47 -4
  30. meerschaum/api/dash/callbacks/dashboard.py +29 -0
  31. meerschaum/api/dash/callbacks/jobs.py +3 -2
  32. meerschaum/api/dash/callbacks/login.py +10 -1
  33. meerschaum/api/dash/callbacks/register.py +9 -2
  34. meerschaum/api/dash/pages/login.py +2 -2
  35. meerschaum/api/dash/pipes.py +72 -36
  36. meerschaum/api/dash/webterm.py +14 -6
  37. meerschaum/api/models/_pipes.py +7 -1
  38. meerschaum/api/resources/static/js/terminado.js +3 -0
  39. meerschaum/api/resources/static/js/xterm-addon-unicode11.js +2 -0
  40. meerschaum/api/resources/templates/termpage.html +1 -0
  41. meerschaum/api/routes/_jobs.py +23 -11
  42. meerschaum/api/routes/_login.py +73 -5
  43. meerschaum/api/routes/_pipes.py +6 -4
  44. meerschaum/api/routes/_webterm.py +3 -3
  45. meerschaum/config/__init__.py +60 -13
  46. meerschaum/config/_default.py +89 -61
  47. meerschaum/config/_edit.py +10 -8
  48. meerschaum/config/_formatting.py +2 -0
  49. meerschaum/config/_patch.py +4 -2
  50. meerschaum/config/_paths.py +127 -12
  51. meerschaum/config/_read_config.py +32 -12
  52. meerschaum/config/_version.py +1 -1
  53. meerschaum/config/environment.py +262 -0
  54. meerschaum/config/stack/__init__.py +7 -5
  55. meerschaum/connectors/_Connector.py +1 -2
  56. meerschaum/connectors/__init__.py +37 -2
  57. meerschaum/connectors/api/_APIConnector.py +1 -1
  58. meerschaum/connectors/api/_jobs.py +11 -0
  59. meerschaum/connectors/api/_pipes.py +7 -1
  60. meerschaum/connectors/instance/_plugins.py +9 -1
  61. meerschaum/connectors/instance/_tokens.py +20 -3
  62. meerschaum/connectors/instance/_users.py +8 -1
  63. meerschaum/connectors/parse.py +1 -1
  64. meerschaum/connectors/sql/_create_engine.py +3 -0
  65. meerschaum/connectors/sql/_pipes.py +93 -79
  66. meerschaum/connectors/sql/_users.py +8 -1
  67. meerschaum/connectors/valkey/_ValkeyConnector.py +3 -3
  68. meerschaum/connectors/valkey/_pipes.py +7 -5
  69. meerschaum/core/Pipe/__init__.py +45 -71
  70. meerschaum/core/Pipe/_attributes.py +66 -90
  71. meerschaum/core/Pipe/_cache.py +555 -0
  72. meerschaum/core/Pipe/_clear.py +0 -11
  73. meerschaum/core/Pipe/_data.py +0 -50
  74. meerschaum/core/Pipe/_deduplicate.py +0 -13
  75. meerschaum/core/Pipe/_delete.py +12 -21
  76. meerschaum/core/Pipe/_drop.py +11 -23
  77. meerschaum/core/Pipe/_dtypes.py +1 -1
  78. meerschaum/core/Pipe/_index.py +8 -14
  79. meerschaum/core/Pipe/_sync.py +12 -18
  80. meerschaum/core/Plugin/_Plugin.py +7 -1
  81. meerschaum/core/Token/_Token.py +1 -1
  82. meerschaum/core/User/_User.py +1 -2
  83. meerschaum/jobs/_Executor.py +88 -4
  84. meerschaum/jobs/_Job.py +146 -36
  85. meerschaum/jobs/systemd.py +7 -2
  86. meerschaum/plugins/__init__.py +277 -81
  87. meerschaum/utils/daemon/Daemon.py +197 -42
  88. meerschaum/utils/daemon/FileDescriptorInterceptor.py +0 -1
  89. meerschaum/utils/daemon/RotatingFile.py +63 -36
  90. meerschaum/utils/daemon/StdinFile.py +53 -13
  91. meerschaum/utils/daemon/__init__.py +18 -5
  92. meerschaum/utils/daemon/_names.py +6 -3
  93. meerschaum/utils/debug.py +34 -4
  94. meerschaum/utils/dtypes/__init__.py +5 -1
  95. meerschaum/utils/formatting/__init__.py +4 -1
  96. meerschaum/utils/formatting/_jobs.py +1 -1
  97. meerschaum/utils/formatting/_pipes.py +47 -46
  98. meerschaum/utils/formatting/_shell.py +33 -9
  99. meerschaum/utils/misc.py +22 -38
  100. meerschaum/utils/packages/__init__.py +15 -13
  101. meerschaum/utils/packages/_packages.py +1 -0
  102. meerschaum/utils/pipes.py +33 -5
  103. meerschaum/utils/process.py +1 -1
  104. meerschaum/utils/prompt.py +172 -143
  105. meerschaum/utils/sql.py +12 -2
  106. meerschaum/utils/threading.py +42 -0
  107. meerschaum/utils/venv/__init__.py +2 -0
  108. meerschaum/utils/warnings.py +19 -13
  109. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/METADATA +3 -1
  110. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/RECORD +116 -110
  111. meerschaum/config/_environment.py +0 -145
  112. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/WHEEL +0 -0
  113. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/entry_points.txt +0 -0
  114. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/licenses/LICENSE +0 -0
  115. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/licenses/NOTICE +0 -0
  116. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/top_level.txt +0 -0
  117. {meerschaum-3.0.0rc4.dist-info → meerschaum-3.0.0rc8.dist-info}/zip-safe +0 -0
@@ -277,18 +277,31 @@ def pprint_pipe_columns(
277
277
 
278
278
 
279
279
  def pipe_repr(
280
- pipe: mrsm.Pipe,
280
+ pipe: Union[mrsm.Pipe, Dict[str, Any]],
281
281
  as_rich_text: bool = False,
282
282
  ansi: Optional[bool] = None,
283
283
  ) -> Union[str, 'rich.text.Text']:
284
284
  """
285
285
  Return a formatted string for representing a `meerschaum.Pipe`.
286
286
  """
287
- from meerschaum.utils.formatting import UNICODE, ANSI, CHARSET, colored, rich_text_to_str
287
+ from meerschaum.utils.formatting import ANSI, colored, rich_text_to_str
288
288
  from meerschaum.utils.packages import import_rich, attempt_import
289
- rich = import_rich()
289
+ import meerschaum as mrsm
290
+
291
+ _ = import_rich()
290
292
  Text = attempt_import('rich.text').Text
291
293
 
294
+ if isinstance(pipe, mrsm.Pipe):
295
+ connector_keys = pipe.connector_keys
296
+ metric_key = pipe.metric_key
297
+ location_key = pipe.location_key
298
+ instance_keys = pipe.instance_keys
299
+ else:
300
+ connector_keys = pipe.get('connector_keys')
301
+ metric_key = pipe.get('metric_key')
302
+ location_key = pipe.get('location_key')
303
+ instance_keys = pipe.get('instance_keys', get_config('meerschaum', 'instance'))
304
+
292
305
  styles = get_config('formatting', 'pipes', '__repr__', 'ansi', 'styles')
293
306
  if not ANSI or (ansi is False):
294
307
  styles = {k: '' for k in styles}
@@ -298,26 +311,26 @@ def pipe_repr(
298
311
  )
299
312
  text_obj = (
300
313
  Text.from_markup(_pipe_style_prefix + "Pipe(" + _pipe_style_suffix)
301
- + colored(("'" + pipe.connector_keys + "'"), style=styles['connector'], as_rich_text=True)
314
+ + colored(("'" + connector_keys + "'"), style=styles['connector'], as_rich_text=True)
302
315
  + Text.from_markup(_pipe_style_prefix + ", " + _pipe_style_suffix)
303
- + colored(("'" + pipe.metric_key + "'"), style=styles['metric'], as_rich_text=True)
316
+ + colored(("'" + metric_key + "'"), style=styles['metric'], as_rich_text=True)
304
317
  + (
305
318
  (
306
319
  colored(', ', style=styles['punctuation'], as_rich_text=True)
307
320
  + colored(
308
- ("'" + pipe.location_key + "'"),
321
+ ("'" + location_key + "'"),
309
322
  style=styles['location'], as_rich_text=True
310
323
  )
311
- ) if pipe.location_key is not None
324
+ ) if location_key is not None
312
325
  else colored('', style='', as_rich_text=True)
313
326
  ) + (
314
327
  ( ### Add the `instance=` argument.
315
328
  colored(', instance=', style=styles['punctuation'], as_rich_text=True)
316
329
  + colored(
317
- ("'" + pipe.instance_keys + "'"),
330
+ ("'" + instance_keys + "'"),
318
331
  style=styles['instance'], as_rich_text=True
319
332
  )
320
- ) if pipe.instance_keys != get_config('meerschaum', 'instance')
333
+ ) if instance_keys != get_config('meerschaum', 'instance')
321
334
  else colored('', style='', as_rich_text=True)
322
335
  )
323
336
  + Text.from_markup(_pipe_style_prefix + ")" + _pipe_style_suffix)
@@ -327,6 +340,7 @@ def pipe_repr(
327
340
  return rich_text_to_str(text_obj).replace('\n', '')
328
341
 
329
342
 
343
+
330
344
  def highlight_pipes(message: str) -> str:
331
345
  """
332
346
  Add syntax highlighting to an info message containing stringified `meerschaum.Pipe` objects.
@@ -334,48 +348,35 @@ def highlight_pipes(message: str) -> str:
334
348
  if 'Pipe(' not in message:
335
349
  return message
336
350
 
337
- from meerschaum import Pipe
351
+ from meerschaum.utils.misc import parse_arguments_str
338
352
  segments = message.split('Pipe(')
339
353
  msg = ''
340
- _d = {}
341
354
  for i, segment in enumerate(segments):
342
- comma_index = segment.find(',')
343
- paren_index = segment.find(')')
344
- single_quote_index = segment.find("'")
345
- double_quote_index = segment.find('"')
346
-
347
- has_comma = comma_index != -1
348
- has_paren = paren_index != -1
349
- has_single_quote = single_quote_index != -1
350
- has_double_quote = double_quote_index != -1
351
- has_quote = has_single_quote or has_double_quote
352
- quote_index = (
353
- min(single_quote_index, double_quote_index)
354
- if has_double_quote and has_single_quote
355
- else (single_quote_index if has_single_quote else double_quote_index)
356
- )
357
-
358
- has_pipe = (
359
- has_comma
360
- and
361
- has_paren
362
- and
363
- has_quote
364
- and not
365
- (comma_index > paren_index or quote_index > paren_index)
366
- )
355
+ if i == 0:
356
+ msg += segment
357
+ continue
367
358
 
368
- if has_pipe:
369
- code = "_d['pipe'] = Pipe(" + segment[:paren_index + 1]
370
- try:
371
- exec(code)
372
- _to_add = pipe_repr(_d['pipe']) + segment[paren_index + 1:]
373
- _ = _d.pop('pipe', None)
374
- except Exception as e:
375
- _to_add = 'Pipe(' + segment
376
- msg += _to_add
359
+ paren_index = segment.find(')')
360
+ if paren_index == -1:
361
+ msg += 'Pipe(' + segment
377
362
  continue
378
- msg += segment
363
+
364
+ pipe_args_str = segment[:paren_index]
365
+ try:
366
+ args, kwargs = parse_arguments_str(pipe_args_str)
367
+ pipe_dict = {
368
+ 'connector_keys': args[0],
369
+ 'metric_key': args[1],
370
+ }
371
+ if len(args) > 2:
372
+ pipe_dict['location_key'] = args[2]
373
+ if 'instance' in kwargs:
374
+ pipe_dict['instance_keys'] = kwargs['instance']
375
+
376
+ _to_add = pipe_repr(pipe_dict) + segment[paren_index + 1:]
377
+ except Exception:
378
+ _to_add = 'Pipe(' + segment
379
+ msg += _to_add
379
380
  return msg
380
381
 
381
382
 
@@ -6,10 +6,12 @@
6
6
  Formatting functions for the interactive shell
7
7
  """
8
8
 
9
- from re import sub
10
9
  from meerschaum.utils.threading import Lock
11
10
  _locks = {'_tried_clear_command': Lock()}
12
11
 
12
+ from meerschaum._internal.static import STATIC_CONFIG
13
+ FLUSH_TOKEN: str = STATIC_CONFIG['jobs']['flush_token']
14
+
13
15
 
14
16
  def make_header(message: str, ruler: str = '─', left_pad: int = 2) -> str:
15
17
  """Format a message string with a ruler.
@@ -51,28 +53,40 @@ def clear_screen(debug: bool = False) -> bool:
51
53
  from meerschaum.utils.debug import dprint
52
54
  from meerschaum.config import get_config
53
55
  from meerschaum.utils.daemon import running_in_daemon
56
+ from meerschaum._internal.static import STATIC_CONFIG
54
57
  global _tried_clear_command
58
+ clear_string = '\033[2J'
59
+ reset_string = '\033[0m'
60
+ clear_token = STATIC_CONFIG['jobs']['clear_token']
55
61
 
56
- if running_in_daemon():
62
+ if not get_config('shell', 'clear_screen'):
57
63
  return True
58
64
 
59
- if not get_config('shell', 'clear_screen'):
65
+ if running_in_daemon():
66
+ if debug:
67
+ dprint("Skip printing clear token.")
68
+ flush_stdout()
69
+ return True
70
+
71
+ print(clear_token, flush=True)
60
72
  return True
61
73
 
62
- print("", end="", flush=True)
74
+
75
+ flush_stdout()
63
76
  if debug:
64
77
  dprint("Skipping screen clear.")
65
78
  return True
79
+
66
80
  if ANSI and platform.system() != 'Windows':
67
81
  if get_console() is not None:
68
82
  get_console().clear()
69
- print("", end="", flush=True)
83
+ flush_stdout()
70
84
  return True
71
- clear_string = '\033[2J'
72
- reset_string = '\033[0m'
85
+
73
86
  print(clear_string + reset_string, end="")
74
- print("", end="", flush=True)
87
+ flush_stdout()
75
88
  return True
89
+
76
90
  ### ANSI support is disabled, try system level instead
77
91
  if _tried_clear_command is not None:
78
92
  return os.system(_tried_clear_command) == 0
@@ -81,7 +95,7 @@ def clear_screen(debug: bool = False) -> bool:
81
95
  command = 'clear' if platform.system() != 'Windows' else 'cls'
82
96
  try:
83
97
  rc = os.system(command)
84
- except Exception as e:
98
+ except Exception:
85
99
  pass
86
100
  if rc == 0:
87
101
  with _locks['_tried_clear_command']:
@@ -89,6 +103,16 @@ def clear_screen(debug: bool = False) -> bool:
89
103
  return rc == 0
90
104
 
91
105
 
106
+ def flush_stdout():
107
+ """
108
+ Flush stdout, including printing the flush token for daemons.
109
+ """
110
+ from meerschaum.utils.daemon import running_in_daemon
111
+ print('', end='', flush=True)
112
+ if running_in_daemon():
113
+ print(FLUSH_TOKEN, end='', flush=True)
114
+
115
+
92
116
  def flush_with_newlines(debug: bool = False) -> None:
93
117
  """Print newlines such that the entire terminal is cleared and new text will show up at the bottom."""
94
118
  import sys
meerschaum/utils/misc.py CHANGED
@@ -6,9 +6,11 @@ Miscellaneous functions go here
6
6
  """
7
7
 
8
8
  from __future__ import annotations
9
+
9
10
  import sys
10
11
  import functools
11
- from datetime import timedelta, datetime, timezone
12
+ from datetime import timedelta, datetime
13
+
12
14
  from meerschaum.utils.typing import (
13
15
  Union,
14
16
  Any,
@@ -20,13 +22,8 @@ from meerschaum.utils.typing import (
20
22
  Iterable,
21
23
  PipesDict,
22
24
  Tuple,
23
- InstanceConnector,
24
- Hashable,
25
- Generator,
26
- Iterator,
27
25
  TYPE_CHECKING,
28
26
  )
29
- import meerschaum as mrsm
30
27
  if TYPE_CHECKING:
31
28
  import collections
32
29
 
@@ -43,6 +40,9 @@ __pdoc__: Dict[str, bool] = {
43
40
  'df_is_chunk_generator': False,
44
41
  'choices_docstring': False,
45
42
  '_get_subaction_names': False,
43
+ 'is_pipe_registered': False,
44
+ 'replace_pipes_in_dict': False,
45
+ 'round_time': False,
46
46
  }
47
47
 
48
48
 
@@ -347,37 +347,6 @@ def edit_file(
347
347
  return rc == 0
348
348
 
349
349
 
350
- def is_pipe_registered(
351
- pipe: mrsm.Pipe,
352
- pipes: PipesDict,
353
- debug: bool = False
354
- ) -> bool:
355
- """
356
- Check if a Pipe is inside the pipes dictionary.
357
-
358
- Parameters
359
- ----------
360
- pipe: meerschaum.Pipe
361
- The pipe to see if it's in the dictionary.
362
-
363
- pipes: PipesDict
364
- The dictionary to search inside.
365
-
366
- debug: bool, default False
367
- Verbosity toggle.
368
-
369
- Returns
370
- -------
371
- A bool indicating whether the pipe is inside the dictionary.
372
- """
373
- from meerschaum.utils.debug import dprint
374
- ck, mk, lk = pipe.connector_keys, pipe.metric_key, pipe.location_key
375
- if debug:
376
- dprint(f'{ck}, {mk}, {lk}')
377
- dprint(f'{pipe}, {pipes}')
378
- return ck in pipes and mk in pipes[ck] and lk in pipes[ck][mk]
379
-
380
-
381
350
  def get_cols_lines(default_cols: int = 100, default_lines: int = 120) -> Tuple[int, int]:
382
351
  """
383
352
  Determine the columns and lines in the terminal.
@@ -1263,11 +1232,15 @@ def is_systemd_available() -> bool:
1263
1232
  import subprocess
1264
1233
  try:
1265
1234
  has_systemctl = subprocess.call(
1266
- ['systemctl', '-h'],
1235
+ ['systemctl', 'whoami'],
1267
1236
  stdout=subprocess.DEVNULL,
1268
1237
  stderr=subprocess.STDOUT,
1269
1238
  ) == 0
1239
+ except FileNotFoundError:
1240
+ has_systemctl = False
1270
1241
  except Exception:
1242
+ import traceback
1243
+ traceback.print_exc()
1271
1244
  has_systemctl = False
1272
1245
  return has_systemctl
1273
1246
 
@@ -1283,6 +1256,8 @@ def is_tmux_available() -> bool:
1283
1256
  stdout=subprocess.DEVNULL,
1284
1257
  stderr=subprocess.STDOUT
1285
1258
  ) == 0
1259
+ except FileNotFoundError:
1260
+ has_tmux = False
1286
1261
  except Exception:
1287
1262
  has_tmux = False
1288
1263
  return has_tmux
@@ -1844,6 +1819,15 @@ def replace_pipes_in_dict(*args, **kwargs):
1844
1819
  return replace_pipes_in_dict(*args, **kwargs)
1845
1820
 
1846
1821
 
1822
+ def is_pipe_registered(*args, **kwargs):
1823
+ """
1824
+ Placeholder function to prevent breaking legacy behavior.
1825
+ See `meerschaum.utils.pipes.is_pipe_registered`.
1826
+ """
1827
+ from meerschaum.utils.pipes import is_pipe_registered
1828
+ return is_pipe_registered(*args, **kwargs)
1829
+
1830
+
1847
1831
  def round_time(*args, **kwargs):
1848
1832
  """
1849
1833
  Placeholder function to prevent breaking legacy behavior.
@@ -136,17 +136,17 @@ def get_module_path(
136
136
 
137
137
 
138
138
  def manually_import_module(
139
- import_name: str,
140
- venv: Optional[str] = 'mrsm',
141
- check_update: bool = True,
142
- check_pypi: bool = False,
143
- install: bool = True,
144
- split: bool = True,
145
- warn: bool = True,
146
- color: bool = True,
147
- debug: bool = False,
148
- use_sys_modules: bool = True,
149
- ) -> Union['ModuleType', None]:
139
+ import_name: str,
140
+ venv: Optional[str] = 'mrsm',
141
+ check_update: bool = True,
142
+ check_pypi: bool = False,
143
+ install: bool = True,
144
+ split: bool = True,
145
+ warn: bool = True,
146
+ color: bool = True,
147
+ debug: bool = False,
148
+ use_sys_modules: bool = True,
149
+ ) -> Union['ModuleType', None]:
150
150
  """
151
151
  Manually import a module from a virtual environment (or the base environment).
152
152
 
@@ -1179,7 +1179,8 @@ def run_python_package(
1179
1179
  Either a return code integer or a `subprocess.Popen` object
1180
1180
  (or `None` if a `KeyboardInterrupt` occurs and as_proc is `True`).
1181
1181
  """
1182
- import sys, platform
1182
+ import sys
1183
+ import platform
1183
1184
  import subprocess
1184
1185
  from meerschaum.config._paths import VIRTENV_RESOURCES_PATH
1185
1186
  from meerschaum.utils.process import run_process
@@ -1206,7 +1207,7 @@ def run_python_package(
1206
1207
  capture_output=capture_output,
1207
1208
  **kw
1208
1209
  )
1209
- except Exception as e:
1210
+ except Exception:
1210
1211
  msg = f"Failed to execute {command}, will try again:\n{traceback.format_exc()}"
1211
1212
  warn(msg, color=False)
1212
1213
  stdout, stderr = (
@@ -1218,6 +1219,7 @@ def run_python_package(
1218
1219
  command,
1219
1220
  stdout=stdout,
1220
1221
  stderr=stderr,
1222
+ stdin=sys.stdin,
1221
1223
  env=env_dict,
1222
1224
  )
1223
1225
  to_return = proc if as_proc else proc.wait()
@@ -175,6 +175,7 @@ packages['api'] = {
175
175
  'httpx' : 'httpx>=0.28.1',
176
176
  'httpcore' : 'httpcore>=1.0.9',
177
177
  'valkey' : 'valkey>=6.1.0',
178
+ 'jose' : 'python-jose>=3.5.0',
178
179
  }
179
180
  packages['api'].update(packages['sql'])
180
181
  packages['api'].update(packages['formatting'])
meerschaum/utils/pipes.py CHANGED
@@ -14,7 +14,7 @@ import ast
14
14
  import copy
15
15
  import uuid
16
16
 
17
- from meerschaum.utils.typing import PipesDict, Optional, Any
17
+ from meerschaum.utils.typing import PipesDict, Optional
18
18
  import meerschaum as mrsm
19
19
 
20
20
 
@@ -96,9 +96,7 @@ def replace_pipes_syntax(text: str) -> Any:
96
96
  Parse a string containing the `{{ Pipe() }}` syntax.
97
97
  """
98
98
  from meerschaum.utils.warnings import warn
99
- from meerschaum.utils.sql import sql_item_name
100
99
  from meerschaum.utils.dtypes import json_serialize_value
101
- from meerschaum.utils.misc import parse_arguments_str
102
100
  pattern = r'\{\{\s*(?:mrsm\.)?Pipe\((.*?)\)((?:\.[\w]+|\[[^\]]+\])*)\s*\}\}'
103
101
 
104
102
  matches = list(re.finditer(pattern, text))
@@ -158,7 +156,6 @@ def replace_pipes_in_dict(
158
156
 
159
157
  debug: bool, default False
160
158
  Verbosity toggle.
161
-
162
159
 
163
160
  Returns
164
161
  -------
@@ -168,7 +165,7 @@ def replace_pipes_in_dict(
168
165
  def change_dict(d: Dict[Any, Any]) -> None:
169
166
  for k, v in d.items():
170
167
  if isinstance(v, dict):
171
- change_dict(v, func)
168
+ change_dict(v)
172
169
  elif isinstance(v, list):
173
170
  d[k] = [func(i) for i in v]
174
171
  elif isinstance(v, tuple):
@@ -183,3 +180,34 @@ def replace_pipes_in_dict(
183
180
  result = copy.deepcopy(pipes)
184
181
  change_dict(result)
185
182
  return result
183
+
184
+
185
+ def is_pipe_registered(
186
+ pipe: mrsm.Pipe,
187
+ pipes: PipesDict,
188
+ debug: bool = False
189
+ ) -> bool:
190
+ """
191
+ Check if a Pipe is inside the pipes dictionary.
192
+
193
+ Parameters
194
+ ----------
195
+ pipe: meerschaum.Pipe
196
+ The pipe to see if it's in the dictionary.
197
+
198
+ pipes: PipesDict
199
+ The dictionary to search inside.
200
+
201
+ debug: bool, default False
202
+ Verbosity toggle.
203
+
204
+ Returns
205
+ -------
206
+ A bool indicating whether the pipe is inside the dictionary.
207
+ """
208
+ from meerschaum.utils.debug import dprint
209
+ ck, mk, lk = pipe.connector_keys, pipe.metric_key, pipe.location_key
210
+ if debug:
211
+ dprint(f'{ck}, {mk}, {lk}')
212
+ dprint(f'{pipe}, {pipes}')
213
+ return ck in pipes and mk in pipes[ck] and lk in pipes[ck][mk]
@@ -178,7 +178,7 @@ def run_process(
178
178
  # make us tty's foreground again
179
179
  try:
180
180
  os.tcsetpgrp(sys.stdin.fileno(), old_pgrp)
181
- except Exception as e:
181
+ except Exception:
182
182
  pass
183
183
  # now restore the handler
184
184
  signal.signal(signal.SIGTTOU, hdlr)