Skip to content

Commit

Permalink
remove v2 commands (#4478)
Browse files Browse the repository at this point in the history
* remove v2 commands

* format

* remove v2

* remove v2

* little fixes friend

* add cloud

* relock poetry deps

* bump reflex-hosting-cli dep

* test_dynamic_routes: wait for token

attempt to avoid test flakiness

* relock deps

* test_dynamic_routes: increase polling timeout

---------

Co-authored-by: simon <simon@reflex.dev>
Co-authored-by: Masen Furer <m_github@0x26.net>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent e23d939 commit 1277100
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 197 deletions.
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ wrapt = [
{version = ">=1.11.0,<2.0", python = "<3.11"},
]
packaging = ">=23.1,<25.0"
reflex-hosting-cli = ">=0.1.17,<2.0"
reflex-hosting-cli = ">=0.1.28,<2.0"
charset-normalizer = ">=3.3.2,<4.0"
wheel = ">=0.42.0,<1.0"
build = ">=1.0.3,<2.0"
Expand Down
4 changes: 2 additions & 2 deletions reflex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ class Config:
frontend_packages: List[str] = []

# The hosting service backend URL.
cp_backend_url: str = Hosting.CP_BACKEND_URL
cp_backend_url: str = Hosting.HOSTING_SERVICE
# The hosting service frontend URL.
cp_web_url: str = Hosting.CP_WEB_URL
cp_web_url: str = Hosting.HOSTING_SERVICE_UI

# The worker class used in production mode
gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"
Expand Down
4 changes: 2 additions & 2 deletions reflex/custom_components/custom_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,11 @@ def _collect_details_for_gallery():
Raises:
Exit: If pyproject.toml file is ill-formed or the request to the backend services fails.
"""
from reflex.reflex import _login
from reflex_cli.utils import hosting

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

console.rule("[bold]Custom Component Information")
params = {}
Expand Down
191 changes: 8 additions & 183 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import typer
import typer.core
from reflex_cli.deployments import deployments_cli
from reflex_cli.utils import dependency
from reflex_cli.v2.deployments import check_version, hosting_cli

from reflex import constants
Expand Down Expand Up @@ -330,41 +328,8 @@ def export(
)


def _login() -> str:
"""Helper function to authenticate with Reflex hosting service."""
from reflex_cli.utils import hosting

access_token, invitation_code = hosting.authenticated_token()
if access_token:
console.print("You already logged in.")
return access_token

# If not already logged in, open a browser window/tab to the login page.
access_token = hosting.authenticate_on_browser(invitation_code)

if not access_token:
console.error("Unable to authenticate. Please try again or contact support.")
raise typer.Exit(1)

console.print("Successfully logged in.")
return access_token


@cli.command()
def login(
loglevel: constants.LogLevel = typer.Option(
config.loglevel, help="The log level to use."
),
):
"""Authenticate with Reflex hosting service."""
# Set the log level.
console.set_log_level(loglevel)

_login()


@cli.command()
def loginv2(loglevel: constants.LogLevel = typer.Option(config.loglevel)):
def login(loglevel: constants.LogLevel = typer.Option(config.loglevel)):
"""Authenicate with experimental Reflex hosting service."""
from reflex_cli.v2 import cli as hosting_cli

Expand All @@ -382,26 +347,11 @@ def logout(
),
):
"""Log out of access to Reflex hosting service."""
from reflex_cli.utils import hosting

console.set_log_level(loglevel)

hosting.log_out_on_browser()
console.debug("Deleting access token from config locally")
hosting.delete_token_from_config(include_invitation_code=True)


@cli.command()
def logoutv2(
loglevel: constants.LogLevel = typer.Option(
config.loglevel, help="The log level to use."
),
):
"""Log out of access to Reflex hosting service."""
from reflex_cli.v2 import cli
from reflex_cli.v2.cli import logout

check_version()
cli.logout()

logout(loglevel) # type: ignore


db_cli = typer.Typer()
Expand Down Expand Up @@ -486,126 +436,6 @@ def makemigrations(

@cli.command()
def deploy(
key: Optional[str] = typer.Option(
None,
"-k",
"--deployment-key",
help="The name of the deployment. Domain name safe characters only.",
),
app_name: str = typer.Option(
config.app_name,
"--app-name",
help="The name of the App to deploy under.",
hidden=True,
),
regions: List[str] = typer.Option(
list(),
"-r",
"--region",
help="The regions to deploy to.",
),
envs: List[str] = typer.Option(
list(),
"--env",
help="The environment variables to set: <key>=<value>. For multiple envs, repeat this option, e.g. --env k1=v2 --env k2=v2.",
),
cpus: Optional[int] = typer.Option(
None, help="The number of CPUs to allocate.", hidden=True
),
memory_mb: Optional[int] = typer.Option(
None, help="The amount of memory to allocate.", hidden=True
),
auto_start: Optional[bool] = typer.Option(
None,
help="Whether to auto start the instance.",
hidden=True,
),
auto_stop: Optional[bool] = typer.Option(
None,
help="Whether to auto stop the instance.",
hidden=True,
),
frontend_hostname: Optional[str] = typer.Option(
None,
"--frontend-hostname",
help="The hostname of the frontend.",
hidden=True,
),
interactive: bool = typer.Option(
True,
help="Whether to list configuration options and ask for confirmation.",
),
with_metrics: Optional[str] = typer.Option(
None,
help="Setting for metrics scraping for the deployment. Setup required in user code.",
hidden=True,
),
with_tracing: Optional[str] = typer.Option(
None,
help="Setting to export tracing for the deployment. Setup required in user code.",
hidden=True,
),
upload_db_file: bool = typer.Option(
False,
help="Whether to include local sqlite db files when uploading to hosting service.",
hidden=True,
),
loglevel: constants.LogLevel = typer.Option(
config.loglevel, help="The log level to use."
),
):
"""Deploy the app to the Reflex hosting service."""
from reflex_cli import cli as hosting_cli

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

# Set the log level.
console.set_log_level(loglevel)

# Only check requirements if interactive. There is user interaction for requirements update.
if interactive:
dependency.check_requirements()

# Check if we are set up.
if prerequisites.needs_reinit(frontend=True):
_init(name=config.app_name, loglevel=loglevel)
prerequisites.check_latest_package_version(constants.ReflexHostingCLI.MODULE_NAME)

hosting_cli.deploy(
app_name=app_name,
export_fn=lambda zip_dest_dir,
api_url,
deploy_url,
frontend,
backend,
zipping: export_utils.export(
zip_dest_dir=zip_dest_dir,
api_url=api_url,
deploy_url=deploy_url,
frontend=frontend,
backend=backend,
zipping=zipping,
loglevel=loglevel.subprocess_level(),
upload_db_file=upload_db_file,
),
key=key,
regions=regions,
envs=envs,
cpus=cpus,
memory_mb=memory_mb,
auto_start=auto_start,
auto_stop=auto_stop,
frontend_hostname=frontend_hostname,
interactive=interactive,
with_metrics=with_metrics,
with_tracing=with_tracing,
loglevel=loglevel.subprocess_level(),
)


@cli.command()
def deployv2(
app_name: str = typer.Option(
config.app_name,
"--app-name",
Expand Down Expand Up @@ -657,8 +487,8 @@ def deployv2(
),
):
"""Deploy the app to the Reflex hosting service."""
from reflex_cli.utils import dependency
from reflex_cli.v2 import cli as hosting_cli
from reflex_cli.v2.utils import dependency

from reflex.utils import export as export_utils
from reflex.utils import prerequisites
Expand Down Expand Up @@ -702,23 +532,18 @@ def deployv2(
envfile=envfile,
hostname=hostname,
interactive=interactive,
loglevel=loglevel.subprocess_level(),
loglevel=type(loglevel).INFO, # type: ignore
token=token,
project=project,
)


cli.add_typer(db_cli, name="db", help="Subcommands for managing the database schema.")
cli.add_typer(script_cli, name="script", help="Subcommands running helper scripts.")
cli.add_typer(
deployments_cli,
name="deployments",
help="Subcommands for managing the Deployments.",
)
cli.add_typer(
hosting_cli,
name="apps",
help="Subcommands for managing the Deployments.",
name="cloud",
help="Subcommands for managing the reflex cloud.",
)
cli.add_typer(
custom_components_cli,
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/test_dynamic_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def cached_arg_str(self) -> str:
@rx.page(route="/arg/[arg_str]")
def arg() -> rx.Component:
return rx.vstack(
rx.input(
value=DynamicState.router.session.client_token,
read_only=True,
id="token",
),
rx.data_list.root(
rx.data_list.item(
rx.data_list.label("rx.State.arg_str (dynamic)"),
Expand Down Expand Up @@ -373,12 +378,14 @@ async def test_on_load_navigate_non_dynamic(
async def test_render_dynamic_arg(
dynamic_route: AppHarness,
driver: WebDriver,
token: str,
):
"""Assert that dynamic arg var is rendered correctly in different contexts.
Args:
dynamic_route: harness for DynamicRoute app.
driver: WebDriver instance.
token: The token visible in the driver browser.
"""
assert dynamic_route.app_instance is not None
with poll_for_navigation(driver):
Expand All @@ -398,7 +405,8 @@ def assert_content(expected: str, expect_not: str):
el = driver.find_element(By.ID, id)
assert el
assert (
dynamic_route.poll_for_content(el, exp_not_equal=expect_not) == expected
dynamic_route.poll_for_content(el, timeout=30, exp_not_equal=expect_not)
== expected
)

assert_content("0", "")
Expand Down

0 comments on commit 1277100

Please sign in to comment.