meerschaum 2.2.6__py3-none-any.whl → 2.3.0.dev1__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 (61) hide show
  1. meerschaum/__init__.py +4 -1
  2. meerschaum/__main__.py +10 -5
  3. meerschaum/_internal/arguments/_parser.py +44 -15
  4. meerschaum/_internal/entry.py +35 -14
  5. meerschaum/_internal/shell/Shell.py +155 -53
  6. meerschaum/_internal/shell/updates.py +175 -0
  7. meerschaum/actions/api.py +12 -12
  8. meerschaum/actions/attach.py +95 -0
  9. meerschaum/actions/delete.py +35 -26
  10. meerschaum/actions/register.py +19 -5
  11. meerschaum/actions/show.py +119 -148
  12. meerschaum/actions/start.py +85 -75
  13. meerschaum/actions/stop.py +68 -39
  14. meerschaum/actions/sync.py +3 -3
  15. meerschaum/actions/upgrade.py +28 -36
  16. meerschaum/api/_events.py +18 -1
  17. meerschaum/api/_oauth2.py +2 -0
  18. meerschaum/api/_websockets.py +2 -2
  19. meerschaum/api/dash/jobs.py +5 -2
  20. meerschaum/api/routes/__init__.py +1 -0
  21. meerschaum/api/routes/_actions.py +122 -44
  22. meerschaum/api/routes/_jobs.py +340 -0
  23. meerschaum/api/routes/_pipes.py +25 -25
  24. meerschaum/config/_default.py +1 -0
  25. meerschaum/config/_formatting.py +1 -0
  26. meerschaum/config/_paths.py +5 -0
  27. meerschaum/config/_shell.py +84 -67
  28. meerschaum/config/_version.py +1 -1
  29. meerschaum/config/static/__init__.py +9 -0
  30. meerschaum/connectors/__init__.py +9 -11
  31. meerschaum/connectors/api/APIConnector.py +18 -1
  32. meerschaum/connectors/api/_actions.py +60 -71
  33. meerschaum/connectors/api/_jobs.py +260 -0
  34. meerschaum/connectors/api/_misc.py +1 -1
  35. meerschaum/connectors/api/_request.py +13 -9
  36. meerschaum/connectors/parse.py +23 -7
  37. meerschaum/core/Pipe/_sync.py +3 -0
  38. meerschaum/plugins/__init__.py +89 -5
  39. meerschaum/utils/daemon/Daemon.py +333 -149
  40. meerschaum/utils/daemon/FileDescriptorInterceptor.py +19 -10
  41. meerschaum/utils/daemon/RotatingFile.py +18 -7
  42. meerschaum/utils/daemon/StdinFile.py +110 -0
  43. meerschaum/utils/daemon/__init__.py +40 -27
  44. meerschaum/utils/formatting/__init__.py +83 -37
  45. meerschaum/utils/formatting/_jobs.py +118 -51
  46. meerschaum/utils/formatting/_shell.py +6 -0
  47. meerschaum/utils/jobs/_Job.py +684 -0
  48. meerschaum/utils/jobs/__init__.py +245 -0
  49. meerschaum/utils/misc.py +18 -17
  50. meerschaum/utils/packages/__init__.py +21 -15
  51. meerschaum/utils/packages/_packages.py +2 -2
  52. meerschaum/utils/prompt.py +20 -7
  53. meerschaum/utils/schedule.py +21 -15
  54. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.dist-info}/METADATA +9 -9
  55. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.dist-info}/RECORD +61 -54
  56. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.dist-info}/WHEEL +1 -1
  57. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.dist-info}/LICENSE +0 -0
  58. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.dist-info}/NOTICE +0 -0
  59. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.dist-info}/entry_points.txt +0 -0
  60. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.dist-info}/top_level.txt +0 -0
  61. {meerschaum-2.2.6.dist-info → meerschaum-2.3.0.dev1.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
@@ -429,11 +430,11 @@ def sync_plugins_symlinks(debug: bool = False, warn: bool = True) -> None:
429
430
 
430
431
 
431
432
  def import_plugins(
432
- *plugins_to_import: Union[str, List[str], None],
433
- warn: bool = True,
434
- ) -> Union[
435
- 'ModuleType', Tuple['ModuleType', None]
436
- ]:
433
+ *plugins_to_import: Union[str, List[str], None],
434
+ warn: bool = True,
435
+ ) -> Union[
436
+ 'ModuleType', Tuple['ModuleType', None]
437
+ ]:
437
438
  """
438
439
  Import the Meerschaum plugins directory.
439
440
 
@@ -524,6 +525,89 @@ def import_plugins(
524
525
  return imported_plugins
525
526
 
526
527
 
528
+ def from_plugin_import(plugin_import_name: str, *attrs: str) -> Any:
529
+ """
530
+ Emulate the `from module import x` behavior.
531
+
532
+ Parameters
533
+ ----------
534
+ plugin_import_name: str
535
+ The import name of the plugin's module.
536
+ Separate submodules with '.' (e.g. 'compose.utils.pipes')
537
+
538
+ attrs: str
539
+ Names of the attributes to return.
540
+
541
+ Returns
542
+ -------
543
+ Objects from a plugin's submodule.
544
+ If multiple objects are provided, return a tuple.
545
+
546
+ Examples
547
+ --------
548
+ >>> init = from_plugin_import('compose.utils', 'init')
549
+ >>> with mrsm.Venv('compose'):
550
+ ... cf = init()
551
+ >>> build_parent_pipe, get_defined_pipes = from_plugin_import(
552
+ ... 'compose.utils.pipes',
553
+ ... 'build_parent_pipe',
554
+ ... 'get_defined_pipes',
555
+ ... )
556
+ >>> parent_pipe = build_parent_pipe(cf)
557
+ >>> defined_pipes = get_defined_pipes(cf)
558
+ """
559
+ import importlib
560
+ from meerschaum.config._paths import PLUGINS_RESOURCES_PATH
561
+ from meerschaum.utils.warnings import warn as _warn
562
+ if plugin_import_name.startswith('plugins.'):
563
+ plugin_import_name = plugin_import_name[len('plugins.'):]
564
+ plugin_import_parts = plugin_import_name.split('.')
565
+ plugin_root_name = plugin_import_parts[0]
566
+ plugin = mrsm.Plugin(plugin_root_name)
567
+
568
+ submodule_import_name = '.'.join(
569
+ [PLUGINS_RESOURCES_PATH.stem]
570
+ + plugin_import_parts
571
+ )
572
+ if len(attrs) == 0:
573
+ raise ValueError(f"Provide which attributes to return from '{submodule_import_name}'.")
574
+
575
+ attrs_to_return = []
576
+ with mrsm.Venv(plugin):
577
+ if plugin.module is None:
578
+ return None
579
+
580
+ try:
581
+ submodule = importlib.import_module(submodule_import_name)
582
+ except ImportError as e:
583
+ _warn(
584
+ f"Failed to import plugin '{submodule_import_name}':\n "
585
+ + f"{e}\n\nHere's a stacktrace:",
586
+ stack=False,
587
+ )
588
+ from meerschaum.utils.formatting import get_console
589
+ get_console().print_exception(
590
+ suppress=[
591
+ 'meerschaum/plugins/__init__.py',
592
+ importlib,
593
+ importlib._bootstrap,
594
+ ]
595
+ )
596
+ return None
597
+
598
+ for attr in attrs:
599
+ try:
600
+ attrs_to_return.append(getattr(submodule, attr))
601
+ except Exception:
602
+ _warn(f"Failed to access '{attr}' from '{submodule_import_name}'.")
603
+ attrs_to_return.append(None)
604
+
605
+ if len(attrs) == 1:
606
+ return attrs_to_return[0]
607
+
608
+ return tuple(attrs_to_return)
609
+
610
+
527
611
  def load_plugins(debug: bool = False, shell: bool = False) -> None:
528
612
  """
529
613
  Import Meerschaum plugins and update the actions dictionary.