-
-
Notifications
You must be signed in to change notification settings - Fork 64
fix: add click compatibility layer for CLI alias support #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #645 +/- ##
==========================================
+ Coverage 80.44% 80.61% +0.17%
==========================================
Files 87 88 +1
Lines 6453 6553 +100
Branches 838 850 +12
==========================================
+ Hits 5191 5283 +92
- Misses 998 1003 +5
- Partials 264 267 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d8fb342 to
478cd78
Compare
import datetime
from litestar import Litestar
from litestar.handlers.http_handlers.decorators import get
from sqlalchemy.orm import Mapped
from advanced_alchemy.base import UUIDBase
from advanced_alchemy.config import AsyncSessionConfig
from advanced_alchemy.extensions.litestar.plugins import SQLAlchemyAsyncConfig, SQLAlchemyPlugin
@get("/test")
async def test_handler() -> dict[str, str]:
return {"message": "test"}
class AuthorModel(UUIDBase):
__tablename__ = "author"
name: Mapped[str]
dob: Mapped[datetime.date]
session_config = AsyncSessionConfig(expire_on_commit=False)
alchemy_config = SQLAlchemyAsyncConfig(
connection_string="sqlite+aiosqlite:///test.sqlite",
session_config=session_config,
create_all=True,
)
app = Litestar(
route_handlers=[test_handler],
plugins=[SQLAlchemyPlugin(config=alchemy_config)],
) |
|
Its says |
|
@Harshal6927 Give it another look now |
The `aliases` parameter in click groups is a rich-click 1.9+ feature that causes failures when users have only plain click installed or older rich-click versions. This commit introduces a compatibility layer that provides alias support across all environments. Changes: - Add `advanced_alchemy/utils/cli_tools.py` with: - `AliasedGroup` class that mimics rich-click's alias handling - `group()` and `command()` wrappers that auto-select the right class - Detection constants for rich-click availability and alias support - Update all CLI modules to use the compatibility layer: - `advanced_alchemy/cli.py` - `advanced_alchemy/extensions/fastapi/cli.py` - `advanced_alchemy/extensions/flask/cli.py` - `advanced_alchemy/extensions/litestar/cli.py` - Add comprehensive unit tests for the compatibility layer The CLI now works correctly with: - Plain click (no rich-click) - Old rich-click (< 1.9.0) - New rich-click (>= 1.9.0)
- Add **kwargs to AliasedGroup.add_command and _patched_add_command to ensure forward compatibility with future click API changes - Add comprehensive edge case tests: - Alias collision behavior (last-wins semantics) - Non-aliased command lookup verification - New rich-click child with plain click parent scenario - Command name not added to own alias mapping
|
This PR still causes |
Summary
advanced_alchemy/utils/cli_tools.py) that provides click alias support across all environmentsaliasesparameter in click groups is a rich-click 1.9+ feature that causesTypeErrorwhen users have plain click or older rich-clickAliasedGroupclass that mimics rich-click's alias handling for plain clickProblem
Users encounter failures when using the CLI in these scenarios:
Scenario A: Plain click (no rich-click)
Scenario B: Old rich-click (< 1.9.0)
Solution
Created
advanced_alchemy/utils/cli_tools.pywith:AliasedGroupclass that implements alias resolution for plain clickgroup()andcommand()wrapper decorators that auto-select the appropriate class_RICH_CLICK_AVAILABLE,_RICH_CLICK_ALIASES_SUPPORTED)Changes
advanced_alchemy/utils/cli_tools.pytests/unit/test_utils/test_click.pyadvanced_alchemy/cli.pyadvanced_alchemy/extensions/fastapi/cli.pyadvanced_alchemy/extensions/flask/cli.pyadvanced_alchemy/extensions/litestar/cli.pyTest plan
AliasedGroupclass