-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Prevent CLI from loading on import of robyn module #801
Comments
Hey @LilyRose2798 👋 Thanks for creating this issues and bringing this to my attention.
Let me dive a bit deeper and come back with an approach to tackle this. |
IMO, The one way we can tackle this is to rewrite Robyn whole CLI api, where we expose the functions like |
A way around the issue I found that isn't ideal is to move the Robyn import to after I've declared my own from argparse import ArgumentParser, Namespace
parser = ArgumentParser("myapi")
parser.add_argument("-a", "--address", default = "127.0.0.1", help = "the address to use for the api (default: %(default)s)")
parser.add_argument("-p", "--port", default = 8000, type = int, help = "the port to use for the api (default: %(default)s)")
parser.add_argument("-l", "--limit", default = 3600, type = int, help = "the number of requests per hour to limit usage of the api to (default: %(default)s)")
parser.add_argument("--processes", default = 1, type = int, help = "the number of processes to use for the api (default: %(default)s)")
parser.add_argument("--workers", default = 1, type = int, help = "the number of workers to use for the api (default: %(default)s)")
parser.add_argument("--log-level", default = "INFO", help = "the log level use for the api (default: %(default)s)")
args = parser.parse_args()
from robyn import Robyn
app = Robyn(__file__, Namespace(**{
"processes": args.processes,
"workers": args.workers,
"dev": False,
"create": False,
"docs": False,
"open_browser": False,
"version": False,
"compile_rust_path": None,
"create_rust_file": None,
"log_level": args.log_level,
}))
# API routes declared here...
app.start(host = args.address, port = args.port) |
@LilyRose2798 , this seems a bit too complicated. I am thinking of just adding an override args flag and then add the ability the ability to pass through the app.start |
It currently looks to be impossible to implement your own argument parser when using Robyn, as just importing the
robyn
module creates its ownArgumentParser
. I do not think that simply importing a module should have this behavior, and that you should have to pass a flag to theRobyn
constructor in order for it to create theArgumentParser
instance. You should also be able to create your ownConfig
object containing all the values likeprocesses
,workers
, etc when initializingRobyn
, so that if you have your own args or other way of getting these values, then you can pass them through. I'm currently having to do this in the following way:So a better way of doing this would be desirable.
The text was updated successfully, but these errors were encountered: