diff --git a/.cruft.json b/.cruft.json deleted file mode 100644 index fbc1487..0000000 --- a/.cruft.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "template": "https://github.com/Azure-Samples/Azure-Python-Standardization-Template-Generator", - "commit": "619a6b29afba8ca26c528526bc313294d5c414a4", - "checkout": null, - "context": { - "cookiecutter": { - "project_name": "azure", - "python_version": "3.12", - "project_backend": "fastapi", - "db_resource": "postgres-flexible", - "project_host": "appservice", - "web_port": "8000", - "__repo_name": "azure-fastapi-postgres-flexible-appservice", - "__src_folder_name": "azure-fastapi-postgres-flexible-appservice", - "__project_short_description": "Create a relecloud demo application with fastapi and postgres-flexible", - "_copy_without_render": [ - ".github/workflows/azure-dev.yml", - ".github/workflows/cruft.yml", - ".github/workflows/devcontainer-ci.yml", - ".github/workflows/format.yml" - ], - "_extensions": [ - "extensions.GetUrlForBackend" - ], - "_jinja2_env_vars": { - "lstrip_blocks": true, - "trim_blocks": true - }, - "_template": "https://github.com/Azure-Samples/Azure-Python-Standardization-Template-Generator" - } - }, - "directory": null -} \ No newline at end of file diff --git a/.github/workflows/audit-bicep.yml b/.github/workflows/audit-bicep.yml index 5633e15..7f8fc69 100644 --- a/.github/workflows/audit-bicep.yml +++ b/.github/workflows/audit-bicep.yml @@ -3,13 +3,11 @@ on: push: branches: - main - - cruft/update paths: - "infra/**" pull_request: branches: - main - - cruft/update paths: - "infra/**" workflow_dispatch: diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index f91fe40..531d972 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -5,7 +5,6 @@ on: push: branches: - main - - cruft/update # GitHub Actions workflow to deploy to Azure using azd # To configure required secrets for connecting to Azure, simply run `azd pipeline config` @@ -19,8 +18,6 @@ permissions: jobs: build: runs-on: ubuntu-latest - outputs: - uri: ${{ steps.output.outputs.uri }} env: AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} @@ -69,39 +66,3 @@ jobs: AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }} AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} - - - name: Output Deployment URI - id: output - run: | - azd env get-values > .env - source .env - echo "uri=$BACKEND_URI" >> "$GITHUB_OUTPUT" - - smoketests: - runs-on: ubuntu-latest - needs: build - steps: - - - name: Basic smoke test (curl) - env: - URI: ${{needs.build.outputs.uri}} - run: | - echo "Sleeping 1 minute due to https://github.com/Azure/azure-dev/issues/2669" - sleep 60 - curl -sSf $URI - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup python - uses: actions/setup-python@v4 - with: - python-version: 3.12 - - - name: End-to-end smoke tests (playwright) - env: - URI: ${{needs.build.outputs.uri}} - run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r requirements-dev.txt - python3 -m playwright install chromium --with-deps - python3 -m pytest --exitfirst src/tests/smoke/smoketests.py --live-server-url $URI diff --git a/.github/workflows/cruft.yml b/.github/workflows/cruft.yml deleted file mode 100644 index 2fed35b..0000000 --- a/.github/workflows/cruft.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Update repository with Cruft -permissions: - contents: write - pull-requests: write -on: - workflow_dispatch: - schedule: - - cron: "0 2 * * 1" # Every Monday at 2am -jobs: - update: - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - include: - - add-paths: . - body: Use this to merge the changes to this repository. - branch: cruft/update - commit-message: "chore: accept new Cruft update" - title: New updates detected with Cruft - - add-paths: .cruft.json - body: Use this to reject the changes in this repository. - branch: cruft/reject${{ github.run_id }} - commit-message: "chore: reject new Cruft update" - title: Reject new updates detected with Cruft - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-python@v4 - with: - python-version: "3.12" - - - name: Install Cruft - run: pip3 install -r requirements-dev.txt - - - name: Check if update is available - continue-on-error: false - id: check - run: | - CHANGES=0 - if [ -f .cruft.json ]; then - if ! cruft check; then - CHANGES=1 - fi - else - echo "No .cruft.json file" - fi - - echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" - - - name: Run update if available - if: steps.check.outputs.has_changes == '1' - run: | - git config --global user.email "you@example.com" - git config --global user.name "GitHub" - - cruft update --skip-apply-ask --refresh-private-variables - git restore --staged . - - - name: Create pull request - if: steps.check.outputs.has_changes == '1' - run: | - echo "::set-output name=branch::${{ matrix.branch }}" - echo "::set-output name=commit-message::${{ matrix.commit-message }}" - git checkout -b "${{ matrix.branch }}" - git add ${{ matrix.add-paths }} - git commit -m "${{ matrix.commit-message }}" - git push origin "${{ matrix.branch }}" diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 3f76605..b53b3af 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -5,15 +5,11 @@ on: branches: [ main ] paths-ignore: - '**.md' - - 'lab/**' - - 'assets/**' pull_request: branches: [ main ] paths-ignore: - '**.md' - - 'lab/**' - - 'assets/**' jobs: checks-format: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index acfe24f..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Run Python E2E tests - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test_package: - - name: Test ${{ matrix.os }} Python ${{ matrix.python_version }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: ["ubuntu-latest", "macos-13", "macos-latest-xlarge", "windows-latest"] - python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - exclude: - - os: macos-latest-xlarge - python_version: 3.8 - - os: macos-latest-xlarge - python_version: 3.9 - - os: macos-latest-xlarge - python_version: "3.10" - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Check for MacOS Runner - if: matrix.os == 'macos-latest-xlarge' - run: brew install postgresql@14 - - name: Setup postgres - uses: ikalnytskyi/action-setup-postgres@v6 - - name: Setup python - uses: actions/setup-python@v4 - with: - - python-version: ${{ matrix.python_version }} - architecture: x64 - - name: Install dependencies - run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r requirements-dev.txt - playwright install chromium --with-deps - python3 -m pip install -e src - - name: Seed data - run: | - python3 src/fastapi_app/seed_data.py - env: - POSTGRES_HOST: localhost - POSTGRES_USERNAME: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DATABASE: postgres - - name: Run tests Windows - if: runner.os == 'windows' - run: python3 -m pytest --ignore=src/tests/local/test_gunicorn.py - env: - POSTGRES_HOST: localhost - POSTGRES_USERNAME: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DATABASE: postgres - - name: Run tests - if: runner.os != 'windows' - run: python3 -m pytest - env: - POSTGRES_HOST: localhost - POSTGRES_USERNAME: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DATABASE: postgres \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index f573268..ad77dd8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,8 +11,10 @@ "module": "uvicorn", "args": [ "fastapi_app:app", - "--reload" + "--reload", + "--port=8888" ], + "justMyCode": false }, { "name": "Python: Debug Tests", diff --git a/README.md b/README.md index f7ed7dc..e825852 100644 --- a/README.md +++ b/README.md @@ -45,14 +45,12 @@ export POSTGRES_PASSWORD= python3 -m pip install -r src/requirements.txt ``` - 1. Install the app as an editable package: ```sh python3 -m pip install -e src ``` - 1. Apply database migrations and seed initial data: ```sh @@ -67,7 +65,6 @@ If you're running the app inside VS Code or GitHub Codespaces, you can use the " python3 -m uvicorn fastapi_app:app --reload --port=8000 ``` - ## Running tests 1. Install the development requirements: @@ -122,4 +119,3 @@ to be stored as Github action secrets. To set that up, run: ```shell azd pipeline config ``` - diff --git a/azure.yaml b/azure.yaml index 028cd6c..44eaa2d 100644 --- a/azure.yaml +++ b/azure.yaml @@ -1,9 +1,9 @@ # yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json -name: azure-fastapi-postgres-flexible-appservice +name: python-app-service-postgresql-fastapi metadata: - template: azure-fastapi-postgres-flexible-appservice@0.0.1 + template: python-app-service-postgresql-fastapi@0.0.1 infra: provider: "bicep" services: diff --git a/pyproject.toml b/pyproject.toml index 1e0a350..2fe696d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,9 @@ [tool.ruff] line-length = 120 + +[tool.ruff.lint] select = ["E", "F", "I", "UP"] ignore = ["D203"] -extend-exclude = ["src/flaskapp/migrations/"] -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["fastapi_app"] - -[tool.pytest.ini_options] -addopts = "-ra -vv" - -[tool.coverage.report] -show_missing = true diff --git a/requirements-dev.txt b/requirements-dev.txt index 6784c50..dbc3251 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,16 +1,2 @@ -r src/requirements.txt - -# Cookiecutter Support -cruft -pip-tools - -# Testing Tools -pytest -ephemeral-port-reserve -pytest-playwright -coverage -pytest-cov -axe-playwright-python - -# Linters ruff diff --git a/src/fastapi_app/models.py b/src/fastapi_app/models.py index 7a73391..305cef0 100644 --- a/src/fastapi_app/models.py +++ b/src/fastapi_app/models.py @@ -2,8 +2,8 @@ # ruff: noqa: UP006 import os import typing - from datetime import datetime + from sqlmodel import Field, SQLModel, create_engine POSTGRES_USERNAME = os.environ.get("POSTGRES_USERNAME")