Skip to content

Commit

Permalink
Merge pull request #110 from stckme/remove_autorollback
Browse files Browse the repository at this point in the history
Removed deprecated autorollback
  • Loading branch information
gauravr authored Oct 7, 2024
2 parents 3ed30bc + 70901e4 commit 9eb952a
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 165 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.12
python-version: 3.9
cache: "pip"
cache-dependency-path: "**/requirements_dev.txt"
- name: Run tests
run: |
export SETTINGS_DIR=.
pip install -r requirements_dev.txt
pip install -e .
# pre-commit run --all-files TODO: check what's wrong in CI
pre-commit run --all-files
pytest fastapi_tests
pytest tests
18 changes: 4 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
exclude: ^(data/|app/templates/|tests/data)
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args:
- --profile=black
- --filter-files
- --force-grid-wrap=3

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.8.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
language_version: python3

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand Down
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ install:

before_script:
- psql -c 'create database defaultdb;' -U postgres
#- hug -f tests/service.py &
- gunicorn tests.service:__hug_wsgi__ -D
- sleep 2

script: tox

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
History
=======

0.96.2 (2024-10-07)
-------------------
* Removed deprecated peewee autorollback option.

0.96.1 (2024-09-26)
-------------------
* Added annotated fastapi dependencies.
Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Ready to contribute? Here's how to set up `apphelpers` for local development.

$ export SETTINGS_DIR=.
$ docker-compose up -d # start postgres and redis
$ gunicorn tests.service:__hug_wsgi__
$ pytest tests

6. When you're done making changes for fastapi, check that your changes pass flake8 and the
Expand All @@ -92,7 +91,6 @@ Ready to contribute? Here's how to set up `apphelpers` for local development.

$ export SETTINGS_DIR=.
$ docker-compose up -d # start postgres and redis
$ uvicorn fastapi_tests.service:app --host 0.0.0.0 --port 5000
$ pytest fastapi_tests

7. Commit your changes and push your branch to GitHub::
Expand Down
2 changes: 1 addition & 1 deletion apphelpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = """Scroll Tech"""
__email__ = "[email protected]"
__version__ = "0.96.1"
__version__ = "0.96.2"
19 changes: 12 additions & 7 deletions apphelpers/db/peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def create_pgdb_pool(
user=user,
password=password,
max_connections=max_connections,
autorollback=True,
register_hstore=False,
stale_timeout=60 * 2,
) # 2 minutes
Expand All @@ -54,7 +53,12 @@ class Meta:
only_save_dirty = True

def to_dict(self, only=None, exclude=None, recurse=False):
return model_to_dict(self, only=only, exclude=exclude, recurse=recurse)
return model_to_dict(
self,
only=only,
exclude=exclude,
recurse=recurse,
)

return BaseModel

Expand All @@ -77,8 +81,8 @@ def dbtransaction_ctx(db):
def dbtransaction(db):
"""
wrapper that make db transactions automic
note db connections are used only when it is needed (hence there is no usual
connection open/close)
note db connections are used only when it is needed (hence there is no
usual connection open/close)
"""

def wrapper(f):
Expand All @@ -97,8 +101,8 @@ def enumify(TheModel, name_field="name", val_field="id"):
Converts a model rows into an enum
Can be effective cache for mostly unchanging data.
Limitation: No auto updates. If you update the model and you are using
process manager like gunicorn you would need to restart to rnsure enums are
updated
process manager like gunicorn you would need to restart to rnsure enums
are updated
eg.
>>> class Week(BaseModel):
Expand Down Expand Up @@ -130,7 +134,8 @@ def get_sub_models(base_model):


# Useful functions for test/dev setups
# NOTE: For below functions, models is list of model classes sorted by dependency
# NOTE: For below functions, models is list of model classes sorted by
# dependency
# Example: [Author, Publication, Post, Comment]


Expand Down
12 changes: 2 additions & 10 deletions apphelpers/db/piccolo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
from contextlib import asynccontextmanager
from functools import wraps
from typing import (
List,
Set,
Type,
)
from typing import List, Set, Type

