Skip to content

Commit

Permalink
reforat with ruff, fix jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
collerek committed Jan 25, 2024
1 parent c5a10fb commit 87ecdbc
Show file tree
Hide file tree
Showing 219 changed files with 1,399 additions and 1,189 deletions.
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Lint
run: make style
run: python -m ruff . --fix
2 changes: 1 addition & 1 deletion .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Lint
run: make type_check
run: python -m mypy . --ignore-missing-imports --install-types --non-interactive
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ test:
coverage:
pytest --cov=ormar --cov=tests --cov-fail-under=100 --cov-report=term-missing


fmt:
poetry run python -m black --line-length=120 .

type_check:
mkdir -p .mypy_cache && poetry run python -m mypy . --ignore-missing-imports --install-types --non-interactive

lint:
poetry run python -m ruff . --fix

style: fmt lint
poetry run python -m ruff . --fix
4 changes: 2 additions & 2 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

import databases
import nest_asyncio
import ormar
import pytest
import pytest_asyncio
import sqlalchemy

import ormar
from tests.settings import DATABASE_URL

nest_asyncio.apply()
Expand All @@ -25,6 +24,7 @@
database=database,
)


class Author(ormar.Model):
class Meta(BaseMeta):
tablename = "authors"
Expand Down
4 changes: 2 additions & 2 deletions docs_src/aggregations/docs001.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

import databases
import sqlalchemy

import ormar
import sqlalchemy
from tests.settings import DATABASE_URL

database = databases.Database(DATABASE_URL)
Expand All @@ -15,6 +14,7 @@
database=database,
)


class Author(ormar.Model):
class Meta(BaseMeta):
tablename = "authors"
Expand Down
3 changes: 1 addition & 2 deletions docs_src/fastapi/docs001.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import List, Optional

import databases
import ormar
import sqlalchemy
from fastapi import FastAPI

import ormar

app = FastAPI()
metadata = sqlalchemy.MetaData()
database = databases.Database("sqlite:///test.db")
Expand Down
3 changes: 1 addition & 2 deletions docs_src/fastapi/mypy/docs001.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/fields/docs001.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
7 changes: 4 additions & 3 deletions docs_src/fields/docs002.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand All @@ -26,7 +25,9 @@ class Meta:
id: int = ormar.Integer(primary_key=True)
name: str = ormar.String(max_length=100)
completed: bool = ormar.Boolean(default=False)
department: Optional[Department] = ormar.ForeignKey(Department, related_name="my_courses")
department: Optional[Department] = ormar.ForeignKey(
Department, related_name="my_courses"
)


department = Department(name="Science")
Expand Down
3 changes: 1 addition & 2 deletions docs_src/fields/docs003.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/fields/docs004.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from datetime import datetime

import databases
import ormar
import sqlalchemy
from sqlalchemy import func, text

import ormar

database = databases.Database("sqlite:///test.db")
metadata = sqlalchemy.MetaData()

Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs001.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs002.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs003.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
7 changes: 4 additions & 3 deletions docs_src/models/docs004.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()


class Course(ormar.Model):
class Meta(ormar.ModelMeta): # note you don't have to subclass - but it's recommended for ide completion and mypy
class Meta(
ormar.ModelMeta
): # note you don't have to subclass - but it's recommended for ide completion and mypy
database = database
metadata = metadata

Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs005.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs006.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs007.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs008.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///test.db", force_rollback=True)
metadata = sqlalchemy.MetaData()
Expand Down
2 changes: 1 addition & 1 deletion docs_src/models/docs009.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Optional

import databases
import ormar
import sqlalchemy

import ormar
from .docs010 import Artist # previous example

database = databases.Database("sqlite:///test.db", force_rollback=True)
Expand Down
2 changes: 1 addition & 1 deletion docs_src/models/docs010.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import databases
import ormar
import sqlalchemy

import ormar
from .docs008 import Child

