meerschaum 2.2.4__py3-none-any.whl → 2.2.5.dev2__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 (37) hide show
  1. meerschaum/_internal/arguments/_parse_arguments.py +23 -14
  2. meerschaum/_internal/arguments/_parser.py +4 -1
  3. meerschaum/_internal/entry.py +2 -4
  4. meerschaum/_internal/shell/Shell.py +0 -3
  5. meerschaum/actions/__init__.py +5 -1
  6. meerschaum/actions/backup.py +43 -0
  7. meerschaum/actions/bootstrap.py +32 -7
  8. meerschaum/actions/delete.py +62 -0
  9. meerschaum/actions/edit.py +98 -15
  10. meerschaum/actions/python.py +44 -2
  11. meerschaum/actions/show.py +26 -0
  12. meerschaum/actions/uninstall.py +24 -29
  13. meerschaum/api/_oauth2.py +17 -0
  14. meerschaum/api/routes/_login.py +23 -7
  15. meerschaum/config/__init__.py +16 -6
  16. meerschaum/config/_edit.py +1 -1
  17. meerschaum/config/_paths.py +3 -0
  18. meerschaum/config/_version.py +1 -1
  19. meerschaum/config/stack/__init__.py +3 -1
  20. meerschaum/core/Pipe/_fetch.py +25 -21
  21. meerschaum/core/Pipe/_sync.py +89 -59
  22. meerschaum/plugins/bootstrap.py +333 -0
  23. meerschaum/utils/daemon/Daemon.py +14 -3
  24. meerschaum/utils/daemon/FileDescriptorInterceptor.py +21 -14
  25. meerschaum/utils/daemon/RotatingFile.py +21 -18
  26. meerschaum/utils/formatting/__init__.py +22 -10
  27. meerschaum/utils/packages/_packages.py +1 -1
  28. meerschaum/utils/prompt.py +64 -21
  29. meerschaum/utils/yaml.py +32 -1
  30. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/METADATA +5 -2
  31. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/RECORD +37 -35
  32. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/WHEEL +1 -1
  33. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/LICENSE +0 -0
  34. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/NOTICE +0 -0
  35. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/entry_points.txt +0 -0
  36. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/top_level.txt +0 -0
  37. {meerschaum-2.2.4.dist-info → meerschaum-2.2.5.dev2.dist-info}/zip-safe +0 -0
@@ -80,8 +80,9 @@ def parse_arguments(sysargs: List[str]) -> Dict[str, Any]:
80
80
 
81
81
  ### rebuild sysargs without sub_arguments
82
82
  filtered_sysargs = [
83
- word for i, word in enumerate(sysargs)
84
- if i not in sub_arg_indices
83
+ word
84
+ for i, word in enumerate(sysargs)
85
+ if i not in sub_arg_indices
85
86
  ]
86
87
 
87
88
  try:
@@ -99,7 +100,6 @@ def parse_arguments(sysargs: List[str]) -> Dict[str, Any]:
99
100
  except Exception as _e:
100
101
  args_dict['text'] = ' '.join(sysargs)
101
102
  args_dict[STATIC_CONFIG['system']['arguments']['failure_key']] = e
102
- unknown = []
103
103
 
104
104
  false_flags = [arg for arg, val in args_dict.items() if val is False]
105
105
  for arg in false_flags:
@@ -126,17 +126,26 @@ def parse_arguments(sysargs: List[str]) -> Dict[str, Any]:
126
126
 
127
127
  ### remove None (but not False) args
128
128
  none_args = []
129
+ none_args_keep = []
129
130
  for a, v in args_dict.items():
130
131
  if v is None:
131
132
  none_args.append(a)
133
+ elif v == 'None':
134
+ none_args_keep.append(a)
132
135
  for a in none_args:
133
136
  del args_dict[a]
137
+ for a in none_args_keep:
138
+ args_dict[a] = None
134
139
 
135
140
  ### location_key '[None]' or 'None' -> None
136
141
  if 'location_keys' in args_dict:
137
142
  args_dict['location_keys'] = [
138
- None if lk in ('[None]', 'None')
139
- else lk for lk in args_dict['location_keys']
143
+ (
144
+ None
145
+ if lk in ('[None]', 'None')
146
+ else lk
147
+ )
148
+ for lk in args_dict['location_keys']
140
149
  ]
141
150
 
142
151
  return parse_synonyms(args_dict)
@@ -145,7 +154,7 @@ def parse_arguments(sysargs: List[str]) -> Dict[str, Any]:
145
154
  def parse_line(line: str) -> Dict[str, Any]:
146
155
  """
147
156
  Parse a line of text into standard Meerschaum arguments.
148
-
157
+
149
158
  Parameters
150
159
  ----------
151
160
  line: str
@@ -165,12 +174,12 @@ def parse_line(line: str) -> Dict[str, Any]:
165
174
  try:
166
175
  return parse_arguments(shlex.split(line))
167
176
  except Exception as e:
168
- return {'action': [], 'text': line,}
177
+ return {'action': [], 'text': line}
169
178
 
170
179
 
171
180
  def parse_synonyms(
172
- args_dict: Dict[str, Any]
173
- ) -> Dict[str, Any]:
181
+ args_dict: Dict[str, Any]
182
+ ) -> Dict[str, Any]:
174
183
  """Check for synonyms (e.g. `async` = `True` -> `unblock` = `True`)"""
175
184
  if args_dict.get('async', None):
176
185
  args_dict['unblock'] = True
@@ -194,8 +203,8 @@ def parse_synonyms(
194
203
 
195
204
 
196
205
  def parse_dict_to_sysargs(
197
- args_dict : Dict[str, Any]
198
- ) -> List[str]:
206
+ args_dict: Dict[str, Any]
207
+ ) -> List[str]:
199
208
  """Revert an arguments dictionary back to a command line list."""
200
209
  from meerschaum._internal.arguments._parser import get_arguments_triggers
201
210
  sysargs = []
@@ -230,9 +239,9 @@ def parse_dict_to_sysargs(
230
239
 
231
240
 
232
241
  def remove_leading_action(
233
- action: List[str],
234
- _actions: Optional[Dict[str, Callable[[Any], SuccessTuple]]] = None,
235
- ) -> List[str]:
242
+ action: List[str],
243
+ _actions: Optional[Dict[str, Callable[[Any], SuccessTuple]]] = None,
244
+ ) -> List[str]:
236
245
  """
237
246
  Remove the leading strings in the `action` list.
238
247
 
@@ -37,12 +37,15 @@ class ArgumentParser(argparse.ArgumentParser):
37
37
  return result
38
38
 
39
39
 
40
- def parse_datetime(dt_str: str) -> datetime:
40
+ def parse_datetime(dt_str: str) -> Union[datetime, int, str]:
41
41
  """Parse a string into a datetime."""
42
42
  from meerschaum.utils.misc import is_int
43
43
  if is_int(dt_str):
44
44
  return int(dt_str)
45
45
 
46
+ if dt_str in ('None', '[None]'):
47
+ return 'None'
48
+
46
49
  from meerschaum.utils.packages import attempt_import
47
50
  dateutil_parser = attempt_import('dateutil.parser')
48
51
 
@@ -47,9 +47,6 @@ def entry(sysargs: Optional[List[str]] = None) -> SuccessTuple:
47
47
  )
48
48
  )
49
49
 
50
- # if args.get('schedule', None):
51
- # from meerschaum.utils.schedule import schedule_function
52
- # return schedule_function(entry_with_args, **args)
53
50
  return entry_with_args(**args)
54
51
 
55
52
 
@@ -122,11 +119,12 @@ def entry_with_args(
122
119
  def _do_action_wrapper(action_function, plugin_name, **kw):
123
120
  from meerschaum.plugins import Plugin
124
121
  from meerschaum.utils.venv import Venv, active_venvs, deactivate_venv
122
+ from meerschaum.utils.misc import filter_keywords
125
123
  plugin = Plugin(plugin_name) if plugin_name else None
126
124
  with Venv(plugin, debug=kw.get('debug', False)):
127
125
  action_name = ' '.join(action_function.__name__.split('_') + kw.get('action', []))
128
126
  try:
129
- result = action_function(**kw)
127
+ result = action_function(**filter_keywords(action_function, **kw))
130
128
  except Exception as e:
131
129
  if kw.get('debug', False):
132
130
  import traceback
@@ -182,7 +182,6 @@ def _check_complete_keys(line: str) -> Optional[List[str]]:
182
182
  is_trigger = True
183
183
  elif line.endswith(' '):
184
184
  ### return empty list so we don't try to parse an incomplete line.
185
- # print('ABORT')
186
185
  return []
187
186
 
188
187
  from meerschaum.utils.misc import get_connector_labels
@@ -196,8 +195,6 @@ def _check_complete_keys(line: str) -> Optional[List[str]]:
196
195
  if line.rstrip(' ').endswith(trigger):
197
196
  return get_connector_labels()
198
197
 
199
- # args = parse_line(line.rstrip(' '))
200
- # search_term = args[var] if var != 'connector_keys' else args[var][0]
201
198
  return get_connector_labels(search_term=last_word.rstrip(' '))
202
199
 
203
200
  return None
@@ -40,7 +40,11 @@ def get_subactions(
40
40
  for name, f in inspect.getmembers(action_module):
41
41
  if not inspect.isfunction(f):
42
42
  continue
43
- if action_function.__name__ + '_' in name and not name.lstrip('_').startswith('complete'):
43
+
44
+ ### Detect subactions which may contain an underscore prefix.
45
+ if (
46
+ name.lstrip('_').startswith(action_function.__name__.lstrip('_') + '_')
47
+ ):
44
48
  _name = name.replace(action_function.__name__, '')
45
49
  _name = _name.lstrip('_')
46
50
  subactions[_name] = f
@@ -0,0 +1,43 @@
1
+ #! /usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # vim:fenc=utf-8
4
+
5
+ """
6
+ Backup the stack database.
7
+ """
8
+
9
+ from __future__ import annotations
10
+ from meerschaum.utils.typing import SuccessTuple, Any, List, Optional, Union
11
+
12
+ def backup(
13
+ action: Optional[List[str]] = None,
14
+ **kwargs: Any
15
+ ) -> SuccessTuple:
16
+ """
17
+ Backup the stack database.
18
+ """
19
+ from meerschaum.actions import choose_subaction
20
+ options = {
21
+ 'database' : _backup_database,
22
+ }
23
+ return choose_subaction(action, options, **kwargs)
24
+
25
+
26
+ def _backup_database(
27
+ action: Optional[List[str]] = None,
28
+ ) -> SuccessTuple:
29
+ """
30
+ Backup the stack's database to a sql file.
31
+ """
32
+ from meerschaum.actions import get_action
33
+ from meerschaum.config.paths import BACKUP_RESOURCES_PATH
34
+ do_stack = get_action('stack')
35
+ cmd_list = ['exec', 'db', 'pg']
36
+ stack_success, stack_msg = do_stack(['exec'])
37
+ return True, "Success"
38
+
39
+ ### NOTE: This must be the final statement of the module.
40
+ ### Any subactions added below these lines will not
41
+ ### be added to the `help` docstring.
42
+ from meerschaum.utils.misc import choices_docstring as _choices_docstring
43
+ backup.__doc__ += _choices_docstring('backup')
@@ -25,6 +25,7 @@ def bootstrap(
25
25
  options = {
26
26
  'pipes' : _bootstrap_pipes,
27
27
  'connectors' : _bootstrap_connectors,
28
+ 'plugins' : _bootstrap_plugins,
28
29
  }
29
30
  return choose_subaction(action, options, **kw)
30
31
 
@@ -102,12 +103,14 @@ def _bootstrap_pipes(
102
103
  )
103
104
  try:
104
105
  ck = choose(
105
- f"Where are the data coming from?\n\n" +
106
- f" Please type the keys of a connector from below,\n" +
107
- f" or enter '{new_label}' to register a new connector.\n\n" +
108
- f" {get_config('formatting', 'emoji', 'connector')} Connector:\n",
106
+ (
107
+ "Where are the data coming from?\n\n" +
108
+ f" Please type the keys of a connector or enter '{new_label}'\n" +
109
+ " to register a new connector.\n\n" +
110
+ f" {get_config('formatting', 'emoji', 'connector')} Connector:"
111
+ ),
109
112
  get_connector_labels() + [new_label],
110
- numeric = False
113
+ numeric = False,
111
114
  )
112
115
  except KeyboardInterrupt:
113
116
  return abort_tuple
@@ -257,8 +260,8 @@ def _bootstrap_connectors(
257
260
  _type = choose(
258
261
  (
259
262
  'Please choose a connector type.\n'
260
- + 'For more information on connectors, '
261
- + 'please visit https://meerschaum.io/reference/connectors'
263
+ + ' See https://meerschaum.io/reference/connectors '
264
+ + 'for documentation on connectors.\n'
262
265
  ),
263
266
  sorted(list(connectors)),
264
267
  default = 'sql'
@@ -382,6 +385,28 @@ def _bootstrap_connectors(
382
385
  return True, "Success"
383
386
 
384
387
 
388
+ def _bootstrap_plugins(
389
+ action: Optional[List[str]] = None,
390
+ debug: bool = False,
391
+ **kwargs: Any
392
+ ) -> SuccessTuple:
393
+ """
394
+ Launch an interactive wizard to guide the user to creating a new plugin.
395
+ """
396
+ from meerschaum.utils.prompt import prompt
397
+ from meerschaum.plugins.bootstrap import bootstrap_plugin
398
+
399
+ if not action:
400
+ action = [prompt("Enter the name of your new plugin:")]
401
+
402
+ for plugin_name in action:
403
+ bootstrap_success, bootstrap_msg = bootstrap_plugin(plugin_name)
404
+ if not bootstrap_success:
405
+ return bootstrap_success, bootstrap_msg
406
+
407
+ return True, "Success"
408
+
409
+
385
410
  ### NOTE: This must be the final statement of the module.
386
411
  ### Any subactions added below these lines will not
387
412
  ### be added to the `help` docstring.
@@ -29,6 +29,7 @@ def delete(
29
29
  'users' : _delete_users,
30
30
  'connectors' : _delete_connectors,
31
31
  'jobs' : _delete_jobs,
32
+ 'venvs' : _delete_venvs,
32
33
  }
33
34
  return choose_subaction(action, options, **kw)
34
35
 
@@ -486,6 +487,67 @@ def _delete_jobs(
486
487
  )
487
488
 
488
489
 
490
+ def _delete_venvs(
491
+ action: Optional[List[str]] = None,
492
+ yes: bool = False,
493
+ force: bool = False,
494
+ **kwargs: Any
495
+ ) -> SuccessTuple:
496
+ """
497
+ Remove virtual environments.
498
+ Specify which venvs to remove, or remove everything at once.
499
+ """
500
+ import os
501
+ import shutil
502
+ import pathlib
503
+ from meerschaum.config.paths import VIRTENV_RESOURCES_PATH
504
+ from meerschaum.utils.venv import venv_exists
505
+ from meerschaum.utils.prompt import yes_no
506
+ from meerschaum.utils.misc import print_options
507
+ from meerschaum.utils.warnings import warn
508
+
509
+ venvs_to_skip = ['mrsm']
510
+ venvs = [
511
+ _venv
512
+ for _venv in action or os.listdir(VIRTENV_RESOURCES_PATH)
513
+ if venv_exists(_venv)
514
+ and _venv not in venvs_to_skip
515
+ ]
516
+
517
+ if not venvs:
518
+ msg = "No venvs to delete."
519
+ if action:
520
+ return False, msg
521
+ return True, msg
522
+
523
+ print_options(
524
+ venvs,
525
+ header = 'Venvs to Delete:',
526
+ **kwargs
527
+ )
528
+ confirm_delete = yes_no(
529
+ (
530
+ "Remove the above venv" + ('s' if len(venvs) != 1 else '') + "?\n "
531
+ + "Run `mrsm upgrade packages` and `mrsm install required` to reinstall dependencies.\n"
532
+ ),
533
+ yes = yes,
534
+ default = 'n',
535
+ force = force,
536
+ )
537
+ if not confirm_delete:
538
+ return True, "Nothing was deleted."
539
+
540
+ for venv in venvs:
541
+ venv_path = pathlib.Path(VIRTENV_RESOURCES_PATH / venv)
542
+ try:
543
+ shutil.rmtree(venv_path)
544
+ except Exception as e:
545
+ error_msg = f"Failed to remove '{venv_path}':\n{e}"
546
+ return False, error_msg
547
+
548
+ msg = f"Removed {len(venvs)} venv" + ('s' if len(venvs) != 1 else '') + '.'
549
+ return True, msg
550
+
489
551
 
490
552
  ### NOTE: This must be the final statement of the module.
491
553
  ### Any subactions added below these lines will not
@@ -7,6 +7,7 @@ Functions for editing elements belong here.
7
7
  """
8
8
 
9
9
  from __future__ import annotations
10
+ import meerschaum as mrsm
10
11
  from meerschaum.utils.typing import List, Any, SuccessTuple, Optional, Dict
11
12
 
12
13
  def edit(
@@ -22,19 +23,22 @@ def edit(
22
23
  'pipes' : _edit_pipes,
23
24
  'definition': _edit_definition,
24
25
  'users' : _edit_users,
26
+ 'plugins' : _edit_plugins,
25
27
  }
26
28
  return choose_subaction(action, options, **kw)
27
29
 
28
30
 
29
31
  def _complete_edit(
30
- action: Optional[List[str]] = None,
31
- **kw: Any
32
- ) -> List[str]:
32
+ action: Optional[List[str]] = None,
33
+ **kw: Any
34
+ ) -> List[str]:
33
35
  """
34
36
  Override the default Meerschaum `complete_` function.
35
37
  """
36
38
  options = {
37
39
  'config': _complete_edit_config,
40
+ 'plugin': _complete_edit_plugins,
41
+ 'plugins': _complete_edit_plugins,
38
42
  }
39
43
 
40
44
  if action is None:
@@ -78,7 +82,7 @@ def _edit_config(action : Optional[List[str]] = None, **kw : Any) -> SuccessTupl
78
82
  action.append('meerschaum')
79
83
  return edit_config(keys=action, **kw)
80
84
 
81
- def _complete_edit_config(action: Optional[List[str]] = None, **kw : Any) -> List[str]:
85
+ def _complete_edit_config(action: Optional[List[str]] = None, **kw: Any) -> List[str]:
82
86
  from meerschaum.config._read_config import get_possible_keys
83
87
  keys = get_possible_keys()
84
88
  if not action:
@@ -172,9 +176,9 @@ def _edit_pipes(
172
176
 
173
177
 
174
178
  def _edit_definition(
175
- action: Optional[List[str]] = None,
176
- **kw
177
- ) -> SuccessTuple:
179
+ action: Optional[List[str]] = None,
180
+ **kw
181
+ ) -> SuccessTuple:
178
182
  """
179
183
  Edit pipes' definitions.
180
184
  Alias for `edit pipes definition`.
@@ -183,13 +187,13 @@ def _edit_definition(
183
187
 
184
188
 
185
189
  def _edit_users(
186
- action: Optional[List[str]] = None,
187
- mrsm_instance: Optional[str] = None,
188
- yes: bool = False,
189
- noask: bool = False,
190
- debug: bool = False,
191
- **kw: Any
192
- ) -> SuccessTuple:
190
+ action: Optional[List[str]] = None,
191
+ mrsm_instance: Optional[str] = None,
192
+ yes: bool = False,
193
+ noask: bool = False,
194
+ debug: bool = False,
195
+ **kw: Any
196
+ ) -> SuccessTuple:
193
197
  """
194
198
  Edit users' registration information.
195
199
  """
@@ -262,7 +266,7 @@ def _edit_users(
262
266
  if not action:
263
267
  return False, "No users to edit."
264
268
 
265
- success = dict()
269
+ success = {}
266
270
  for username in action:
267
271
  try:
268
272
  user = build_user(username)
@@ -289,6 +293,85 @@ def _edit_users(
289
293
  info(msg)
290
294
  return True, msg
291
295
 
296
+
297
+ def _edit_plugins(
298
+ action: Optional[List[str]] = None,
299
+ debug: bool = False,
300
+ **kwargs: Any
301
+ ):
302
+ """
303
+ Edit a plugin's source code.
304
+ """
305
+ import pathlib
306
+ from meerschaum.utils.warnings import warn
307
+ from meerschaum.utils.prompt import prompt, yes_no
308
+ from meerschaum.utils.misc import edit_file
309
+ from meerschaum.utils.packages import reload_meerschaum
310
+ from meerschaum.actions import actions
311
+
312
+ if not action:
313
+ return False, "Specify which plugin to edit."
314
+
315
+ for plugin_name in action:
316
+ plugin = mrsm.Plugin(plugin_name)
317
+
318
+ if not plugin.is_installed():
319
+ warn(f"Plugin '{plugin_name}' is not installed.", stack=False)
320
+
321
+ if not yes_no(
322
+ f"Would you like to create a new plugin '{plugin_name}'?",
323
+ **kwargs
324
+ ):
325
+ return False, f"Plugin '{plugin_name}' does not exist."
326
+
327
+ actions['bootstrap'](
328
+ ['plugins', plugin_name],
329
+ debug = debug,
330
+ **kwargs
331
+ )
332
+ continue
333
+
334
+ plugin_file_path = pathlib.Path(plugin.__file__).resolve()
335
+
336
+ try:
337
+ _ = prompt(f"Press [Enter] to open '{plugin_file_path}':", icon=False)
338
+ except (KeyboardInterrupt, Exception):
339
+ continue
340
+
341
+ edit_file(plugin_file_path)
342
+ reload_meerschaum(debug=debug)
343
+
344
+ return True, "Success"
345
+
346
+
347
+ def _complete_edit_plugins(
348
+ action: Optional[List[str]] = None,
349
+ line: Optional[str] = None,
350
+ **kw: Any
351
+ ) -> List[str]:
352
+ from meerschaum.plugins import get_plugins_names
353
+ plugins_names = get_plugins_names(try_import=False)
354
+ if not action:
355
+ return plugins_names
356
+
357
+ last_word = action[-1]
358
+ if last_word in plugins_names and (line or '')[-1] == ' ':
359
+ return [
360
+ plugin_name
361
+ for plugin_name in plugins_names
362
+ if plugin_name not in action
363
+ ]
364
+
365
+ possibilities = []
366
+ for plugin_name in plugins_names:
367
+ if (
368
+ plugin_name.startswith(last_word)
369
+ and plugin_name not in action
370
+ ):
371
+ possibilities.append(plugin_name)
372
+ return possibilities
373
+
374
+
292
375
  ### NOTE: This must be the final statement of the module.
293
376
  ### Any subactions added below these lines will not
294
377
  ### be added to the `help` docstring.
@@ -11,6 +11,9 @@ from meerschaum.utils.typing import SuccessTuple, Any, List, Optional
11
11
  def python(
12
12
  action: Optional[List[str]] = None,
13
13
  sub_args: Optional[List[str]] = None,
14
+ nopretty: bool = False,
15
+ noask: bool = False,
16
+ venv: Optional[str] = None,
14
17
  debug: bool = False,
15
18
  **kw: Any
16
19
  ) -> SuccessTuple:
@@ -24,6 +27,21 @@ def python(
24
27
  Examples:
25
28
  mrsm python
26
29
  mrsm python [-m pip -V]
30
+
31
+ Flags:
32
+ `--nopretty`
33
+ Open a plain Pyhthon REPL rather than ptpython.
34
+
35
+ `--noask`
36
+ Run the supplied Python code and do not open a REPL.
37
+
38
+ `--venv`
39
+ Run the Python interpreter from a virtual environment.
40
+ Will not have Meercshaum imported.
41
+
42
+ `--sub-args` (or flags surrounded by `[]`)
43
+ Rather than run Python code, execute the interpreter with the given sub-flags
44
+ (e.g. `mrsm python [-V]`)
27
45
  """
28
46
  import sys, subprocess, os
29
47
  from meerschaum.utils.debug import dprint
@@ -33,11 +51,16 @@ def python(
33
51
  from meerschaum.config import __version__ as _version
34
52
  from meerschaum.config.paths import VIRTENV_RESOURCES_PATH, PYTHON_RESOURCES_PATH
35
53
  from meerschaum.utils.packages import run_python_package, attempt_import
54
+ from meerschaum.utils.process import run_process
36
55
 
37
56
  if action is None:
38
57
  action = []
39
58
 
40
- joined_actions = ["import meerschaum as mrsm"]
59
+ joined_actions = (
60
+ ["import meerschaum as mrsm"]
61
+ if venv is None and not sub_args
62
+ else []
63
+ )
41
64
  line = ""
42
65
  for i, a in enumerate(action):
43
66
  if a == '':
@@ -68,6 +91,11 @@ def python(
68
91
  '"""); '
69
92
  + 'pts.print_formatted_text(ansi); '
70
93
  )
94
+ if nopretty or venv is not None or sub_args:
95
+ print_command = ""
96
+
97
+ if sub_args:
98
+ nopretty = True
71
99
 
72
100
  command = print_command
73
101
  for a in joined_actions:
@@ -89,7 +117,21 @@ def python(
89
117
  'ptpython',
90
118
  sub_args or ['--dark-bg', '-i', init_script_path.as_posix()],
91
119
  foreground = True,
92
- venv = None,
120
+ venv = venv,
121
+ ) if not nopretty else run_process(
122
+ (
123
+ [venv_executable(venv)] + (
124
+ sub_args or
125
+ (
126
+ (
127
+ ['-i']
128
+ if not noask
129
+ else []
130
+ ) + [init_script_path.as_posix()]
131
+ )
132
+ )
133
+ ),
134
+ foreground = True,
93
135
  )
94
136
  except KeyboardInterrupt:
95
137
  return_code = 1
@@ -42,6 +42,7 @@ def show(
42
42
  'logs' : _show_logs,
43
43
  'tags' : _show_tags,
44
44
  'schedules' : _show_schedules,
45
+ 'venvs' : _show_venvs,
45
46
  }
46
47
  return choose_subaction(action, show_options, **kw)
47
48
 
@@ -903,6 +904,31 @@ def _show_schedules(
903
904
  return True, "Success"
904
905
 
905
906
 
907
+ def _show_venvs(
908
+ **kwargs: Any
909
+ ):
910
+ """
911
+ Print the available virtual environments in the current MRSM_ROOT_DIR.
912
+ """
913
+ import os
914
+ import pathlib
915
+ from meerschaum.config.paths import VIRTENV_RESOURCES_PATH
916
+ from meerschaum.utils.venv import venv_exists
917
+ from meerschaum.utils.misc import print_options
918
+
919
+ venvs = [
920
+ _venv
921
+ for _venv in os.listdir(VIRTENV_RESOURCES_PATH)
922
+ if venv_exists(_venv)
923
+ ]
924
+ print_options(
925
+ venvs,
926
+ name = 'Venvs:',
927
+ **kwargs
928
+ )
929
+
930
+ return True, "Success"
931
+
906
932
 
907
933
  ### NOTE: This must be the final statement of the module.
908
934
  ### Any subactions added below these lines will not