Skip to content

Commit

Permalink
fixes #654
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Jun 17, 2024
1 parent c93d8f9 commit 9dce07a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
36 changes: 19 additions & 17 deletions robyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from robyn import status_codes
from robyn.argument_parser import Config
from robyn.authentication import AuthenticationHandler
from robyn.cli import start_dev_server
from robyn.dependency_injection import DependencyMap
from robyn.env_populator import load_vars
from robyn.events import Events
Expand Down Expand Up @@ -56,8 +57,6 @@ def __init__(
"SERVER IS RUNNING IN VERBOSE/DEBUG MODE. Set --log-level to WARN to run in production mode.",
color=Colors.BLUE,
)
if self.config.dev:
exit("Dev mode is not supported in the python wrapper. Please use the CLI. e.g. python3 -m robyn app.py --dev ")

self.router = Router()
self.middleware_router = MiddlewareRouter()
Expand Down Expand Up @@ -225,21 +224,24 @@ def start(self, host: str = "127.0.0.1", port: int = 8080, _check_port: bool = T

mp.allow_connection_pickling()

run_processes(
host,
port,
self.directories,
self.request_headers,
self.router.get_routes(),
self.middleware_router.get_global_middlewares(),
self.middleware_router.get_route_middlewares(),
self.web_socket_router.get_routes(),
self.event_handlers,
self.config.workers,
self.config.processes,
self.response_headers,
open_browser,
)
if self.config.dev:
start_dev_server(self.config, self.config.file_path)
else:
run_processes(
host,
port,
self.directories,
self.request_headers,
self.router.get_routes(),
self.middleware_router.get_global_middlewares(),
self.middleware_router.get_route_middlewares(),
self.web_socket_router.get_routes(),
self.event_handlers,
self.config.workers,
self.config.processes,
self.response_headers,
open_browser,
)

def exception(self, exception_handler: Callable):
self.exception_handler = exception_handler
Expand Down
18 changes: 13 additions & 5 deletions robyn/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def __init__(self) -> None:
default=False,
help="Development mode. It restarts the server based on file changes.",
)
parser.add_argument(
"--file",
dest="file_path",
default=None,
help="The file associated.",
)
parser.add_argument(
"--log-level",
dest="log_level",
Expand Down Expand Up @@ -75,18 +81,20 @@ def __init__(self) -> None:
self.processes = args.processes
self.workers = args.workers
self.dev = args.dev
self.file_path = args.file_path
self.create = args.create
self.docs = args.docs
self.open_browser = args.open_browser
self.version = args.version
self.compile_rust_path = args.compile_rust_path
self.create_rust_file = args.create_rust_file

# find something that ends with .py in unknown_args
for arg in unknown_args:
if arg.endswith(".py"):
self.file_path = arg
break
if self.file_path is None:
# find something that ends with .py in unknown_args
for arg in unknown_args:
if arg.endswith(".py"):
self.file_path = arg
break

if self.dev and (self.processes != 1 or self.workers != 1):
raise Exception("--processes and --workers shouldn't be used with --dev")
Expand Down

0 comments on commit 9dce07a

Please sign in to comment.