meerschaum 2.2.6__py3-none-any.whl → 2.3.0__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 (80) hide show
  1. meerschaum/__init__.py +6 -1
  2. meerschaum/__main__.py +9 -9
  3. meerschaum/_internal/arguments/__init__.py +1 -1
  4. meerschaum/_internal/arguments/_parse_arguments.py +72 -6
  5. meerschaum/_internal/arguments/_parser.py +45 -15
  6. meerschaum/_internal/docs/index.py +265 -8
  7. meerschaum/_internal/entry.py +167 -37
  8. meerschaum/_internal/shell/Shell.py +290 -99
  9. meerschaum/_internal/shell/updates.py +175 -0
  10. meerschaum/actions/__init__.py +29 -17
  11. meerschaum/actions/api.py +12 -12
  12. meerschaum/actions/attach.py +113 -0
  13. meerschaum/actions/copy.py +68 -41
  14. meerschaum/actions/delete.py +112 -50
  15. meerschaum/actions/edit.py +3 -3
  16. meerschaum/actions/install.py +40 -32
  17. meerschaum/actions/pause.py +44 -27
  18. meerschaum/actions/register.py +19 -5
  19. meerschaum/actions/restart.py +107 -0
  20. meerschaum/actions/show.py +130 -159
  21. meerschaum/actions/start.py +161 -100
  22. meerschaum/actions/stop.py +78 -42
  23. meerschaum/actions/sync.py +3 -3
  24. meerschaum/actions/upgrade.py +28 -36
  25. meerschaum/api/_events.py +25 -1
  26. meerschaum/api/_oauth2.py +2 -0
  27. meerschaum/api/_websockets.py +2 -2
  28. meerschaum/api/dash/callbacks/jobs.py +36 -44
  29. meerschaum/api/dash/jobs.py +89 -78
  30. meerschaum/api/routes/__init__.py +1 -0
  31. meerschaum/api/routes/_actions.py +148 -17
  32. meerschaum/api/routes/_jobs.py +407 -0
  33. meerschaum/api/routes/_pipes.py +25 -25
  34. meerschaum/config/_default.py +1 -0
  35. meerschaum/config/_formatting.py +1 -0
  36. meerschaum/config/_jobs.py +1 -1
  37. meerschaum/config/_paths.py +11 -0
  38. meerschaum/config/_shell.py +84 -67
  39. meerschaum/config/_version.py +1 -1
  40. meerschaum/config/static/__init__.py +18 -0
  41. meerschaum/connectors/Connector.py +13 -7
  42. meerschaum/connectors/__init__.py +28 -15
  43. meerschaum/connectors/api/APIConnector.py +27 -1
  44. meerschaum/connectors/api/_actions.py +71 -6
  45. meerschaum/connectors/api/_jobs.py +368 -0
  46. meerschaum/connectors/api/_misc.py +1 -1
  47. meerschaum/connectors/api/_pipes.py +85 -84
  48. meerschaum/connectors/api/_request.py +13 -9
  49. meerschaum/connectors/parse.py +27 -15
  50. meerschaum/core/Pipe/_bootstrap.py +16 -8
  51. meerschaum/core/Pipe/_sync.py +3 -0
  52. meerschaum/jobs/_Executor.py +69 -0
  53. meerschaum/jobs/_Job.py +899 -0
  54. meerschaum/jobs/__init__.py +396 -0
  55. meerschaum/jobs/systemd.py +694 -0
  56. meerschaum/plugins/__init__.py +97 -12
  57. meerschaum/utils/daemon/Daemon.py +352 -147
  58. meerschaum/utils/daemon/FileDescriptorInterceptor.py +19 -10
  59. meerschaum/utils/daemon/RotatingFile.py +22 -8
  60. meerschaum/utils/daemon/StdinFile.py +121 -0
  61. meerschaum/utils/daemon/__init__.py +42 -27
  62. meerschaum/utils/daemon/_names.py +15 -13
  63. meerschaum/utils/formatting/__init__.py +83 -37
  64. meerschaum/utils/formatting/_jobs.py +146 -55
  65. meerschaum/utils/formatting/_shell.py +6 -0
  66. meerschaum/utils/misc.py +41 -22
  67. meerschaum/utils/packages/__init__.py +21 -15
  68. meerschaum/utils/packages/_packages.py +9 -6
  69. meerschaum/utils/process.py +9 -9
  70. meerschaum/utils/prompt.py +20 -7
  71. meerschaum/utils/schedule.py +21 -15
  72. meerschaum/utils/venv/__init__.py +2 -2
  73. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/METADATA +22 -25
  74. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/RECORD +80 -70
  75. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/WHEEL +1 -1
  76. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/LICENSE +0 -0
  77. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/NOTICE +0 -0
  78. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/entry_points.txt +0 -0
  79. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/top_level.txt +0 -0
  80. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dist-info}/zip-safe +0 -0
@@ -8,6 +8,7 @@ Expose plugin management APIs from the `meerschaum.plugins` module.
8
8
 
9
9
  from __future__ import annotations
10
10
  import functools
11
+ import meerschaum as mrsm
11
12
  from meerschaum.utils.typing import Callable, Any, Union, Optional, Dict, List, Tuple
12
13
  from meerschaum.utils.threading import Lock, RLock
13
14
  from meerschaum.plugins._Plugin import Plugin
@@ -27,7 +28,8 @@ _locks = {
27
28
  'PLUGINS_INTERNAL_LOCK_PATH': RLock(),
28
29
  }
29
30
  __all__ = (
30
- "Plugin", "make_action", "api_plugin", "dash_plugin", "import_plugins",
31
+ "Plugin", "make_action", "api_plugin", "dash_plugin", "web_page",
32
+ "import_plugins", "from_plugin_import",
31
33
  "reload_plugins", "get_plugins", "get_data_plugins", "add_plugin_argument",
32
34
  "pre_sync_hook", "post_sync_hook",
33
35
  )
@@ -36,12 +38,12 @@ __pdoc__ = {
36
38
  }
37
39
 
38
40
  def make_action(
39
- function: Callable[[Any], Any],
40
- shell: bool = False,
41
- activate: bool = True,
42
- deactivate: bool = True,
43
- debug: bool = False
44
- ) -> Callable[[Any], Any]:
41
+ function: Callable[[Any], Any],
42
+ shell: bool = False,
43
+ activate: bool = True,
44
+ deactivate: bool = True,
45
+ debug: bool = False
46
+ ) -> Callable[[Any], Any]:
45
47
  """
46
48
  Make a function a Meerschaum action. Useful for plugins that are adding multiple actions.
47
49
 
@@ -429,11 +431,11 @@ def sync_plugins_symlinks(debug: bool = False, warn: bool = True) -> None:
429
431
 
430
432
 
431
433
  def import_plugins(
432
- *plugins_to_import: Union[str, List[str], None],
433
- warn: bool = True,
434
- ) -> Union[
435
- 'ModuleType', Tuple['ModuleType', None]
436
- ]:
434
+ *plugins_to_import: Union[str, List[str], None],
435
+ warn: bool = True,
436
+ ) -> Union[
437
+ 'ModuleType', Tuple['ModuleType', None]
438
+ ]:
437
439
  """
438
440
  Import the Meerschaum plugins directory.
439
441
 
@@ -524,6 +526,89 @@ def import_plugins(
524
526
  return imported_plugins
525
527
 
526
528
 
529
+ def from_plugin_import(plugin_import_name: str, *attrs: str) -> Any:
530
+ """
531
+ Emulate the `from module import x` behavior.
532
+
533
+ Parameters
534
+ ----------
535
+ plugin_import_name: str
536
+ The import name of the plugin's module.
537
+ Separate submodules with '.' (e.g. 'compose.utils.pipes')
538
+
539
+ attrs: str
540
+ Names of the attributes to return.
541
+
542
+ Returns
543
+ -------
544
+ Objects from a plugin's submodule.
545
+ If multiple objects are provided, return a tuple.
546
+
547
+ Examples
548
+ --------
549
+ >>> init = from_plugin_import('compose.utils', 'init')
550
+ >>> with mrsm.Venv('compose'):
551
+ ... cf = init()
552
+ >>> build_parent_pipe, get_defined_pipes = from_plugin_import(
553
+ ... 'compose.utils.pipes',
554
+ ... 'build_parent_pipe',
555
+ ... 'get_defined_pipes',
556
+ ... )
557
+ >>> parent_pipe = build_parent_pipe(cf)
558
+ >>> defined_pipes = get_defined_pipes(cf)
559
+ """
560
+ import importlib
561
+ from meerschaum.config._paths import PLUGINS_RESOURCES_PATH
562
+ from meerschaum.utils.warnings import warn as _warn
563
+ if plugin_import_name.startswith('plugins.'):
564
+ plugin_import_name = plugin_import_name[len('plugins.'):]
565
+ plugin_import_parts = plugin_import_name.split('.')
566
+ plugin_root_name = plugin_import_parts[0]
567
+ plugin = mrsm.Plugin(plugin_root_name)
568
+
569
+ submodule_import_name = '.'.join(
570
+ [PLUGINS_RESOURCES_PATH.stem]
571
+ + plugin_import_parts
572
+ )
573
+ if len(attrs) == 0:
574
+ raise ValueError(f"Provide which attributes to return from '{submodule_import_name}'.")
575
+
576
+ attrs_to_return = []
577
+ with mrsm.Venv(plugin):
578
+ if plugin.module is None:
579
+ return None
580
+
581
+ try:
582
+ submodule = importlib.import_module(submodule_import_name)
583
+ except ImportError as e:
584
+ _warn(
585
+ f"Failed to import plugin '{submodule_import_name}':\n "
586
+ + f"{e}\n\nHere's a stacktrace:",
587
+ stack=False,
588
+ )
589
+ from meerschaum.utils.formatting import get_console
590
+ get_console().print_exception(
591
+ suppress=[
592
+ 'meerschaum/plugins/__init__.py',
593
+ importlib,
594
+ importlib._bootstrap,
595
+ ]
596
+ )
597
+ return None
598
+
599
+ for attr in attrs:
600
+ try:
601
+ attrs_to_return.append(getattr(submodule, attr))
602
+ except Exception:
603
+ _warn(f"Failed to access '{attr}' from '{submodule_import_name}'.")
604
+ attrs_to_return.append(None)
605
+
606
+ if len(attrs) == 1:
607
+ return attrs_to_return[0]
608
+
609
+ return tuple(attrs_to_return)
610
+
611
+
527
612
  def load_plugins(debug: bool = False, shell: bool = False) -> None:
528
613
  """
529
614
  Import Meerschaum plugins and update the actions dictionary.