sqlseed-cli 0.2.4__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.
@@ -0,0 +1,66 @@
1
+ """Public API exports for the sqlseed-cli package.
2
+
3
+ This package provides the ``sqlseed`` console command. The entry point
4
+ ``sqlseed = "sqlseed_cli:main"`` is declared in ``pyproject.toml``.
5
+
6
+ AI subcommand injection
7
+ -----------------------
8
+ Third-party packages (notably ``sqlseed-ai``) may register additional CLI
9
+ subcommands by exposing an entry point in the ``sqlseed.cli_commands``
10
+ group. Each entry point must resolve to a callable with the signature
11
+ ``register(cli_group: click.Group) -> None``. This module discovers and
12
+ invokes all such callables at import time so that installing
13
+ ``sqlseed-ai`` is sufficient to make ``ai-suggest`` appear under the
14
+ ``sqlseed`` command — no source-level import is required.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from importlib.metadata import entry_points
20
+
21
+ from sqlseed_cli.main import cli, main
22
+
23
+ from sqlseed._utils.logger import get_logger
24
+
25
+ __all__ = ["cli", "main"]
26
+
27
+ _logger = get_logger(__name__)
28
+
29
+
30
+ def _register_plugin_commands() -> None:
31
+ """Discover and register CLI subcommands contributed by other packages.
32
+
33
+ Iterates the ``sqlseed.cli_commands`` entry-point group. Each entry
34
+ point resolves to a callable ``register(cli_group: click.Group) -> None``.
35
+ Failures are logged at WARNING level (not silently swallowed) so users
36
+ can diagnose missing subcommands without setting SQLSEED_LOG_LEVEL=DEBUG.
37
+ """
38
+ eps = entry_points(group="sqlseed.cli_commands")
39
+
40
+ for ep in eps:
41
+ try:
42
+ register = ep.load()
43
+ register(cli)
44
+ except (
45
+ ImportError,
46
+ AttributeError,
47
+ TypeError,
48
+ ValueError,
49
+ RuntimeError,
50
+ OSError,
51
+ ) as exc:
52
+ # A failing plugin must never break the core CLI, but a warning
53
+ # makes the failure visible by default so users can diagnose
54
+ # missing subcommands (e.g. ai-suggest not appearing because
55
+ # sqlseed-ai failed to load). Specific exception types are caught
56
+ # rather than bare Exception to avoid suppressing BaseException
57
+ # subclasses (KeyboardInterrupt, SystemExit) and to make the
58
+ # resilience contract explicit.
59
+ _logger.warning(
60
+ "Failed to load CLI plugin entry point",
61
+ entry_point=ep.name,
62
+ error=str(exc),
63
+ )
64
+
65
+
66
+ _register_plugin_commands()
sqlseed_cli/_utils.py ADDED
@@ -0,0 +1,22 @@
1
+ """Shared CLI utility functions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from typing import Any
7
+
8
+
9
+ def sanitize_table_config(config_dict: dict[str, Any]) -> None:
10
+ """Remove leading dots/colons from table and column names in config dict.
11
+
12
+ Args:
13
+ config_dict: Configuration dictionary to sanitize in-place.
14
+ """
15
+ name = config_dict.get("name")
16
+ if isinstance(name, str):
17
+ config_dict["name"] = re.sub(r"^[:.]+", "", name)
18
+ for col in config_dict.get("columns", []):
19
+ if isinstance(col, dict):
20
+ col_name = col.get("name")
21
+ if isinstance(col_name, str):
22
+ col["name"] = re.sub(r"^[:.]+", "", col_name)