Skip to content

Commit 346ccf7

Browse files
authored
granian all the way (#4994)
* granian all the way * uv lock * get it right pyright * reenable uvicorn in dev * remove interestingly named prop * update ruff
1 parent 0e2d392 commit 346ccf7

File tree

12 files changed

+268
-200
lines changed

12 files changed

+268
-200
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fail_fast: true
22

33
repos:
44
- repo: https://github.com/charliermarsh/ruff-pre-commit
5-
rev: v0.9.10
5+
rev: v0.11.0
66
hooks:
77
- id: ruff-format
88
args: [reflex, tests]

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies = [
2525
"charset-normalizer >=3.3.2,<4.0",
2626
"distro >=1.8.0,<2.0; platform_system == 'Linux'",
2727
"fastapi >=0.96.0,!=0.111.0,!=0.111.1",
28-
"gunicorn >=20.1.0,<24.0",
28+
"granian[reload] >=2.0.0",
2929
"httpx >=0.25.1,<1.0",
3030
"jinja2 >=3.1.2,<4.0",
3131
"lazy_loader >=0.4",
@@ -46,7 +46,6 @@ dependencies = [
4646
"twine >=4.0.0,<7.0",
4747
"typer >=0.15.1,<1.0",
4848
"typing_extensions >=4.6.0",
49-
"uvicorn >=0.20.0",
5049
"wheel >=0.42.0,<1.0",
5150
"wrapt >=1.17.0,<2.0",
5251
]
@@ -140,7 +139,6 @@ dev = [
140139
"asynctest >=0.13.0,<1.0",
141140
"darglint >=1.8.1,<2.0",
142141
"dill >=0.3.8",
143-
"granian[reload] >= 2.0.0",
144142
"numpy >=2.2.3,<3.0",
145143
"pandas >=2.1.1,<3.0",
146144
"pillow >=10.0.0,<12.0",
@@ -159,7 +157,8 @@ dev = [
159157
"pytest-retry >=1.7.0,<2.0",
160158
"pytest-split >=0.10.0,<1.0",
161159
"libsass >=0.23.0,<1.0",
162-
"ruff ==0.9.10",
160+
"ruff ==0.11.0",
163161
"selenium >=4.11.0,<5.0",
164162
"toml >=0.10.2,<1.0",
163+
"uvicorn >=0.20.0",
165164
]

reflex/compiler/compiler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,11 @@ def get_shared_components_recursive(component: BaseComponent):
368368

369369
# Include dynamic imports in the shared component.
370370
if dynamic_imports := component._get_all_dynamic_imports():
371-
rendered_components.update(
372-
{dynamic_import: None for dynamic_import in dynamic_imports}
373-
)
371+
rendered_components.update(dict.fromkeys(dynamic_imports))
374372

375373
# Include custom code in the shared component.
376374
rendered_components.update(
377-
{code: None for code in component._get_all_custom_code()},
375+
dict.fromkeys(component._get_all_custom_code()),
378376
)
379377

380378
# Include all imports in the shared component.

reflex/components/dynamic.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ def make_component(component: Component) -> str:
7272
rendered_components = {}
7373
# Include dynamic imports in the shared component.
7474
if dynamic_imports := component._get_all_dynamic_imports():
75-
rendered_components.update(
76-
{dynamic_import: None for dynamic_import in dynamic_imports}
77-
)
75+
rendered_components.update(dict.fromkeys(dynamic_imports))
7876

7977
# Include custom code in the shared component.
8078
rendered_components.update(
81-
{code: None for code in component._get_all_custom_code()},
79+
dict.fromkeys(component._get_all_custom_code()),
8280
)
8381

8482
rendered_components[

reflex/config.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
)
3131

3232
import pydantic.v1 as pydantic
33-
from reflex_cli.constants.hosting import Hosting
3433

3534
from reflex import constants
3635
from reflex.base import Base
@@ -602,7 +601,7 @@ class EnvironmentVariables:
602601
# The npm registry to use.
603602
NPM_CONFIG_REGISTRY: EnvVar[str | None] = env_var(None)
604603

605-
# Whether to use Granian for the backend. Otherwise, use Uvicorn.
604+
# Whether to use Granian for the backend. By default, the backend uses Uvicorn if available.
606605
REFLEX_USE_GRANIAN: EnvVar[bool] = env_var(False)
607606

608607
# The username to use for authentication on python package repository. Username and password must both be provided.
@@ -807,8 +806,8 @@ class Config: # pyright: ignore [reportIncompatibleVariableOverride]
807806
# Tailwind config.
808807
tailwind: dict[str, Any] | None = {"plugins": ["@tailwindcss/typography"]}
809808

810-
# Timeout when launching the gunicorn server. TODO(rename this to backend_timeout?)
811-
timeout: int = 120
809+
# DEPRECATED. Timeout when launching the gunicorn server.
810+
timeout: int | None = None
812811

813812
# Whether to enable or disable nextJS gzip compression.
814813
next_compression: bool = True
@@ -819,22 +818,17 @@ class Config: # pyright: ignore [reportIncompatibleVariableOverride]
819818
# Additional frontend packages to install.
820819
frontend_packages: list[str] = []
821820

822-
# The hosting service backend URL.
823-
cp_backend_url: str = Hosting.HOSTING_SERVICE
824-
# The hosting service frontend URL.
825-
cp_web_url: str = Hosting.HOSTING_SERVICE_UI
826-
827-
# The worker class used in production mode
821+
# DEPRECATED. The worker class used in production mode
828822
gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"
829823

830-
# Number of gunicorn workers from user
824+
# DEPRECATED. Number of gunicorn workers from user
831825
gunicorn_workers: int | None = None
832826

833-
# Number of requests before a worker is restarted; set to 0 to disable
834-
gunicorn_max_requests: int = 100
827+
# DEPRECATED. Number of requests before a worker is restarted; set to 0 to disable
828+
gunicorn_max_requests: int | None = None
835829

836-
# Variance limit for max requests; gunicorn only
837-
gunicorn_max_requests_jitter: int = 25
830+
# DEPRECATED. Variance limit for max requests; gunicorn only
831+
gunicorn_max_requests_jitter: int | None = None
838832

839833
# Indicate which type of state manager to use
840834
state_manager_mode: constants.StateManagerMode = constants.StateManagerMode.DISK

reflex/custom_components/custom_components.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,19 @@ def _collect_details_for_gallery():
826826
Raises:
827827
Exit: If pyproject.toml file is ill-formed or the request to the backend services fails.
828828
"""
829+
import reflex_cli.constants
829830
from reflex_cli.utils import hosting
830831

831832
console.rule("[bold]Authentication with Reflex Services")
832833
console.print("First let's log in to Reflex backend services.")
833834
access_token, _ = hosting.authenticated_token()
834835

836+
if not access_token:
837+
console.error(
838+
"Unable to authenticate with Reflex backend services. Make sure you are logged in."
839+
)
840+
raise typer.Exit(code=1)
841+
835842
console.rule("[bold]Custom Component Information")
836843
params = {}
837844
package_name = None
@@ -845,10 +852,8 @@ def _collect_details_for_gallery():
845852
console.print(f"[ Custom component package name ] : {package_name}")
846853
params["package_name"] = package_name
847854

848-
config = get_config()
849-
850855
post_custom_components_gallery_endpoint = (
851-
f"{config.cp_backend_url}/custom-components/gallery"
856+
f"{reflex_cli.constants.Hosting.HOSTING_SERVICE}/custom-components/gallery"
852857
)
853858

854859
# Check the backend services if the user is allowed to update information of this package is already shared.

reflex/reflex.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from __future__ import annotations
44

55
import atexit
6-
import concurrent.futures
76
from pathlib import Path
87

98
import typer
109
import typer.core
11-
from reflex_cli.v2.deployments import check_version, hosting_cli
10+
from reflex_cli.v2.deployments import hosting_cli
1211

1312
from reflex import constants
1413
from reflex.config import environment, get_config
@@ -210,6 +209,8 @@ def _run(
210209

211210
# Granian fails if the app is already imported.
212211
if should_use_granian():
212+
import concurrent.futures
213+
213214
compile_future = concurrent.futures.ProcessPoolExecutor(max_workers=1).submit(
214215
app_task
215216
)
@@ -396,6 +397,7 @@ def export(
396397
def login(loglevel: constants.LogLevel | None = typer.Option(None)):
397398
"""Authenticate with experimental Reflex hosting service."""
398399
from reflex_cli.v2 import cli as hosting_cli
400+
from reflex_cli.v2.deployments import check_version
399401

400402
loglevel = loglevel or get_config().loglevel
401403

@@ -417,6 +419,7 @@ def logout(
417419
):
418420
"""Log out of access to Reflex hosting service."""
419421
from reflex_cli.v2.cli import logout
422+
from reflex_cli.v2.deployments import check_version
420423

421424
check_version()
422425

@@ -577,6 +580,7 @@ def deploy(
577580
from reflex_cli.constants.base import LogLevel as HostingLogLevel
578581
from reflex_cli.utils import dependency
579582
from reflex_cli.v2 import cli as hosting_cli
583+
from reflex_cli.v2.deployments import check_version
580584

581585
from reflex.utils import export as export_utils
582586
from reflex.utils import prerequisites

0 commit comments

Comments
 (0)