from piccolo.engine.postgres import PostgresEngine
from piccolo.table import (
Table,
create_db_tables_sync,
drop_db_tables_sync,
)
from piccolo.table import Table, create_db_tables_sync, drop_db_tables_sync


@asynccontextmanager
Expand Down
12 changes: 2 additions & 10 deletions apphelpers/rest/common.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
from __future__ import annotations

from dataclasses import (
asdict,
dataclass,
field,
)
from typing import (
Dict,
List,
Optional,
)
from dataclasses import asdict, dataclass, field
from typing import Dict, List, Optional

from converge import settings
from requests.exceptions import HTTPError
Expand Down
12 changes: 2 additions & 10 deletions apphelpers/rest/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from typing import Annotated

from converge import settings
from fastapi import (
APIRouter,
Depends,
Header,
)
from fastapi import APIRouter, Depends, Header
from fastapi.routing import APIRoute
from starlette.requests import Request

Expand All @@ -20,11 +16,7 @@
InvalidSessionError,
)
from apphelpers.rest import endpoint as ep
from apphelpers.rest.common import (
User,
notify_honeybadger,
phony,
)
from apphelpers.rest.common import User, notify_honeybadger, phony
from apphelpers.sessions import SessionDBHandler

if settings.get("HONEYBADGER_API_KEY"):
Expand Down
6 changes: 1 addition & 5 deletions apphelpers/rest/hug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

import hug
from converge import settings
from falcon import (
HTTPForbidden,
HTTPNotFound,
HTTPUnauthorized,
)
from falcon import HTTPForbidden, HTTPNotFound, HTTPUnauthorized
from hug.decorators import wraps

from apphelpers.db import dbtransaction
Expand Down
7 changes: 1 addition & 6 deletions apphelpers/utilities/caching.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from __future__ import annotations

import json
from typing import (
Any,
ClassVar,
List,
Optional,
)
from typing import Any, ClassVar, List, Optional

from redis import Redis

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

sys.path.insert(0, os.path.abspath(".."))

import apphelpers
import apphelpers # noqa E402

# -- General configuration ---------------------------------------------

Expand Down
8 changes: 1 addition & 7 deletions fastapi_tests/app/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
from pydantic import BaseModel

from apphelpers.rest import endpoint as ep
from apphelpers.rest.fastapi import (
header,
json_body,
user,
user_agent,
user_id,
)
from apphelpers.rest.fastapi import header, json_body, user, user_agent, user_id
from fastapi_tests.app.models import Book


Expand Down
8 changes: 4 additions & 4 deletions fastapi_tests/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

sys.path.append(os.getcwd() + "/..")

import settings
from apphelpers.rest.fastapi import APIFactory
from fastapi_tests.app.endpoints import setup_routes
from fastapi_tests.app.models import db
import settings # noqa E402
from apphelpers.rest.fastapi import APIFactory # noqa E402
from fastapi_tests.app.endpoints import setup_routes # noqa E402
from fastapi_tests.app.models import db # noqa E402


def make_app():
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pre-commit
fastapi
httpx
pytest
pytz
uvicorn
celery
requests
Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.96.1
current_version = 0.96.2
commit = True
tag = True

Expand All @@ -16,5 +16,10 @@ universal = 1

[flake8]
exclude = docs
max-line-length = 88

[isort]
multi_line_output = 3
profile = black

[aliases]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/scrolltech/apphelpers",
version="0.96.1",
version="0.96.2",
zip_safe=False,
)
6 changes: 1 addition & 5 deletions tests/test_peewee.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from peewee import TextField

import settings
from apphelpers.db.peewee import (
create_base_model,
create_pgdb_pool,
dbtransaction,
)
from apphelpers.db.peewee import create_base_model, create_pgdb_pool, dbtransaction

db = create_pgdb_pool(
host=settings.DB_HOST,
Expand Down
Loading

0 comments on commit 9eb952a

Please sign in to comment.