فهرست منبع

Hosting CLI: remove requirements generation when init, add back timeout for deploy command, remove deploy legacy command (#2179)

Martin Xu 1 سال پیش
والد
کامیت
adb26787c8
5فایلهای تغییر یافته به همراه11 افزوده شده و 57 حذف شده
  1. 0 8
      reflex/config.py
  2. 1 1
      reflex/constants/config.py
  3. 1 43
      reflex/reflex.py
  4. 8 5
      reflex/utils/hosting.py
  5. 1 0
      tests/test_reflex.py

+ 0 - 8
reflex/config.py

@@ -185,19 +185,11 @@ class Config(Base):
     # Additional frontend packages to install.
     frontend_packages: List[str] = []
 
-    # Params to remove eventually.
-    # For rest are for deploy only.
-    # The rxdeploy url.
-    rxdeploy_url: Optional[str] = None
-
     # The hosting service backend URL.
     cp_backend_url: str = constants.Hosting.CP_BACKEND_URL
     # The hosting service frontend URL.
     cp_web_url: str = constants.Hosting.CP_WEB_URL
 
-    # The username.
-    username: Optional[str] = None
-
     # The worker class used in production mode
     gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"
 

+ 1 - 1
reflex/constants/config.py

@@ -47,7 +47,7 @@ class RequirementsTxt(SimpleNamespace):
     # The requirements.txt file.
     FILE = "requirements.txt"
     # The partial text used to form requirement that pins a reflex version
-    DEFAULTS_STUB = f"{Reflex.MODULE_NAME}=="
+    DEFAULTS_STUB = f"{Reflex.MODULE_NAME}>="
 
 
 # The deployment URL.

+ 1 - 43
reflex/reflex.py

@@ -14,7 +14,6 @@ from datetime import datetime
 from pathlib import Path
 from typing import List, Optional
 
-import httpx
 import typer
 import typer.core
 from alembic.util.exc import CommandError
@@ -258,47 +257,6 @@ def run(
     _run(env, frontend, backend, frontend_port, backend_port, backend_host, loglevel)
 
 
-@cli.command()
-def deploy_legacy(
-    dry_run: bool = typer.Option(False, help="Whether to run a dry run."),
-    loglevel: constants.LogLevel = typer.Option(
-        console._LOG_LEVEL, help="The log level to use."
-    ),
-):
-    """Deploy the app to the Reflex hosting service."""
-    # Set the log level.
-    console.set_log_level(loglevel)
-
-    # Show system info
-    exec.output_system_info()
-
-    # Check if the deploy url is set.
-    if config.rxdeploy_url is None:
-        console.info("This feature is coming soon!")
-        return
-
-    # Compile the app in production mode.
-    export(loglevel=loglevel)
-
-    # Exit early if this is a dry run.
-    if dry_run:
-        return
-
-    # Deploy the app.
-    data = {"userId": config.username, "projectId": config.app_name}
-    original_response = httpx.get(config.rxdeploy_url, params=data)
-    response = original_response.json()
-    frontend = response["frontend_resources_url"]
-    backend = response["backend_resources_url"]
-
-    # Upload the frontend and backend.
-    with open(constants.ComponentName.FRONTEND.zip(), "rb") as f:
-        httpx.put(frontend, data=f)  # type: ignore
-
-    with open(constants.ComponentName.BACKEND.zip(), "rb") as f:
-        httpx.put(backend, data=f)  # type: ignore
-
-
 @cli.command()
 def export(
     zipping: bool = typer.Option(
@@ -569,7 +527,7 @@ def deploy(
             enabled_regions = pre_deploy_response.enabled_regions
 
     except Exception as ex:
-        console.error(f"Unable to prepare deployment")
+        console.error(f"Unable to prepare deployment due to: {ex}")
         raise typer.Exit(1) from ex
 
     # The app prefix should not change during the time of preparation

+ 8 - 5
reflex/utils/hosting.py

@@ -142,6 +142,8 @@ def save_token_to_config(token: str, code: str | None = None):
     if code:
         hosting_config["code"] = code
     try:
+        if not os.path.exists(constants.Reflex.DIR):
+            os.makedirs(constants.Reflex.DIR)
         with open(constants.Hosting.HOSTING_JSON, "w") as config_file:
             json.dump(hosting_config, config_file)
     except Exception as ex:
@@ -324,22 +326,22 @@ def prepare_deploy(
             enabled_regions=response_json.get("enabled_regions"),
         )
     except httpx.RequestError as re:
-        console.error(f"Unable to prepare launch due to {re}.")
+        console.debug(f"Unable to prepare launch due to {re}.")
         raise Exception(str(re)) from re
     except httpx.HTTPError as he:
-        console.error(f"Unable to prepare deploy due to {he}.")
+        console.debug(f"Unable to prepare deploy due to {he}.")
         raise Exception(f"{he}") from he
     except json.JSONDecodeError as jde:
-        console.error(f"Server did not respond with valid json: {jde}")
+        console.debug(f"Server did not respond with valid json: {jde}")
         raise Exception("internal errors") from jde
     except (KeyError, ValidationError) as kve:
-        console.error(f"The server response format is unexpected {kve}")
+        console.debug(f"The server response format is unexpected {kve}")
         raise Exception("internal errors") from kve
     except ValueError as ve:
         # This is a recognized client error, currently indicates forbidden
         raise Exception(f"{ve}") from ve
     except Exception as ex:
-        console.error(f"Unexpected error: {ex}.")
+        console.debug(f"Unexpected error: {ex}.")
         raise Exception("internal errors") from ex
 
 
@@ -465,6 +467,7 @@ def deploy(
                 headers=authorization_header(token),
                 data=params.dict(exclude_none=True),
                 files=files,
+                timeout=HTTP_REQUEST_TIMEOUT,
             )
         # If the server explicitly states bad request,
         # display a different error

+ 1 - 0
tests/test_reflex.py

@@ -61,6 +61,7 @@ def test_deploy_required_args_missing(args):
 @pytest.fixture
 def setup_env_authentication(mocker):
     mocker.patch("reflex.utils.prerequisites.check_initialized")
+    mocker.patch("reflex.utils.dependency.check_requirements")
     mocker.patch("reflex.utils.hosting.authenticated_token", return_value="fake-token")
     mocker.patch("time.sleep")