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

A more customisable CLI and REPL #3018

Open
1 task done
goodki-d opened this issue Dec 24, 2024 · 6 comments
Open
1 task done

A more customisable CLI and REPL #3018

goodki-d opened this issue Dec 24, 2024 · 6 comments
Assignees

Comments

@goodki-d
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

No response

Describe the solution you'd like

Sanic CLI currently has options for different run configurations.
Requested:

  • Ability to add custom commands for application related workflows. With application context available to the command.

Usage can be similar to how inspector commands are created currently.

Sanic REPL currently provides 4 objects by default In the repl context.
Requested:

  • Ability to add/inject additional objects to the repl context.
  • Ability to prepare REPL context. (e.g. pre importing modules, models)

Thanks

Additional context

No response

@goodki-d
Copy link
Author

REPL was one of the best feature added for developer experience imo. Being able to have some models/classes pre-imported or adding custom utility objects would be great. I'd love to contribute too.

@ahopkins ahopkins self-assigned this Dec 31, 2024
@ahopkins
Copy link
Member

The CLI bit I was planning for a long time. The how of it was always the concern, but I figured that out. Stay tuned.

I like the REPL injection idea also.

@ahopkins
Copy link
Member

See #3019

If the REPL idea is something you'd like to work on @goodki-d, LMK.

@goodki-d
Copy link
Author

goodki-d commented Jan 1, 2025

Yes! I'd love to work on it. I have some approaches in mind

@ahopkins
Copy link
Member

ahopkins commented Jan 1, 2025

Excellent. What was your thought? It's going to be a bit of a challenge as you are diving deep into the process manager internals. Maybe ping me on the Discord server and we can brainstorm?

@goodki-d
Copy link
Author

goodki-d commented Jan 2, 2025

Sure, lets connect on discord!

I was not sure about the process manager here. I assumed REPL was running on the main process.

sanic/sanic/cli/app.py

Lines 183 to 186 in a575f5c

@app.main_process_ready
async def start_repl(app):
SanicREPL(app, self.args.repl).run()
await app._startup()


I was thinking If we could merge the user supplied variables with the currently available locals

- super().__init__(locals=locals_available)
+ super().__init__(locals={**locals_available, **user_locals})

and generating the variable description to show dynamically.

For the user API, I was thinking of something like

from sanic import Sanic
app = Sanic(...)

# variable == module/class/object/callable
app.repl.add_local(variable, "<name>", "desc")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants