diff --git a/.github/workflows/analysis-coverage.yml b/.github/workflows/analysis-coverage.yml index 8393482a..c1a3f281 100644 --- a/.github/workflows/analysis-coverage.yml +++ b/.github/workflows/analysis-coverage.yml @@ -99,7 +99,7 @@ jobs: --admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }} php occ config:system:set loglevel --value=1 --type=integer php occ config:system:set debug --value=true --type=boolean - php -S localhost:8080 & + PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & - name: Checkout NcPyApi uses: actions/checkout@v4 @@ -143,7 +143,7 @@ jobs: - name: Enable Talk run: php occ app:enable spreed - - name: Generate coverage report + - name: Generate coverage report (1) working-directory: nc_py_api run: | coverage run --data-file=.coverage.talk_bot tests/_talk_bot.py & @@ -152,6 +152,23 @@ jobs: kill -15 $(cat /tmp/_talk_bot.pid) timeout 3m tail --pid=$(cat /tmp/_talk_bot.pid) -f /dev/null coverage run --data-file=.coverage.at_the_end -m pytest tests/_tests_at_the_end.py + + - name: Uninstall NcPyApi + run: | + php occ app_api:app:unregister "$APP_ID" --silent + php occ app_api:daemon:unregister manual_install + + - name: Generate coverage report (2) + working-directory: nc_py_api + run: | + coverage run --data-file=.coverage.ci_install_models tests/_install_init_handler_models.py & + echo $! > /tmp/_install_models.pid + python3 tests/_install_wait.py http://127.0.0.1:$APP_PORT/heartbeat "\"status\":\"ok\"" 15 0.5 + cd .. + sh nc_py_api/scripts/ci_register.sh "$APP_ID" "$APP_VERSION" "$APP_SECRET" "localhost" "$APP_PORT" + kill -15 $(cat /tmp/_install_models.pid) + timeout 3m tail --pid=$(cat /tmp/_install_models.pid) -f /dev/null + cd nc_py_api coverage combine && coverage xml && coverage html - name: HTML coverage to artifacts @@ -243,7 +260,7 @@ jobs: --admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }} php occ config:system:set loglevel --value=1 php occ config:system:set debug --value=true --type=boolean - php -S localhost:8080 & + PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & - name: Checkout NcPyApi uses: actions/checkout@v4 @@ -287,7 +304,7 @@ jobs: - name: Enable Talk run: php occ app:enable spreed - - name: Generate coverage report + - name: Generate coverage report (1) working-directory: nc_py_api run: | coverage run --data-file=.coverage.talk_bot tests/_talk_bot.py & @@ -296,6 +313,23 @@ jobs: kill -15 $(cat /tmp/_talk_bot.pid) timeout 3m tail --pid=$(cat /tmp/_talk_bot.pid) -f /dev/null coverage run --data-file=.coverage.at_the_end -m pytest tests/_tests_at_the_end.py + + - name: Uninstall NcPyApi + run: | + php occ app_api:app:unregister "$APP_ID" --silent + php occ app_api:daemon:unregister manual_install + + - name: Generate coverage report (2) + working-directory: nc_py_api + run: | + coverage run --data-file=.coverage.ci_install_models tests/_install_init_handler_models.py & + echo $! > /tmp/_install_models.pid + python3 tests/_install_wait.py http://127.0.0.1:$APP_PORT/heartbeat "\"status\":\"ok\"" 15 0.5 + cd .. + sh nc_py_api/scripts/ci_register.sh "$APP_ID" "$APP_VERSION" "$APP_SECRET" "localhost" "$APP_PORT" + kill -15 $(cat /tmp/_install_models.pid) + timeout 3m tail --pid=$(cat /tmp/_install_models.pid) -f /dev/null + cd nc_py_api coverage combine && coverage xml && coverage html - name: HTML coverage to artifacts @@ -381,7 +415,7 @@ jobs: --admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }} php occ config:system:set loglevel --value=1 --type=integer php occ config:system:set debug --value=true --type=boolean - php -S localhost:8080 & + PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & - name: Checkout NcPyApi uses: actions/checkout@v4 @@ -512,7 +546,7 @@ jobs: ./occ config:system:set debug --value=true --type=boolean ./occ app:enable notifications ./occ app:enable notes - php -S localhost:8080 & + PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & - name: Checkout NcPyApi uses: actions/checkout@v4 @@ -662,7 +696,7 @@ jobs: ./occ config:system:set debug --value=true --type=boolean ./occ app:enable notifications ./occ app:enable activity - php -S localhost:8080 & + PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & - name: Checkout NcPyApi uses: actions/checkout@v4 @@ -802,7 +836,7 @@ jobs: ./occ config:system:set debug --value=true --type=boolean ./occ app:enable activity ./occ app:enable notes - php -S localhost:8080 & + PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & - name: Checkout NcPyApi uses: actions/checkout@v4 @@ -847,7 +881,7 @@ jobs: uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} - name: coverage_sqlite_${{ matrix.nextcloud }} + name: coverage_sqlite_${{ matrix.nextcloud }}_client file: coverage.xml fail_ci_if_error: true verbose: true diff --git a/nc_py_api/ex_app/integration_fastapi.py b/nc_py_api/ex_app/integration_fastapi.py index fc645b5e..52acad47 100644 --- a/nc_py_api/ex_app/integration_fastapi.py +++ b/nc_py_api/ex_app/integration_fastapi.py @@ -75,7 +75,7 @@ def set_handlers( :param models_download_params: Parameters to pass to ``snapshot_download`` function from **huggingface_hub**. """ - def fetch_models_task(models: dict): + def fetch_models_task(models: list[str]) -> None: if models: from huggingface_hub import snapshot_download # noqa isort:skip pylint: disable=C0415 disable=E0401 from tqdm import tqdm # noqa isort:skip pylint: disable=C0415 disable=E0401 @@ -115,5 +115,5 @@ def heartbeat_callback(): @fast_api_app.post("/init") def init_callback(background_tasks: BackgroundTasks): - background_tasks.add_task(fetch_models_task, models_to_fetch if models_to_fetch else {}) + background_tasks.add_task(fetch_models_task, models_to_fetch if models_to_fetch else []) return responses.JSONResponse(content={}, status_code=200) diff --git a/tests/_install.py b/tests/_install.py index 1cc58db1..746ca5b9 100644 --- a/tests/_install.py +++ b/tests/_install.py @@ -27,13 +27,17 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str: return "" +def init_handler(): + NextcloudApp().set_init_status(100) + + def heartbeat_callback(): return "ok" @APP.on_event("startup") def initialization(): - ex_app.set_handlers(APP, enabled_handler, heartbeat_callback) + ex_app.set_handlers(APP, enabled_handler, heartbeat_callback, init_handler=init_handler) if __name__ == "__main__": diff --git a/tests/_install_init_handler_models.py b/tests/_install_init_handler_models.py index 9d0f8ef0..c2f2f66f 100644 --- a/tests/_install_init_handler_models.py +++ b/tests/_install_init_handler_models.py @@ -7,22 +7,18 @@ MODEL_NAME = "MBZUAI/LaMini-T5-61M" -def enabled_handler(_enabled: bool, _nc: NextcloudApp) -> str: - if _enabled: +def enabled_handler(enabled: bool, _nc: NextcloudApp) -> str: + if enabled: try: - snapshot_download(MODEL_NAME, local_files_only=True) + snapshot_download(MODEL_NAME, local_files_only=True, cache_dir=ex_app.persistent_storage()) except Exception: # noqa return "model not found" return "" -def init_handler(): - NextcloudApp().set_init_status(100) - - @APP.on_event("startup") def initialization(): - ex_app.set_handlers(APP, enabled_handler, init_handler=init_handler, models_to_fetch=[MODEL_NAME]) + ex_app.set_handlers(APP, enabled_handler, models_to_fetch=[MODEL_NAME]) if __name__ == "__main__": diff --git a/tests/_tests_at_the_end.py b/tests/_tests_at_the_end.py index 0631678b..04cec84d 100644 --- a/tests/_tests_at_the_end.py +++ b/tests/_tests_at_the_end.py @@ -28,26 +28,3 @@ def test_ex_app_enable_disable(nc_client, nc_app): assert nc_client.apps.ex_app_is_enabled("nc_py_api") is True finally: r.terminate() - - -def test_install_init_handler_models(nc_client, nc_app): - child_environment = os.environ.copy() - child_environment["APP_PORT"] = os.environ.get("APP_PORT", "9009") - r = Popen( - [ - sys.executable, - os.path.join(os.path.dirname(os.path.abspath(__file__)), "_install_init_handler_models.py"), - ], - env=child_environment, - cwd=os.getcwd(), - ) - url = f"http://127.0.0.1:{child_environment['APP_PORT']}/heartbeat" - try: - if check_heartbeat(url, '"status":"ok"', 15, 0.3): - raise RuntimeError("`_install_init_handler_models` can not start.") - if nc_client.apps.ex_app_is_enabled("nc_py_api"): - nc_client.apps.ex_app_disable("nc_py_api") - nc_client.apps.ex_app_enable("nc_py_api") - assert nc_client.apps.ex_app_is_enabled("nc_py_api") is True - finally: - r.terminate()