Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions .github/workflows/analysis-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 &
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 &
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nc_py_api/ex_app/integration_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
6 changes: 5 additions & 1 deletion tests/_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
12 changes: 4 additions & 8 deletions tests/_install_init_handler_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
23 changes: 0 additions & 23 deletions tests/_tests_at_the_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()