From 54b081c1043c5be5798af97d2cc9d66f49e2cd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Wed, 6 Nov 2024 09:31:13 -0800 Subject: [PATCH] allow custom bunfig.toml file (#4280) * allow custom bunfig.toml file * always copy custom bunfig * split tests into half * forgot a space * use different syntax * also split node latest check * turn off failfast for app harness --------- Co-authored-by: Khaleel Al-Adhami --- .github/workflows/check_node_latest.yml | 7 ++++-- .github/workflows/integration_app_harness.yml | 18 +++++++------- reflex/constants/installer.py | 5 ++++ reflex/utils/prerequisites.py | 24 ++++++++++++------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/.github/workflows/check_node_latest.yml b/.github/workflows/check_node_latest.yml index 5910fa9ed..1cf9f6fdf 100644 --- a/.github/workflows/check_node_latest.yml +++ b/.github/workflows/check_node_latest.yml @@ -18,7 +18,10 @@ jobs: strategy: matrix: python-version: ['3.12'] + split_index: [1, 2] node-version: ['node'] + fail-fast: false + steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup_build_env @@ -30,11 +33,11 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: | - poetry run uv pip install pyvirtualdisplay pillow + poetry run uv pip install pyvirtualdisplay pillow pytest-split poetry run playwright install --with-deps - run: | poetry run pytest tests/test_node_version.py - poetry run pytest tests/integration + poetry run pytest tests/integration --splits 2 --group ${{matrix.split_index}} diff --git a/.github/workflows/integration_app_harness.yml b/.github/workflows/integration_app_harness.yml index c86893556..ee9394b7e 100644 --- a/.github/workflows/integration_app_harness.yml +++ b/.github/workflows/integration_app_harness.yml @@ -6,13 +6,13 @@ concurrency: on: push: - branches: ['main'] + branches: ["main"] paths-ignore: - - '**/*.md' + - "**/*.md" pull_request: - branches: ['main'] + branches: ["main"] paths-ignore: - - '**/*.md' + - "**/*.md" permissions: contents: read @@ -22,8 +22,10 @@ jobs: timeout-minutes: 30 strategy: matrix: - state_manager: ['redis', 'memory'] - python-version: ['3.11.5', '3.12.0'] + state_manager: ["redis", "memory"] + split_index: [1, 2] + python-version: ["3.11.5", "3.12.0"] + fail-fast: false runs-on: ubuntu-22.04 services: # Label used to access the service container @@ -45,14 +47,14 @@ jobs: python-version: ${{ matrix.python-version }} run-poetry-install: true create-venv-at-path: .venv - - run: poetry run uv pip install pyvirtualdisplay pillow + - run: poetry run uv pip install pyvirtualdisplay pillow pytest-split - name: Run app harness tests env: SCREENSHOT_DIR: /tmp/screenshots REDIS_URL: ${{ matrix.state_manager == 'redis' && 'redis://localhost:6379' || '' }} run: | poetry run playwright install --with-deps - poetry run pytest tests/integration + poetry run pytest tests/integration --splits 2 --group ${{matrix.split_index}} - uses: actions/upload-artifact@v4 name: Upload failed test screenshots if: always() diff --git a/reflex/constants/installer.py b/reflex/constants/installer.py index 26a53f2d8..42084bb4d 100644 --- a/reflex/constants/installer.py +++ b/reflex/constants/installer.py @@ -75,6 +75,11 @@ class Bun(SimpleNamespace): """ return cls.ROOT_PATH / "bin" / ("bun" if not IS_WINDOWS else "bun.exe") + DEFAULT_CONFIG = """ +[install] +registry = {registry} +""" + # FNM config. class Fnm(SimpleNamespace): diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 063c2f594..a712e9a38 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -598,6 +598,8 @@ def initialize_web_directory(): initialize_package_json() + initialize_bun_config() + path_ops.mkdir(get_web_dir() / constants.Dirs.PUBLIC) update_next_config() @@ -622,17 +624,21 @@ def _compile_package_json(): def initialize_package_json(): """Render and write in .web the package.json file.""" output_path = get_web_dir() / constants.PackageJson.PATH - code = _compile_package_json() - output_path.write_text(code) + output_path.write_text(_compile_package_json()) - best_registry = _get_npm_registry() + +def initialize_bun_config(): + """Initialize the bun config file.""" bun_config_path = get_web_dir() / constants.Bun.CONFIG_PATH - bun_config_path.write_text( - f""" -[install] -registry = "{best_registry}" -""" - ) + + if (custom_bunfig := Path(constants.Bun.CONFIG_PATH)).exists(): + bunfig_content = custom_bunfig.read_text() + console.info(f"Copying custom bunfig.toml inside {get_web_dir()} folder") + else: + best_registry = _get_npm_registry() + bunfig_content = constants.Bun.DEFAULT_CONFIG.format(registry=best_registry) + + bun_config_path.write_text(bunfig_content) def init_reflex_json(project_hash: int | None):