-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1676 from Gozargah/ruff
Migrate code formatting from autopep8 to ruff
- Loading branch information
Showing
71 changed files
with
2,633 additions
and
2,943 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Code Format Checker | ||
on: | ||
push: | ||
branches: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
ruff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install Ruff | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install ruff | ||
- name: Run Ruff Format | ||
run: | | ||
ruff check --output-format=github . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,47 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker, DeclarativeBase | ||
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
from config import ( | ||
SQLALCHEMY_DATABASE_URL, | ||
SQLALCHEMY_POOL_SIZE, | ||
SQLIALCHEMY_MAX_OVERFLOW, | ||
) | ||
|
||
IS_SQLITE = SQLALCHEMY_DATABASE_URL.startswith('sqlite') | ||
IS_SQLITE = SQLALCHEMY_DATABASE_URL.startswith("sqlite") | ||
|
||
if IS_SQLITE: | ||
engine = create_engine( | ||
SQLALCHEMY_DATABASE_URL, | ||
connect_args={"check_same_thread": False} | ||
) | ||
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}) | ||
else: | ||
engine = create_engine( | ||
SQLALCHEMY_DATABASE_URL, | ||
pool_size=SQLALCHEMY_POOL_SIZE, | ||
max_overflow=SQLIALCHEMY_MAX_OVERFLOW, | ||
pool_recycle=3600, | ||
pool_timeout=10 | ||
pool_timeout=10, | ||
) | ||
|
||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
|
||
|
||
class Base(DeclarativeBase): | ||
pass | ||
|
||
|
||
class GetDB: # Context Manager | ||
def __init__(self): | ||
self.db = SessionLocal() | ||
|
||
def __enter__(self): | ||
return self.db | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
if isinstance(exc_value, SQLAlchemyError): | ||
self.db.rollback() # rollback on exception | ||
|
||
self.db.close() | ||
|
||
|
||
def get_db(): # Dependency | ||
with GetDB() as db: | ||
yield db |
Oops, something went wrong.