Skip to content

Commit

Permalink
Chore: split models.py into separate files for ease of maintenance (#660
Browse files Browse the repository at this point in the history
)

* split models.py into separate files for ease of maintenance

* fix circular imports

* remove comment

* remove unnecessary List import

* pr comments and isort

* added changelog

* isorted everything

* revert API docs changes

* fix tests

* cleanse db.py

* remove type checking from code coverage

* Fix imports

* I can't spell
  • Loading branch information
danted22 authored Aug 11, 2024
1 parent f040f2c commit 390213b
Show file tree
Hide file tree
Showing 58 changed files with 1,029 additions and 763 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[run]
omit = tests/*,migrations/*,update_changelog.py

[report]
exclude_lines =
pragma: no cover
if TYPE_CHECKING:
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ repos:
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

import os

from create_app import create_app
from config import SAHConfig
from create_app import create_app

DB_CREDENTIALS_PATH = os.environ.get("DB_CREDENTIALS_PATH", "")

Expand Down
16 changes: 9 additions & 7 deletions auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from typing import Any, cast, TypedDict
from datetime import datetime

from functools import wraps
from quart import request
from sqlalchemy import select
from typing import Any, TypedDict, cast

from firebase_admin import App # type: ignore
from firebase_admin.auth import ( # type: ignore
verify_id_token,
InvalidIdTokenError,
ExpiredIdTokenError,
InvalidIdTokenError,
RevokedIdTokenError,
verify_id_token,
)
from quart import request
from sqlalchemy import select

from models import User, SendADatabase
from config import SAHConfig

from models import SendADatabase
from models.schemas.users import User


class RoleData(TypedDict):
id: int
Expand Down
13 changes: 13 additions & 0 deletions changelog/pr660.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pr_number": 660,
"changes": [
{
"change": "Chores",
"description": "Split out models.py to separate model files for easier maintenance."
},
{
"change": "Chores",
"description": "Added isort to keep imports in a consistent order."
}
]
}
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import json
import os
from typing import TypedDict

from firebase_admin import initialize_app # type: ignore
Expand Down
38 changes: 17 additions & 21 deletions create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,37 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import json
from typing import Any, Literal, cast, Sequence
from datetime import datetime
import json
import os
from typing import Any, Literal, Sequence, cast

from quart import Quart, Response, request, abort, jsonify
from pywebpush import WebPushException, webpush # type: ignore
from quart import Quart, Response, abort, jsonify, request
from quart_cors import cors
from pywebpush import webpush, WebPushException # type: ignore
from sqlalchemy import Text, and_, delete, desc, false, func, or_, select, true, update

from auth import AuthError, UserData, requires_auth
from config import SAHConfig

from models import (
Post,
User,
BLOCKED_USER_ROLE_ID,
Filter,
Message,
Thread,
Report,
Notification,
NotificationSub,
Filter,
CoreSAHModel,
BLOCKED_USER_ROLE_ID,
)
from auth import (
AuthError,
UserData,
requires_auth,
Post,
Report,
User,
)
from utils.validator import Validator, ValidationError
from models.common import CoreSAHModel
from models.schemas.messages import Thread
from utils.push_notifications import (
RawPushData,
generate_push_data,
generate_vapid_claims,
RawPushData,
)
from config import SAHConfig

from utils.validator import ValidationError, Validator

DATETIME_PATTERN = "%Y-%m-%dT%H:%M:%S.%fZ"

Expand Down
11 changes: 6 additions & 5 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import asyncio
from logging.config import fileConfig
from logging import getLogger

# from sqlalchemy import pool
from sqlalchemy.engine import Connection
from logging.config import fileConfig

# from sqlalchemy.ext.asyncio import async_engine_from_config
from alembic import context

from models.models import BaseModel
# from sqlalchemy import pool
from sqlalchemy.engine import Connection

from app import config as app_config

from models.common import BaseModel

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
alembic_config = context.config
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200519_1927_9114f1efc30c_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "9114f1efc30c"
down_revision = None
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200519_1928_340ea6984fd5_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "340ea6984fd5"
down_revision = "9114f1efc30c"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200519_1947_8300b1f00fc2_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "8300b1f00fc2"
down_revision = "340ea6984fd5"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200520_1224_e05f567d5754_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "e05f567d5754"
down_revision = "8300b1f00fc2"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200526_2006_fbd822a8ecd6_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "fbd822a8ecd6"
down_revision = "e05f567d5754"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200530_1213_4822d58838df_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "4822d58838df"
down_revision = "fbd822a8ecd6"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200609_1356_2a32dd21c76e_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "2a32dd21c76e"
down_revision = "4822d58838df"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200614_1300_ee014068582b_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "ee014068582b"
down_revision = "2a32dd21c76e"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200620_2253_01fd6b9a8c9a_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "01fd6b9a8c9a"
down_revision = "ee014068582b"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200620_2304_8c92b636cfca_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "8c92b636cfca"
down_revision = "01fd6b9a8c9a"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200621_1832_8e2b04523898_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "8e2b04523898"
down_revision = "8c92b636cfca"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200621_1843_2cd3e0bd28db_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "2cd3e0bd28db"
down_revision = "8e2b04523898"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200621_1918_55c97dad811f_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "55c97dad811f"
down_revision = "2cd3e0bd28db"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200623_1610_40d525bf350e_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "40d525bf350e"
down_revision = "1249cc3ed069"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200623_1624_eb02c1ca03ec_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "eb02c1ca03ec"
down_revision = "40d525bf350e"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200623_1630_26e414955820_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "26e414955820"
down_revision = "eb02c1ca03ec"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200707_1002_eee3f01a8ec9_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "eee3f01a8ec9"
down_revision = "26e414955820"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200707_1026_1f97056a4575_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "1f97056a4575"
down_revision = "eee3f01a8ec9"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200708_1206_028d27d5e5d0_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "028d27d5e5d0"
down_revision = "e9aef1311cba"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200709_1516_1c6735c6ed2a_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "1c6735c6ed2a"
down_revision = "028d27d5e5d0"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200720_1717_9c07afe43ee4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "9c07afe43ee4"
down_revision = "1c6735c6ed2a"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20200724_1503_97ebcd9c039d_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "97ebcd9c039d"
down_revision = "9c07afe43ee4"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20201102_1521_5aa132f978ec_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "5aa132f978ec"
down_revision = "97ebcd9c039d"
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/20201220_1304_d8921945f241_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "d8921945f241"
down_revision = "5aa132f978ec"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "812b00a075e3"
down_revision = "d8921945f241"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "ca0fa484a1fa"
down_revision = "75b20813c7e9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "1d70342e9842"
down_revision = "ca0fa484a1fa"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "7cffbe81fc6b"
down_revision = "1d70342e9842"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "566bd4dfdf19"
down_revision = "7cffbe81fc6b"
Expand Down
Loading

0 comments on commit 390213b

Please sign in to comment.