diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 117ee7ef6..738a6ed27 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -27,21 +27,25 @@ jobs: run: | black --check ./vm_supervisor black --check ./runtimes/aleph-debian-11-python/init1.py + black --check ./examples/example_fastapi/ - name: Test with isort run: | isort --check-only --profile=black ./vm_supervisor isort --check-only --profile=black ./runtimes/aleph-debian-11-python/init1.py + isort --check-only --profile=black ./examples/example_fastapi/ - name: Test with MyPy run: | mypy --ignore-missing-imports ./vm_supervisor mypy --ignore-missing-imports ./runtimes/aleph-debian-11-python/init1.py + mypy --ignore-missing-imports ./examples/example_fastapi/ - name: Test with flake8 run: | flake8 --extend-ignore E501 ./vm_supervisor flake8 --extend-ignore E501,E402 ./runtimes/aleph-debian-11-python/init1.py + flake8 --extend-ignore E501,E402 ./examples/example_fastapi/ code-quality-shell: runs-on: ubuntu-22.04 diff --git a/examples/example_fastapi/main.py b/examples/example_fastapi/main.py index e2931db6f..866fb6ac4 100644 --- a/examples/example_fastapi/main.py +++ b/examples/example_fastapi/main.py @@ -6,26 +6,21 @@ import sys from datetime import datetime from os import listdir +from pathlib import Path from typing import Dict -from pydantic import BaseModel - -logger = logging.getLogger(__name__) - -logger.debug("import aiohttp") import aiohttp - -logger.debug("import aleph_client") -from aleph.sdk.client import AlephClient, AuthenticatedAlephClient from aleph.sdk.chains.remote import RemoteAccount +from aleph.sdk.client import AlephClient, AuthenticatedAlephClient from aleph.sdk.types import StorageEnum from aleph.sdk.vm.app import AlephApp from aleph.sdk.vm.cache import VmCache - -logger.debug("import fastapi") from fastapi import FastAPI from fastapi.responses import PlainTextResponse +from pip._internal.operations.freeze import freeze +from pydantic import BaseModel +logger = logging.getLogger(__name__) logger.debug("imports done") http_app = FastAPI() @@ -60,6 +55,9 @@ async def index(): "/post_a_message", "/state/increment", "/wait-for/{delay}", + "/platform/os", + "/platform/python", + "/platform/pip-freeze", ], "files_in_volumes": { "/opt/venv": opt_venv, @@ -72,7 +70,7 @@ async def check_lifespan(): """ Check that ASGI lifespan startup signal has been received """ - return {"Lifetime": startup_lifespan_executed} + return {"Lifespan": startup_lifespan_executed} @app.get("/environ") @@ -252,6 +250,21 @@ def crash(): ] +@app.get("/platform/os") +def platform_os(): + return PlainTextResponse(content=Path("/etc/os-release").read_text()) + + +@app.get("/platform/python") +def platform_python(): + return PlainTextResponse(content=sys.version) + + +@app.get("/platform/pip-freeze") +def platform_pip_freeze(): + return list(freeze()) + + @app.event(filters=filters) async def aleph_event(event): print("aleph_event", event)