meerschaum 3.0.0rc3__py3-none-any.whl → 3.0.0rc7__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 (126) 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 +434 -0
  6. meerschaum/_internal/docs/index.py +1 -2
  7. meerschaum/_internal/entry.py +44 -8
  8. meerschaum/_internal/shell/Shell.py +113 -19
  9. meerschaum/_internal/shell/__init__.py +4 -1
  10. meerschaum/_internal/static.py +3 -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 +7 -2
  29. meerschaum/api/_oauth2.py +47 -4
  30. meerschaum/api/dash/callbacks/dashboard.py +103 -97
  31. meerschaum/api/dash/callbacks/jobs.py +3 -2
  32. meerschaum/api/dash/callbacks/login.py +10 -1
  33. meerschaum/api/dash/callbacks/pipes.py +136 -57
  34. meerschaum/api/dash/callbacks/register.py +9 -2
  35. meerschaum/api/dash/callbacks/tokens.py +2 -1
  36. meerschaum/api/dash/components.py +6 -7
  37. meerschaum/api/dash/keys.py +17 -1
  38. meerschaum/api/dash/pages/login.py +2 -2
  39. meerschaum/api/dash/pages/pipes.py +14 -4
  40. meerschaum/api/dash/pipes.py +186 -65
  41. meerschaum/api/dash/tokens.py +1 -1
  42. meerschaum/api/dash/webterm.py +14 -6
  43. meerschaum/api/models/_pipes.py +7 -1
  44. meerschaum/api/resources/static/js/terminado.js +3 -0
  45. meerschaum/api/resources/static/js/xterm-addon-unicode11.js +2 -0
  46. meerschaum/api/resources/templates/termpage.html +1 -0
  47. meerschaum/api/routes/_jobs.py +23 -11
  48. meerschaum/api/routes/_login.py +73 -5
  49. meerschaum/api/routes/_pipes.py +6 -4
  50. meerschaum/api/routes/_webterm.py +3 -3
  51. meerschaum/config/__init__.py +60 -13
  52. meerschaum/config/_default.py +89 -61
  53. meerschaum/config/_edit.py +10 -8
  54. meerschaum/config/_formatting.py +2 -0
  55. meerschaum/config/_patch.py +4 -2
  56. meerschaum/config/_paths.py +127 -12
  57. meerschaum/config/_read_config.py +20 -10
  58. meerschaum/config/_version.py +1 -1
  59. meerschaum/config/environment.py +262 -0
  60. meerschaum/config/stack/__init__.py +7 -5
  61. meerschaum/connectors/_Connector.py +1 -2
  62. meerschaum/connectors/__init__.py +37 -2
  63. meerschaum/connectors/api/_APIConnector.py +1 -1
  64. meerschaum/connectors/api/_jobs.py +11 -0
  65. meerschaum/connectors/api/_pipes.py +7 -1
  66. meerschaum/connectors/instance/_plugins.py +9 -1
  67. meerschaum/connectors/instance/_tokens.py +20 -3
  68. meerschaum/connectors/instance/_users.py +8 -1
  69. meerschaum/connectors/parse.py +1 -1
  70. meerschaum/connectors/sql/_create_engine.py +3 -0
  71. meerschaum/connectors/sql/_pipes.py +98 -79
  72. meerschaum/connectors/sql/_users.py +8 -1
  73. meerschaum/connectors/sql/tables/__init__.py +20 -3
  74. meerschaum/connectors/valkey/_ValkeyConnector.py +3 -3
  75. meerschaum/connectors/valkey/_pipes.py +7 -5
  76. meerschaum/core/Pipe/__init__.py +62 -72
  77. meerschaum/core/Pipe/_attributes.py +66 -90
  78. meerschaum/core/Pipe/_cache.py +555 -0
  79. meerschaum/core/Pipe/_clear.py +0 -11
  80. meerschaum/core/Pipe/_data.py +0 -50
  81. meerschaum/core/Pipe/_deduplicate.py +0 -13
  82. meerschaum/core/Pipe/_delete.py +12 -21
  83. meerschaum/core/Pipe/_drop.py +11 -23
  84. meerschaum/core/Pipe/_dtypes.py +1 -1
  85. meerschaum/core/Pipe/_index.py +8 -14
  86. meerschaum/core/Pipe/_sync.py +12 -18
  87. meerschaum/core/Plugin/_Plugin.py +7 -1
  88. meerschaum/core/Token/_Token.py +1 -1
  89. meerschaum/core/User/_User.py +1 -2
  90. meerschaum/jobs/_Executor.py +88 -4
  91. meerschaum/jobs/_Job.py +135 -35
  92. meerschaum/jobs/systemd.py +7 -2
  93. meerschaum/plugins/__init__.py +277 -81
  94. meerschaum/utils/_get_pipes.py +30 -4
  95. meerschaum/utils/daemon/Daemon.py +195 -41
  96. meerschaum/utils/daemon/FileDescriptorInterceptor.py +0 -1
  97. meerschaum/utils/daemon/RotatingFile.py +63 -36
  98. meerschaum/utils/daemon/StdinFile.py +53 -13
  99. meerschaum/utils/daemon/__init__.py +18 -5
  100. meerschaum/utils/daemon/_names.py +6 -3
  101. meerschaum/utils/debug.py +34 -4
  102. meerschaum/utils/dtypes/__init__.py +5 -1
  103. meerschaum/utils/formatting/__init__.py +4 -1
  104. meerschaum/utils/formatting/_jobs.py +1 -1
  105. meerschaum/utils/formatting/_pipes.py +47 -46
  106. meerschaum/utils/formatting/_pprint.py +1 -0
  107. meerschaum/utils/formatting/_shell.py +16 -6
  108. meerschaum/utils/misc.py +18 -38
  109. meerschaum/utils/packages/__init__.py +15 -13
  110. meerschaum/utils/packages/_packages.py +1 -0
  111. meerschaum/utils/pipes.py +39 -7
  112. meerschaum/utils/process.py +1 -1
  113. meerschaum/utils/prompt.py +171 -144
  114. meerschaum/utils/sql.py +12 -2
  115. meerschaum/utils/threading.py +42 -0
  116. meerschaum/utils/venv/__init__.py +2 -0
  117. meerschaum/utils/warnings.py +19 -13
  118. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/METADATA +3 -1
  119. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/RECORD +125 -119
  120. meerschaum/config/_environment.py +0 -145
  121. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/WHEEL +0 -0
  122. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/entry_points.txt +0 -0
  123. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/licenses/LICENSE +0 -0
  124. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/licenses/NOTICE +0 -0
  125. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/top_level.txt +0 -0
  126. {meerschaum-3.0.0rc3.dist-info → meerschaum-3.0.0rc7.dist-info}/zip-safe +0 -0
