Skip to content

Commit 493dcc5

Browse files
authored
Merge pull request #77 from jowilf/dev
Add additional Ruff rules & update dependencies
2 parents f1d480f + bd58d25 commit 493dcc5

26 files changed

+239
-197
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [ "3.7", "3.8", "3.9", "3.10","3.11" ]
16+
python-version: [ "3.8", "3.9", "3.10","3.11" ]
1717

1818
services:
1919
postgres:

.pre-commit-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@ repos:
1212
- id: end-of-file-fixer
1313
- id: trailing-whitespace
1414
- repo: https://github.com/asottile/pyupgrade
15-
rev: v3.3.1
15+
rev: v3.9.0
1616
hooks:
1717
- id: pyupgrade
1818
args:
19-
- --py3-plus
20-
- --keep-runtime-typing
19+
- --py38-plus
2120
- repo: https://github.com/charliermarsh/ruff-pre-commit
22-
rev: v0.0.254
21+
rev: v0.0.277
2322
hooks:
2423
- id: ruff
2524
args:
2625
- --fix
2726
- repo: https://github.com/psf/black
28-
rev: 23.1.0
27+
rev: 23.7.0
2928
hooks:
3029
- id: black

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ engine = create_engine(
111111
)
112112
Base.metadata.create_all(engine)
113113

114-
with Session(engine) as session:
115-
session.add(Attachment(name="attachment1", content=open("./example.txt", "rb")))
114+
with Session(engine) as session, open("./example.txt", "rb") as local_file:
115+
session.add(Attachment(name="attachment1", content=local_file))
116116
session.add(Attachment(name="attachment2", content=b"Hello world"))
117117
session.add(Attachment(name="attachment3", content="Hello world"))
118118
file = File(content="Hello World", filename="hello.txt", content_type="text/plain")

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ engine = create_engine(
110110
)
111111
Base.metadata.create_all(engine)
112112

113-
with Session(engine) as session:
114-
session.add(Attachment(name="attachment1", content=open("./example.txt", "rb")))
113+
with Session(engine) as session, open("./example.txt", "rb") as local_file:
114+
session.add(Attachment(name="attachment1", content=local_file))
115115
session.add(Attachment(name="attachment2", content=b"Hello world"))
116116
session.add(Attachment(name="attachment3", content="Hello world"))
117117
file = File(content="Hello World", filename="hello.txt", content_type="text/plain")

docs_src/example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class Attachment(Base):
3030
)
3131
Base.metadata.create_all(engine)
3232

33-
with Session(engine) as session:
34-
session.add(Attachment(name="attachment1", content=open("./example.txt", "rb")))
33+
with Session(engine) as session, open("./example.txt", "rb") as local_file:
34+
session.add(Attachment(name="attachment1", content=local_file))
3535
session.add(Attachment(name="attachment2", content=b"Hello world"))
3636
session.add(Attachment(name="attachment3", content="Hello world"))
3737
file = File(content="Hello World", filename="hello.txt", content_type="text/plain")

docs_src/tutorial/quick-start/save_your_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class Attachment(Base):
3030
)
3131
Base.metadata.create_all(engine)
3232

33-
with Session(engine) as session:
34-
session.add(Attachment(name="attachment1", content=open("./example.txt", "rb")))
33+
with Session(engine) as session, open("./example.txt", "rb") as local_file:
34+
session.add(Attachment(name="attachment1", content=local_file))
3535
session.add(Attachment(name="attachment2", content=b"Hello world"))
3636
session.add(Attachment(name="attachment3", content="Hello world"))
3737
# Use sqlalchemy_file.File object to provide custom filename and content_type

docs_src/tutorial/using-files-in-models/007_multiple_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ class Attachment(Base):
2929
)
3030
Base.metadata.create_all(engine)
3131

32-
with Session(engine) as session:
32+
with Session(engine) as session, open("./example.txt", "rb") as file:
3333
session.add(
3434
Attachment(
3535
name="attachment1",
3636
multiple_content=[
3737
"from str",
3838
b"from bytes",
39-
open("./example.txt", "rb"),
39+
file,
4040
File(
4141
content="Hello World",
4242
filename="hello.txt",

docs_src/tutorial/using-files-in-models/008_file_information.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class Attachment(Base):
3030
)
3131
Base.metadata.create_all(engine)
3232

33-
with Session(engine) as session:
34-
session.add(Attachment(name="attachment1", content=open("./example.txt", "rb")))
33+
with Session(engine) as session, open("./example.txt", "rb") as local_file:
34+
session.add(Attachment(name="attachment1", content=local_file))
3535
session.add(Attachment(name="attachment2", content=b"Hello world"))
3636
session.add(Attachment(name="attachment3", content="Hello world"))
3737
file = File(content="Hello World", filename="hello.txt", content_type="text/plain")

examples/fastapi/app.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import os
23
from typing import Generator, List, Optional, Union
34

@@ -31,13 +32,10 @@
3132
os.makedirs("./upload_dir", 0o777, exist_ok=True)
3233
driver = get_driver(Provider.LOCAL)("./upload_dir")
3334

34-
# cls = get_driver(Provider.MINIO)
35-
# driver = cls("minioadmin", "minioadmin", secure=False, host="127.0.0.1", port=9000)
3635

37-
try:
36+
with contextlib.suppress(ContainerAlreadyExistsError):
3837
driver.create_container(container_name="category")
39-
except ContainerAlreadyExistsError:
40-
pass
38+
4139

4240
container = driver.get_container(container_name="category")
4341

@@ -135,7 +133,7 @@ async def serve_files(storage: str = Path(...), file_id: str = Path(...)):
135133
return FileResponse(
136134
file.get_cdn_url(), media_type=file.content_type, filename=file.filename
137135
)
138-
elif file.get_cdn_url() is not None:
136+
elif file.get_cdn_url() is not None: # noqa: RET505
139137
"""If file has public url, redirect to this url"""
140138
return RedirectResponse(file.get_cdn_url())
141139
else:

examples/flask/app.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import os
23

34
from flask_sqlalchemy import SQLAlchemy
@@ -87,7 +88,7 @@ def serve_files(storage, file_id):
8788
mimetype=file.content_type,
8889
download_name=file.filename,
8990
)
90-
elif file.get_cdn_url() is not None:
91+
elif file.get_cdn_url() is not None: # noqa: RET505
9192
"""If file has public url, redirect to this url"""
9293
return app.redirect(file.get_cdn_url())
9394
else:
@@ -105,17 +106,18 @@ def serve_files(storage, file_id):
105106
os.makedirs("./upload_dir", 0o777, exist_ok=True)
106107
driver = get_driver(Provider.LOCAL)("./upload_dir")
107108

108-
# cls = get_driver(Provider.MINIO)
109-
# driver = cls("minioadmin", "minioadmin", secure=False, host="127.0.0.1", port=9000)
109+
"""
110+
Or with MinIO:
110111
111-
try:
112+
cls = get_driver(Provider.MINIO)
113+
driver = cls("minioadmin", "minioadmin", secure=False, host="127.0.0.1", port=9000)
114+
"""
115+
116+
with contextlib.suppress(ContainerAlreadyExistsError):
112117
driver.create_container(container_name="images")
113-
except ContainerAlreadyExistsError:
114-
pass
115-
try:
118+
119+
with contextlib.suppress(ContainerAlreadyExistsError):
116120
driver.create_container(container_name="documents")
117-
except ContainerAlreadyExistsError:
118-
pass
119121

120122
StorageManager.add_storage("images", driver.get_container(container_name="images"))
121123
StorageManager.add_storage(

0 commit comments

Comments
 (0)