Skip to content

Commit 079d162

Browse files
authored
Use ruff for linting (#17)
1 parent 5ee62a9 commit 079d162

File tree

8 files changed

+44
-47
lines changed

8 files changed

+44
-47
lines changed

pyproject.toml

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ classifiers = [
2828

2929
[tool.poetry.dependencies]
3030
python = "^3.7"
31-
SQLAlchemy = ">=1.4,<1.5.0"
31+
SQLAlchemy = ">=1.4,<1.5"
3232
apache-libcloud = ">=3.6.0,<3.7"
3333

3434
[tool.poetry.dev-dependencies]
35-
pytest = "^7.1.2"
35+
pytest = "^7.2.0"
36+
mypy = "0.991"
37+
black = "22.10.0"
38+
ruff = "0.0.139"
3639
sqlmodel = "^0.0.8"
37-
Pillow = "^9.2.0"
40+
Pillow = "^9.3.0"
3841
fasteners = "^0.18"
39-
black = "^22.6.0"
40-
coverage = { extras = ["toml"], version = "^6.4.2" }
41-
flake8 = "^3.9.2"
42-
mypy = "^0.982"
43-
isort = "^5.10.1"
44-
mkdocs-material = "^8.4.3"
42+
coverage = { extras = ["toml"], version = "^6.5.0" }
43+
mkdocs-material = "^8.5.10"
4544
PyMySQL = { extras = ["rsa"], version = "^1.0.2" }
46-
psycopg2-binary = "^2.9.3"
45+
psycopg2-binary = "^2.9.5"
4746
mkdocstrings = { extras = ["python"], version = "^0.19.0" }
48-
fastapi = "^0.85.1"
49-
uvicorn = "^0.18.2"
47+
fastapi = "^0.87.0"
48+
uvicorn = "^0.20.0"
5049
python-multipart = "^0.0.5"
5150
Flask = "^2.2.2"
5251
Flask-SQLAlchemy = "^2.5.1"
5352
importlib-metadata = { version = "<5.0", python = "<=3.7" }
5453

54+
5555
[tool.coverage.report]
5656
fail_under = 95
5757
show_missing = true
@@ -65,30 +65,22 @@ parallel = true
6565
command_line = "-m pytest"
6666
source = ["sqlalchemy_file", "tests"]
6767

68-
[tool.isort]
69-
profile = "black"
70-
known_third_party = ["sqlalchemy_file"]
71-
skip_glob = [
72-
"sqlalchemy_file/__init__.py",
68+
[tool.ruff]
69+
select = [
70+
"E", # pycodestyle errors
71+
"W", # pycodestyle warnings
72+
"F", # pyflakes
73+
"I", # isort
74+
"C", # flake8-comprehensions
75+
"B", # flake8-bugbear
7376
]
74-
src_paths = ["sqlalchemy_file", "tests"]
77+
ignore = ["E501", "B904"]
78+
79+
[tool.ruff.isort]
80+
known-third-party = ["sqlalchemy_file"]
7581

7682
[tool.mypy]
77-
disallow_any_generics = true
78-
disallow_subclassing_any = true
79-
disallow_untyped_calls = false
80-
disallow_untyped_defs = true
81-
disallow_incomplete_defs = true
82-
check_untyped_defs = true
83-
disallow_untyped_decorators = true
84-
no_implicit_optional = true
85-
warn_redundant_casts = true
86-
warn_unused_ignores = true
87-
warn_return_any = true
88-
implicit_reexport = false
89-
strict_equality = true
90-
ignore_missing_imports = true
91-
exclude = 'tests/'
83+
strict = true
9284

9385

9486
[build-system]

scripts/format.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
ruff sqlalchemy_file tests --fix
6+
black .

scripts/lint.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ set -e
44
set -x
55

66
mypy sqlalchemy_file
7-
flake8 sqlalchemy_file tests docs_src
8-
black sqlalchemy_file tests docs_src --check
9-
isort sqlalchemy_file tests docs_src --check-only
7+
ruff sqlalchemy_file tests
8+
black sqlalchemy_file tests --check

sqlalchemy_file/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_metadata_file_obj(metadata: Dict[str, Any]) -> "SpooledTemporaryFile[byt
1717
return f
1818

1919

20-
def get_content_from_file_obj(fileobj): # type: ignore
20+
def get_content_from_file_obj(fileobj: Any) -> Any:
2121
"""Provides a real file object from file content
2222
Converts ``str`` and ``bytes`` to an actual file.
2323
"""
@@ -31,21 +31,21 @@ def get_content_from_file_obj(fileobj): # type: ignore
3131
return fileobj
3232

3333

34-
def get_filename_from_fileob(fileobj): # type: ignore
34+
def get_filename_from_fileob(fileobj: Any) -> Any:
3535
if getattr(fileobj, "filename", None) is not None:
3636
return fileobj.filename
3737
elif getattr(fileobj, "name", None) is not None:
3838
return os.path.basename(fileobj.name)
3939
return "unnamed"
4040

4141

42-
def get_content_type_from_fileobj(fileobj, filename): # type: ignore
42+
def get_content_type_from_fileobj(fileobj: Any, filename: str) -> Any:
4343
if getattr(fileobj, "content_type", None) is not None:
4444
return fileobj.content_type
4545
return mimetypes.guess_type(filename, strict=False)[0] or "application/octet-stream"
4646

4747

48-
def get_content_size_from_fileobj(file): # type: ignore
48+
def get_content_size_from_fileobj(file: Any) -> Any:
4949
if hasattr(file, "size"):
5050
return file.size
5151
if hasattr(file, "name"):

sqlalchemy_file/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(
9999
self.thumbnail_format = thumbnail_format
100100

101101
def process(self, file: "File", upload_storage: Optional[str] = None) -> None:
102-
from PIL import Image
102+
from PIL import Image # type: ignore
103103

104104
content = file.original_content
105105
img = Image.open(content)

sqlalchemy_file/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __init__(
152152

153153

154154
class FileFieldSessionTracker(object):
155-
mapped_entities: Dict[Type[Any], List[str]] = dict()
155+
mapped_entities: Dict[Type[Any], List[str]] = {}
156156

157157
@classmethod
158158
def delete_files(cls, paths: Set[str], ctx: str) -> None:
@@ -162,9 +162,9 @@ def delete_files(cls, paths: Set[str], ctx: str) -> None:
162162
@classmethod
163163
def clear_session(cls, session: Session) -> None:
164164
if hasattr(session, "_new_files"):
165-
del session._new_files # type: ignore
165+
del session._new_files
166166
if hasattr(session, "_old_files"):
167-
del session._old_files # type: ignore
167+
del session._old_files
168168

169169
@classmethod
170170
def add_new_files_to_session(cls, session: Session, paths: List[str]) -> None:

sqlalchemy_file/validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ def __init__(
172172
max_aspect_ratio: Optional[float] = None,
173173
allowed_content_types: Optional[List[str]] = None,
174174
):
175-
from PIL import Image
175+
from PIL import Image # type: ignore
176176

177177
Image.init()
178178
super().__init__(
179179
allowed_content_types
180180
if allowed_content_types is not None
181-
else [type for type in Image.MIME.values()]
181+
else list(Image.MIME.values())
182182
)
183183
self.min_width, self.min_height = min_wh if min_wh else (None, None)
184184
self.max_width, self.max_height = max_wh if max_wh else (None, None)

tests/test_sqlmodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Attachment(SQLModel, table=True):
3131
__tablename__ = "attachment"
3232

3333
id: int = Field(None, primary_key=True)
34-
name: str = Field(..., sa_column_kwargs=dict(unique=True))
34+
name: str = Field(..., sa_column_kwargs={"unique": True})
3535
content: Any = Field(sa_column=Column(FileField))
3636

3737

0 commit comments

Comments
 (0)