@@ -1,145 +0,0 @@
1
- #! /usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- # vim:fenc=utf-8
4
-
5
- """
6
- Patch the runtime configuration from environment variables.
7
- """
8
-
9
- import os
10
- import re
11
- import json
12
- from meerschaum.utils.typing import List, Union, Dict, Any
13
- from meerschaum._internal.static import STATIC_CONFIG
14
-
15
- def apply_environment_patches() -> None:
16
- """
17
- Apply patches defined in `MRSM_CONFIG` and `MRSM_PATCH`.
18
- """
19
- config_var = STATIC_CONFIG['environment']['config']
20
- patch_var = STATIC_CONFIG['environment']['patch']
21
- apply_environment_config(config_var)
22
- apply_environment_config(patch_var)
23
-
24
-
25
- def apply_environment_config(env_var: str) -> None:
26
- """
27
- Parse a dictionary (simple or JSON) from an environment variable
28
- and apply it to the current configuration.
29
- """
30
- from meerschaum.config import get_config, set_config, _config
31
- from meerschaum.config._patch import apply_patch_to_config
32
- if env_var not in os.environ:
33
- return
34
- from meerschaum.utils.misc import string_to_dict
35
- try:
36
- _patch = string_to_dict(str(os.environ[env_var]).lstrip())
37
- except Exception as e:
38
- _patch = None
39
- error_msg = (
40
- f"Environment variable {env_var} is set but cannot be parsed.\n"
41
- f"Unset {env_var} or change to JSON or simplified dictionary format " +
42
- "(see --help, under params for formatting)\n" +
43
- f"{env_var} is set to:\n{os.environ[env_var]}\n"
44
- f"Skipping patching os environment into config..."
45
- )
46
-
47
- if not isinstance(_patch, dict):
48
- print(error_msg)
49
- return
50
-
51
- valids = []
52
-
53
- def load_key(key: str) -> Union[Dict[str, Any], None]:
54
- try:
55
- c = get_config(key, warn=False)
56
- except Exception as e:
57
- c = None
58
- return c
59
-
60
- ### This was multi-threaded, but I ran into all sorts of locking issues.
61
- keys = list(_patch.keys())
62
- for key in keys:
63
- _ = load_key(key)
64
-
65
- ### Load and patch config files.
66
- set_config(
67
- apply_patch_to_config(
68
- _config(),
69
- _patch,
70
- )
71
- )
72
-
73
-
74
- def apply_environment_uris() -> None:
75
- """
76
- Patch temporary connectors defined in environment variables which start with
77
- `MRSM_SQL_` or `MRSM_API_`.
78
- """
79
- for env_var in get_connector_env_vars():
80
- apply_connector_uri(env_var)
81
-
82
-
83
- def get_connector_env_regex() -> str:
84
- """
85
- Return the regex pattern for valid environment variable names for instance connectors.
86
- """
87
- return STATIC_CONFIG['environment']['uri_regex']
88
-
89
-
90
- def get_connector_env_vars() -> List[str]:
91
- """
92
- Get the names of the environment variables which match the Meerschaum connector regex.
93
-
94
- Examples
95
- --------
96
- >>> get_connector_environment_vars()
97
- ['MRSM_SQL_FOO']
98
- """
99
- uri_regex = get_connector_env_regex()
100
- env_vars = []
101
- for env_var in os.environ:
102
- matched = re.match(uri_regex, env_var)
103
- if matched is None:
104
- continue
105
- if env_var in STATIC_CONFIG['environment'].values():
106
- continue
107
- env_vars.append(env_var)
108
- return env_vars
109
-
110
-
111
- def apply_connector_uri(env_var: str) -> None:
112
- """
113
- Parse and validate a URI obtained from an environment variable.
114
- """
115
- from meerschaum.config import get_config, set_config, _config
116
- from meerschaum.config._patch import apply_patch_to_config
117
- from meerschaum.config._read_config import search_and_substitute_config
118
- from meerschaum.utils.warnings import warn
119
- uri_regex = get_connector_env_regex()
120
- matched = re.match(uri_regex, env_var)
121
- groups = matched.groups()
122
- typ, label = groups[0].lower(), groups[1].lower()
123
- uri = os.environ[env_var]
124
- if uri.lstrip().startswith('{') and uri.rstrip().endswith('}'):
125
- try:
126
- conn_attrs = json.loads(uri)
127
- except Exception as e:
128
- warn(f"Unable to parse JSON for environment connector '{typ}:{label}'.")
129
- conn_attrs = {'uri': uri}
130
- else:
131
- conn_attrs = {'uri': uri}
132
- set_config(
133
- apply_patch_to_config(
134
- {'meerschaum': get_config('meerschaum')},
135
- {'meerschaum': {'connectors': {typ: {label: conn_attrs}}}},
136
- )
137
- )
138
-
139
-
140
- def get_env_vars() -> List[str]:
141
- """
142
- Return all environment variables which begin with `'MRSM_'`.
143
- """
144
- prefix = STATIC_CONFIG['environment']['prefix']
145
- return sorted([env_var for env_var in os.environ if env_var.startswith(prefix)])