Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Jul 15, 2024
1 parent 394024f commit 606588a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pathlib

from collections import defaultdict
from typing import Optional

Expand Down
18 changes: 11 additions & 7 deletions robyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import socket
import sys
from typing import Callable, List, Optional, Tuple, Union

import multiprocess as mp
Expand All @@ -18,8 +19,10 @@
from robyn.processpool import run_processes
from robyn.reloader import compile_rust_files
from robyn.responses import html, serve_file, serve_html
from robyn.robyn import FunctionInfo, Headers, HttpMethod, Request, Response, WebSocketConnector, get_version
from robyn.router import MiddlewareRouter, MiddlewareType, Router, WebSocketRouter
from robyn.robyn import (FunctionInfo, Headers, HttpMethod, Request, Response,
WebSocketConnector, get_version)
from robyn.router import (MiddlewareRouter, MiddlewareType, Router,
WebSocketRouter)
from robyn.types import Directory
from robyn.ws import WebSocket

Expand Down Expand Up @@ -48,9 +51,10 @@ def __init__(
self.config = config
self.dependencies = dependencies

self._handle_dev_mode()
if 'robyn' in os.path.basename(sys.argv[0]).lower():
# the env variables are already set when are running through the cli
load_vars(project_root=directory_path)

load_vars(project_root=directory_path)
logging.basicConfig(level=self.config.log_level)

if self.config.log_level.lower() != "warn":
Expand All @@ -74,13 +78,13 @@ def _handle_dev_mode(self):
env_dev_mode = os.getenv("ROBYN_DEV_MODE", "False").lower() == "true"
# if we have reached here and we have ROBYN_DEV_MODE set to True
# we understand that we are operating in CLI mode and not through the ROBYN MODULE

if cli_dev_mode:
raise SystemExit("Dev mode is not supported in the python wrapper. Please use the CLI. e.g. python3 -m robyn app.py --dev")
raise SystemExit("Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py --dev")

if env_dev_mode:
logger.info(f"{cli_dev_mode=}")
logger.error("Ignoring ROBYN_DEV_MODE environment variable. Dev mode is not supported in the python wrapper.")
logger.warn("Starting app normally...")
raise SystemExit("Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py --dev")

def add_route(
self,
Expand Down
4 changes: 3 additions & 1 deletion robyn/reloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def stop_server(self):

def reload(self):
self.stop_server()
print("Reloading the server")

new_env = os.environ.copy()
new_env["IS_RELOADER_RUNNING"] = "True" # This is used to check if a reloader is already running
Expand All @@ -116,8 +117,9 @@ def reload(self):
# child processes should not be in dev mode, i.e. can be killed by the reloader
del new_env["ROBYN_DEV_MODE"]

print(f"Reloading {self.file_path}...")
# print(f"Reloading {self.file_path}...", new_env["ROBYN_DEV_MODE"])
arguments = [arg for arg in sys.argv[1:] if not arg.startswith("--dev")]
print("argumens")

clean_rust_binaries(self.built_rust_binaries)
self.built_rust_binaries = compile_rust_files(self.directory_path)
Expand Down

0 comments on commit 606588a

Please sign in to comment.