@@ -189,11 +189,9 @@ def run_frontend_prod(root: Path, port: str, backend_present: bool = True):
189189
190190@once
191191def _warn_user_about_uvicorn ():
192- # When we eventually switch to Granian by default, we should enable this warning.
193- if False :
194- console .warn (
195- "Using Uvicorn for backend as it is installed. This behavior will change in 0.8.0 to use Granian by default."
196- )
192+ console .warn (
193+ "Using Uvicorn for backend as it is installed. This behavior will change in 0.8.0 to use Granian by default."
194+ )
197195
198196
199197def should_use_granian ():
@@ -202,8 +200,8 @@ def should_use_granian():
202200 Returns:
203201 True if Granian should be used.
204202 """
205- if environment .REFLEX_USE_GRANIAN .get ():
206- return True
203+ if environment .REFLEX_USE_GRANIAN .is_set ():
204+ return environment . REFLEX_USE_GRANIAN . get ()
207205 if (
208206 importlib .util .find_spec ("uvicorn" ) is None
209207 or importlib .util .find_spec ("gunicorn" ) is None
@@ -219,9 +217,51 @@ def get_app_module():
219217 Returns:
220218 The app module for the backend.
221219 """
222- config = get_config ()
220+ return get_config ().module
221+
222+
223+ def get_app_instance ():
224+ """Get the app module for the backend.
225+
226+ Returns:
227+ The app module for the backend.
228+ """
229+ return f"{ get_app_module ()} :{ constants .CompileVars .APP } "
223230
224- return f"{ config .module } :{ constants .CompileVars .APP } "
231+
232+ def get_app_file () -> Path :
233+ """Get the app file for the backend.
234+
235+ Returns:
236+ The app file for the backend.
237+
238+ Raises:
239+ ImportError: If the app module is not found.
240+ """
241+ current_working_dir = str (Path .cwd ())
242+ if current_working_dir not in sys .path :
243+ # Add the current working directory to sys.path
244+ sys .path .insert (0 , current_working_dir )
245+ module_spec = importlib .util .find_spec (get_app_module ())
246+ if module_spec is None :
247+ raise ImportError (
248+ f"Module { get_app_module ()} not found. Make sure the module is installed."
249+ )
250+ file_name = module_spec .origin
251+ if file_name is None :
252+ raise ImportError (
253+ f"Module { get_app_module ()} not found. Make sure the module is installed."
254+ )
255+ return Path (file_name ).resolve ()
256+
257+
258+ def get_app_instance_from_file () -> str :
259+ """Get the app module for the backend.
260+
261+ Returns:
262+ The app module for the backend.
263+ """
264+ return f"{ get_app_file ()} :{ constants .CompileVars .APP } "
225265
226266
227267def run_backend (
@@ -323,7 +363,7 @@ def run_uvicorn_backend(host: str, port: int, loglevel: LogLevel):
323363 import uvicorn
324364
325365 uvicorn .run (
326- app = f"{ get_app_module ()} " ,
366+ app = f"{ get_app_instance ()} " ,
327367 factory = True ,
328368 host = host ,
329369 port = port ,
@@ -349,7 +389,7 @@ def run_granian_backend(host: str, port: int, loglevel: LogLevel):
349389 from granian .server import MPServer as Granian
350390
351391 Granian (
352- target = get_app_module (),
392+ target = get_app_instance_from_file (),
353393 factory = True ,
354394 address = host ,
355395 port = port ,
@@ -367,14 +407,12 @@ def _deprecate_asgi_config(
367407 config_name : str ,
368408 reason : str = "" ,
369409):
370- # When we eventually switch to Granian by default, we should enable this deprecation.
371- if False :
372- console .deprecate (
373- f"config.{ config_name } " ,
374- reason = reason ,
375- deprecation_version = "0.7.5" ,
376- removal_version = "0.8.0" ,
377- )
410+ console .deprecate (
411+ f"config.{ config_name } " ,
412+ reason = reason ,
413+ deprecation_version = "0.7.9" ,
414+ removal_version = "0.8.0" ,
415+ )
378416
379417
380418@once
@@ -468,7 +506,7 @@ def run_uvicorn_backend_prod(host: str, port: int, loglevel: LogLevel):
468506
469507 config = get_config ()
470508
471- app_module = get_app_module ()
509+ app_module = get_app_instance ()
472510
473511 command = (
474512 [
@@ -568,7 +606,7 @@ def run_granian_backend_prod(host: str, port: int, loglevel: LogLevel):
568606 * ("--host" , host ),
569607 * ("--port" , str (port )),
570608 * ("--interface" , str (Interfaces .ASGI )),
571- * ("--factory" , get_app_module ()),
609+ * ("--factory" , get_app_instance_from_file ()),
572610 ]
573611 processes .new_process (
574612 command ,
0 commit comments