From 919f239168d789056dfca6c67a500637f3f0ab8e Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 2 Aug 2023 06:33:56 -0700 Subject: [PATCH] check_initialized: skip REFLEX_DIR check for backend only (#1478) --- .github/workflows/integration_tests.yml | 11 ++++++ .../init-test/in_docker_test_script.sh | 2 +- reflex/utils/build.py | 36 +++++++++---------- reflex/utils/prerequisites.py | 2 +- scripts/integration.sh | 15 +++++--- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 02140c922..76b413473 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -59,10 +59,21 @@ jobs: working-directory: ./reflex-examples/counter run: | poetry run pip install -r requirements.txt + - name: Check export --backend-only before init for counter example + working-directory: ./reflex-examples/counter + run: | + poetry run reflex export --backend-only + - name: Check run --backend-only before init for counter example + run: | + poetry run bash scripts/integration.sh ./reflex-examples/counter dev 8001 --backend-only --backend-port 8001 - name: Init Website for counter example working-directory: ./reflex-examples/counter run: | poetry run reflex init --loglevel debug + - name: Check export for counter example + working-directory: ./reflex-examples/counter + run: | + poetry run reflex export - name: Run Website and Check for errors run: | # Check that npm is home diff --git a/integration/init-test/in_docker_test_script.sh b/integration/init-test/in_docker_test_script.sh index 0e8ddecff..1424d7222 100755 --- a/integration/init-test/in_docker_test_script.sh +++ b/integration/init-test/in_docker_test_script.sh @@ -11,4 +11,4 @@ echo "Installing reflex from local repo code" cd /reflex-repo poetry install echo "Running reflex init in test project dir" -poetry run /bin/bash -c "cd ~/hello && reflex init" \ No newline at end of file +poetry run /bin/bash -c "cd ~/hello && reflex init && rm -rf ~/.reflex .web && reflex export --backend-only" \ No newline at end of file diff --git a/reflex/utils/build.py b/reflex/utils/build.py index 87e080a38..68e0ace73 100644 --- a/reflex/utils/build.py +++ b/reflex/utils/build.py @@ -108,24 +108,24 @@ def export( generate_sitemap_config(deploy_url) command = "export-sitemap" - checkpoints = [ - "Linting and checking ", - "Compiled successfully", - "Route (pages)", - "Collecting page data", - "automatically rendered as static HTML", - 'Copying "static build" directory', - 'Copying "public" directory', - "Finalizing page optimization", - "Export successful", - ] - - # Start the subprocess with the progress bar. - process = processes.new_process( - [prerequisites.get_package_manager(), "run", command], - cwd=constants.WEB_DIR, - ) - processes.show_progress("Creating Production Build", process, checkpoints) + if frontend: + checkpoints = [ + "Linting and checking ", + "Compiled successfully", + "Route (pages)", + "Collecting page data", + "automatically rendered as static HTML", + 'Copying "static build" directory', + 'Copying "public" directory', + "Finalizing page optimization", + "Export successful", + ] + # Start the subprocess with the progress bar. + process = processes.new_process( + [prerequisites.get_package_manager(), "run", command], + cwd=constants.WEB_DIR, + ) + processes.show_progress("Creating Production Build", process, checkpoints) # Zip up the app. if zip: diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index e01e9acc7..a869b5139 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -398,7 +398,7 @@ def check_initialized(frontend: bool = True): Exit: If the app is not initialized. """ has_config = os.path.exists(constants.CONFIG_FILE) - has_reflex_dir = IS_WINDOWS or os.path.exists(constants.REFLEX_DIR) + has_reflex_dir = not frontend or IS_WINDOWS or os.path.exists(constants.REFLEX_DIR) has_web_dir = not frontend or os.path.exists(constants.WEB_DIR) # Check if the app is initialized. diff --git a/scripts/integration.sh b/scripts/integration.sh index b35efe6d0..b2d42a505 100755 --- a/scripts/integration.sh +++ b/scripts/integration.sh @@ -1,14 +1,21 @@ #!/bin/bash # Change directory to the first argument passed to the script -pushd "$1" || exit 1 -echo "Changed directory to $1" +project_dir=$1 +shift +pushd "$project_dir" || exit 1 +echo "Changed directory to $project_dir" # So we get stdout / stderr from Python ASAP. Without this, delays can be very long (e.g. on Windows, Github Actions) export PYTHONUNBUFFERED=1 +env_mode=$1 +shift +check_ports=${1:-3000 8000} +shift + # Start the server in the background -reflex run --loglevel debug --env "$2" & pid=$! +reflex run --loglevel debug --env "$env_mode" "$@" & pid=$! # Within the context of this bash, $pid_in_bash is what we need to pass to "kill" on exit # This is true on all platforms. @@ -26,4 +33,4 @@ if [ -f /proc/$pid/winpid ]; then echo "Windows detected, passing winpid $pid to port waiter" fi -python scripts/wait_for_listening_port.py 3000 8000 --timeout=600 --server-pid "$pid" \ No newline at end of file +python scripts/wait_for_listening_port.py 3000 8000 --timeout=600 --server-pid "$pid"