-
-
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
Open
cofin
wants to merge
2
commits into
litestar-org:main
Choose a base branch
from
cofin:fix/cli-alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #645 +/- ##
==========================================
+ Coverage 80.42% 80.56% +0.14%
==========================================
Files 87 88 +1
Lines 6431 6531 +100
Branches 838 850 +12
==========================================
+ Hits 5172 5262 +90
- Misses 995 1001 +6
- Partials 264 268 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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)
Member
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)],
) |
Member
|
Its says |
Member
Author
|
@Harshal6927 Give it another look now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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