Skip to content
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

Better handling of nested meta apps #291

Merged
merged 2 commits into from
Jan 10, 2025
Merged

Better handling of nested meta apps #291

merged 2 commits into from
Jan 10, 2025

Conversation

BrianPugh
Copy link
Owner

@AngellusMortis can you play around with this? I think the following script (along with this PR) is kind of what you want:

from cyclopts import App, Parameter
from typing import Annotated

app_1 = App()

@app_1.meta.default
def meta_1(*tokens: Annotated[str, Parameter(show=False, allow_leading_hyphen=True)]) -> None:
    """This is app1_meta's help."""
    print("child meta")
    app_1(tokens)

@app_1.command
def test() -> None:
    """"app_1 test" help string."""
    print("app_1 test body")

app = App()
app.command(app_1.meta, name="app1")

@app.meta.default
def meta(*tokens: Annotated[str, Parameter(show=False, allow_leading_hyphen=True)]):
    print("parent meta")
    app(tokens)

if __name__ == "__main__":
    app.meta()

Comments:

  • meta apps don't execute for --help. This is intentional as frequently expensive operations are performed in a meta app, such as connecting to an external resource (like a database).
  • meta apps do execute during conventional command execution.
  • The tokens in the meta signature is copied from the meta app docs.

Addresses #290.

@BrianPugh BrianPugh changed the title Nested meta apps Better handling of nested meta apps Jan 9, 2025
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.99%. Comparing base (a898634) to head (840a197).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
+ Coverage   93.83%   93.99%   +0.15%     
==========================================
  Files          26       26              
  Lines        3019     3030      +11     
  Branches      636      639       +3     
==========================================
+ Hits         2833     2848      +15     
+ Misses         90       88       -2     
+ Partials       96       94       -2     
Flag Coverage Δ
unittests 93.99% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AngellusMortis
Copy link

Looks like it works!

@BrianPugh
Copy link
Owner Author

I'll be trying to do a patch release this weekend including this; I want to get some other fixes in with it.

@BrianPugh BrianPugh merged commit 139d12d into main Jan 10, 2025
17 checks passed
@BrianPugh BrianPugh deleted the nested-meta-apps branch January 10, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants