]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
💚 Fix CI installs and tests (#2)
authorSebastián Ramírez <tiangolo@gmail.com>
Tue, 24 Aug 2021 18:14:33 +0000 (20:14 +0200)
committerGitHub <noreply@github.com>
Tue, 24 Aug 2021 18:14:33 +0000 (20:14 +0200)
.github/workflows/build-docs.yml
.github/workflows/publish.yml
.github/workflows/test.yml
pyproject.toml
scripts/test.sh
scripts/zip-docs.sh [new file with mode: 0644]
sqlmodel/main.py
sqlmodel/orm/session.py
sqlmodel/sql/expression.py

index 355987464376957af5b4814cd5f19b1f15293616..82402f537ad41ca104f9dc4d96dd9a7409f0c5b7 100644 (file)
@@ -3,6 +3,12 @@ on:
   push:
   pull_request:
     types: [opened, synchronize]
+  workflow_dispatch:
+    inputs:
+      debug_enabled:
+        description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'     
+        required: false
+        default: false
 jobs:
   build-docs:
     runs-on: ubuntu-20.04
@@ -16,32 +22,39 @@ jobs:
         uses: actions/setup-python@v2
         with:
           python-version: "3.7"
+      # Allow debugging with tmate
+      - name: Setup tmate session
+        uses: mxschmitt/action-tmate@v3
+        if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
+        with:
+          limit-access-to-actor: true
       - uses: actions/cache@v2
         id: cache
         with:
           path: ${{ env.pythonLocation }}
-          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-docs
+          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-root-docs
       - name: Install poetry
         if: steps.cache.outputs.cache-hit != 'true'
+        # TODO: remove python -m pip install --force git+https://github.com/python-poetry/poetry-core.git@ad33bc2
+        # once there's a release of Poetry 1.2.x including poetry-core > 1.1.0a6
+        # Ref: https://github.com/python-poetry/poetry-core/pull/188
         run: |
           python -m pip install --upgrade pip
-          python -m pip install "poetry>=1.2.0a1"
-          python -m poetry plugin add poetry-version-plugin 
+          python -m pip install --force git+https://github.com/python-poetry/poetry-core.git@ad33bc2
+          python -m pip install "poetry==1.2.0a2"
+          python -m poetry plugin add poetry-version-plugin
       - name: Configure poetry
-        run: python -m poetry config virtualenvs.in-project true
-      - name: Ensure cache is healthy
-        if: steps.cache.outputs.cache-hit == 'true'
-        run: python -m poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
+        run: python -m poetry config virtualenvs.create false
       - name: Install Dependencies
         if: steps.cache.outputs.cache-hit != 'true'
         run: python -m poetry install
       - name: Install Material for MkDocs Insiders
         if: github.event.pull_request.head.repo.fork == false && steps.cache.outputs.cache-hit != 'true'
-        run: pip install git+https://${{ secrets.ACTIONS_TOKEN }}@github.com/squidfunk/mkdocs-material-insiders.git
+        run: python -m poetry run pip install git+https://${{ secrets.ACTIONS_TOKEN }}@github.com/squidfunk/mkdocs-material-insiders.git
       - name: Build Docs
-        run: python3.7 -m mkdocs build
+        run: python -m poetry run mkdocs build
       - name: Zip docs
-        run: bash ./scripts/zip-docs.sh
+        run: python -m poetry run bash ./scripts/zip-docs.sh
       - uses: actions/upload-artifact@v2
         with:
           name: docs-zip
index c75ecc0514fdfd14079047d3c9cd9e81fc413584..105dbdd4cc1148833af35da55064589df5155de5 100644 (file)
@@ -4,6 +4,12 @@ on:
   release:
     types:
       - created
+  workflow_dispatch:
+    inputs:
+      debug_enabled:
+        description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'     
+        required: false
+        default: false
 
 jobs:
   publish:
@@ -14,22 +20,29 @@ jobs:
         uses: actions/setup-python@v2
         with:
           python-version: "3.7"
+      # Allow debugging with tmate
+      - name: Setup tmate session
+        uses: mxschmitt/action-tmate@v3
+        if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
+        with:
+          limit-access-to-actor: true
       - uses: actions/cache@v2
         id: cache
         with:
           path: ${{ env.pythonLocation }}
-          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test
+          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-root
       - name: Install poetry
         if: steps.cache.outputs.cache-hit != 'true'
+        # TODO: remove python -m pip install --force git+https://github.com/python-poetry/poetry-core.git@ad33bc2
+        # once there's a release of Poetry 1.2.x including poetry-core > 1.1.0a6
+        # Ref: https://github.com/python-poetry/poetry-core/pull/188
         run: |
           python -m pip install --upgrade pip
-          python -m pip install "poetry>=1.2.0a1"
-          python -m poetry plugin add poetry-version-plugin 
+          python -m pip install --force git+https://github.com/python-poetry/poetry-core.git@ad33bc2
+          python -m pip install "poetry==1.2.0a2"
+          python -m poetry plugin add poetry-version-plugin
       - name: Configure poetry
-        run: python -m poetry config virtualenvs.in-project true
-      - name: Ensure cache is healthy
-        if: steps.cache.outputs.cache-hit == 'true'
-        run: python -m poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
+        run: python -m poetry config virtualenvs.create false
       - name: Install Dependencies
         if: steps.cache.outputs.cache-hit != 'true'
         run: python -m poetry install
index aa60d7faf0fe4bb77bba07a953cfee2adf51a925..6e15a7d6f77a448424fb2ea7933063b0ffda4c87 100644 (file)
@@ -4,6 +4,12 @@ on:
   push:
   pull_request:
     types: [opened, synchronize]
+  workflow_dispatch:
+    inputs:
+      debug_enabled:
+        description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'     
+        required: false
+        default: false
 
 jobs:
   test:
@@ -19,26 +25,36 @@ jobs:
         uses: actions/setup-python@v2
         with:
           python-version: ${{ matrix.python-version }}
+      # Allow debugging with tmate
+      - name: Setup tmate session
+        uses: mxschmitt/action-tmate@v3
+        if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
+        with:
+          limit-access-to-actor: true
       - uses: actions/cache@v2
         id: cache
         with:
           path: ${{ env.pythonLocation }}
-          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test
+          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-root
       - name: Install poetry
         if: steps.cache.outputs.cache-hit != 'true'
+        # TODO: remove python -m pip install --force git+https://github.com/python-poetry/poetry-core.git@ad33bc2
+        # once there's a release of Poetry 1.2.x including poetry-core > 1.1.0a6
+        # Ref: https://github.com/python-poetry/poetry-core/pull/188
         run: |
           python -m pip install --upgrade pip
-          python -m pip install "poetry>=1.2.0a1"
-          python -m poetry plugin add poetry-version-plugin 
+          python -m pip install --force git+https://github.com/python-poetry/poetry-core.git@ad33bc2
+          python -m pip install "poetry==1.2.0a2"
+          python -m poetry plugin add poetry-version-plugin
       - name: Configure poetry
-        run: python -m poetry config virtualenvs.in-project true
-      - name: Ensure cache is healthy
-        if: steps.cache.outputs.cache-hit == 'true'
-        run: python -m poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
+        run: python -m poetry config virtualenvs.create false
       - name: Install Dependencies
         if: steps.cache.outputs.cache-hit != 'true'
         run: python -m poetry install
+      - name: Lint
+        if: ${{ matrix.python-version != '3.6' }}
+        run: python -m poetry run bash scripts/lint.sh
       - name: Test
-        run: bash scripts/test.sh
+        run: python -m poetry run bash scripts/test.sh
       - name: Upload coverage
         uses: codecov/codecov-action@v1
index c4599b5f0d55e67835be14392e18190069bcc70f..e4d7a0ec14a596d59dc0a630485237647e6690bb 100644 (file)
@@ -47,6 +47,9 @@ coverage = {extras = ["toml"], version = "^5.5"}
 fastapi = "^0.68.0"
 requests = "^2.26.0"
 autoflake = "^1.4"
+isort = "^5.9.3"
+async_generator = {version = "*", python = "~3.6"}
+async-exit-stack = {version = "*", python = "~3.6"}
 
 [build-system]
 requires = ["poetry-core"]
index 139c1fb1c03dd4959b785d0958a4907d30d1ae8b..7fce865bd6459d4bdf335bb70e8910503ae911d9 100755 (executable)
@@ -6,3 +6,4 @@ set -x
 coverage run -m pytest tests
 coverage combine
 coverage report --show-missing
+coverage xml
diff --git a/scripts/zip-docs.sh b/scripts/zip-docs.sh
new file mode 100644 (file)
index 0000000..f2b7ba3
--- /dev/null
@@ -0,0 +1,9 @@
+#! /usr/bin/env bash
+
+set -x
+set -e
+
+if [ -f docs.zip ]; then
+    rm -rf docs.zip
+fi
+zip -r docs.zip ./site
index dd38dd2b80f6ad82d0f10a6856fb4e2769b5cab9..661276b31d30af565dbbefbfb0e26065423db682 100644 (file)
@@ -12,7 +12,6 @@ from typing import (
     Callable,
     ClassVar,
     Dict,
-    ForwardRef,
     List,
     Mapping,
     Optional,
@@ -30,7 +29,7 @@ from pydantic.errors import ConfigError, DictError
 from pydantic.fields import FieldInfo as PydanticFieldInfo
 from pydantic.fields import ModelField, Undefined, UndefinedType
 from pydantic.main import BaseConfig, ModelMetaclass, validate_model
-from pydantic.typing import NoArgAnyCallable, resolve_annotations
+from pydantic.typing import ForwardRef, NoArgAnyCallable, resolve_annotations
 from pydantic.utils import ROOT_KEY, Representation
 from sqlalchemy import (
     Boolean,
@@ -343,7 +342,7 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta):
                 )
                 relationship_to = temp_field.type_
                 if isinstance(temp_field.type_, ForwardRef):
-                    relationship_to = temp_field.type_.__forward_arg__
+                    relationship_to = temp_field.type_.__forward_arg__  # type: ignore
                 rel_kwargs: Dict[str, Any] = {}
                 if rel_info.back_populates:
                     rel_kwargs["back_populates"] = rel_info.back_populates
index a96544e9ef6d7a70f4f12df3b30864ec80772eca..d708f1e7e9dc80a70684f12bc599be183394c20e 100644 (file)
@@ -1,4 +1,4 @@
-from typing import Any, Mapping, Optional, Sequence, TypeVar, Union, overload
+from typing import Any, Mapping, Optional, Sequence, Type, TypeVar, Union, overload
 
 from sqlalchemy import util
 from sqlalchemy.orm import Query as _Query
@@ -118,13 +118,13 @@ class Session(_Session):
 
     def get(
         self,
-        entity: _T,
+        entity: Type[_T],
         ident: Any,
         options: Optional[Sequence[Any]] = None,
         populate_existing: bool = False,
         with_for_update: Optional[Union[Literal[True], Mapping[str, Any]]] = None,
         identity_token: Optional[Any] = None,
-    ) -> _T:
+    ) -> Optional[_T]:
         return super().get(
             entity,
             ident,
index e8a922e4d34e6429711f1d7d8c928824fed5f0f3..66063bf2364a4cd655557e7a8fe46db0847698c4 100644 (file)
@@ -45,10 +45,10 @@ else:
     class GenericSelectMeta(GenericMeta, _Select.__class__):  # type: ignore
         pass
 
-    class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
+    class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):  # type: ignore
         pass
 
-    class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):
+    class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta):  # type: ignore
         pass
 
     # Cast them for editors to work correctly, from several tricks tried, this works