database = databases.Database("sqlite:///test.db", force_rollback=True)
Expand Down
6 changes: 3 additions & 3 deletions docs_src/models/docs011.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand All @@ -16,4 +15,5 @@ class Meta:
name: ormar.String(max_length=100)
completed: ormar.Boolean(default=False)

c1 = Course()

c1 = Course()
3 changes: 1 addition & 2 deletions docs_src/models/docs012.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs013.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///test.db", force_rollback=True)
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs014.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs015.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy
from ormar import property_field

database = databases.Database("sqlite:///db.sqlite")
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs016.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
3 changes: 1 addition & 2 deletions docs_src/models/docs017.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import databases
import sqlalchemy

import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
4 changes: 2 additions & 2 deletions docs_src/models/docs018.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
import databases
import sqlalchemy

import databases
import ormar
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()
Expand Down
17 changes: 10 additions & 7 deletions docs_src/queries/docs002.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ class Meta:
id: int = ormar.Integer(primary_key=True)
title: str = ormar.String(max_length=200)
author: str = ormar.String(max_length=100)
genre: str = ormar.String(max_length=100, default='Fiction',
choices=['Fiction', 'Adventure', 'Historic', 'Fantasy'])
genre: str = ormar.String(
max_length=100,
default="Fiction",
choices=["Fiction", "Adventure", "Historic", "Fantasy"],
)


await Book.objects.create(title='Tom Sawyer', author="Twain, Mark", genre='Adventure')
await Book.objects.create(title='War and Peace', author="Tolstoy, Leo", genre='Fiction')
await Book.objects.create(title='Anna Karenina', author="Tolstoy, Leo", genre='Fiction')
await Book.objects.create(title="Tom Sawyer", author="Twain, Mark", genre="Adventure")
await Book.objects.create(title="War and Peace", author="Tolstoy, Leo", genre="Fiction")
await Book.objects.create(title="Anna Karenina", author="Tolstoy, Leo", genre="Fiction")

await Book.objects.update(each=True, genre='Fiction')
all_books = await Book.objects.filter(genre='Fiction').all()
await Book.objects.update(each=True, genre="Fiction")
all_books = await Book.objects.filter(genre="Fiction").all()
assert len(all_books) == 3
19 changes: 12 additions & 7 deletions docs_src/queries/docs003.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ class Meta:
id: int = ormar.Integer(primary_key=True)
title: str = ormar.String(max_length=200)
author: str = ormar.String(max_length=100)
genre: str = ormar.String(max_length=100, default='Fiction',
choices=['Fiction', 'Adventure', 'Historic', 'Fantasy'])
genre: str = ormar.String(
max_length=100,
default="Fiction",
choices=["Fiction", "Adventure", "Historic", "Fantasy"],
)


await Book.objects.create(title='Tom Sawyer', author="Twain, Mark", genre='Adventure')
await Book.objects.create(title='War and Peace', author="Tolstoy, Leo", genre='Fiction')
await Book.objects.create(title='Anna Karenina', author="Tolstoy, Leo", genre='Fiction')
await Book.objects.create(title="Tom Sawyer", author="Twain, Mark", genre="Adventure")
await Book.objects.create(title="War and Peace", author="Tolstoy, Leo", genre="Fiction")
await Book.objects.create(title="Anna Karenina", author="Tolstoy, Leo", genre="Fiction")

# if not exist the instance will be persisted in db
vol2 = await Book.objects.update_or_create(title="Volume II", author='Anonymous', genre='Fiction')
vol2 = await Book.objects.update_or_create(
title="Volume II", author="Anonymous", genre="Fiction"
)
assert await Book.objects.count() == 1

# if pk or pkname passed in kwargs (like id here) the object will be updated
assert await Book.objects.update_or_create(id=vol2.id, genre='Historic')
assert await Book.objects.update_or_create(id=vol2.id, genre="Historic")
assert await Book.objects.count() == 1
Loading

0 comments on commit 87ecdbc

Please sign in to comment.