Spaces:
Runtime error
Runtime error
Benjamin Bossan
commited on
Commit
•
c19ef6e
1
Parent(s):
91194ca
Apply mypy, black, ruff
Browse files- README.md +1 -1
- pyproject.toml +1 -0
- src/gistillery/db.py +2 -2
- src/gistillery/preprocessing.py +0 -1
- src/gistillery/webservice.py +4 -2
- tests/test_app.py +6 -2
README.md
CHANGED
@@ -48,5 +48,5 @@ python -m pytest tests/
|
|
48 |
```sh
|
49 |
mypy src/
|
50 |
black src/ && black tests/
|
51 |
-
ruff src/
|
52 |
```
|
|
|
48 |
```sh
|
49 |
mypy src/
|
50 |
black src/ && black tests/
|
51 |
+
ruff src/ && ruff tests/
|
52 |
```
|
pyproject.toml
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
line-length = 88
|
3 |
target_version = ['py310', 'py311']
|
4 |
preview = true
|
|
|
5 |
|
6 |
[tool.ruff]
|
7 |
line-length = 88
|
|
|
2 |
line-length = 88
|
3 |
target_version = ['py310', 'py311']
|
4 |
preview = true
|
5 |
+
skip_string_normalization = true
|
6 |
|
7 |
[tool.ruff]
|
8 |
line-length = 88
|
src/gistillery/db.py
CHANGED
@@ -81,9 +81,9 @@ TABLES_CREATED = False
|
|
81 |
|
82 |
|
83 |
# https://docs.python.org/3/library/sqlite3.html#how-to-create-and-use-row-factories
|
84 |
-
def namedtuple_factory(cursor, row):
|
85 |
fields = [column[0] for column in cursor.description]
|
86 |
-
cls = namedtuple("Row", fields)
|
87 |
return cls._make(row)
|
88 |
|
89 |
|
|
|
81 |
|
82 |
|
83 |
# https://docs.python.org/3/library/sqlite3.html#how-to-create-and-use-row-factories
|
84 |
+
def namedtuple_factory(cursor, row): # type: ignore
|
85 |
fields = [column[0] for column in cursor.description]
|
86 |
+
cls = namedtuple("Row", fields) # type: ignore
|
87 |
return cls._make(row)
|
88 |
|
89 |
|
src/gistillery/preprocessing.py
CHANGED
@@ -10,7 +10,6 @@ logger = logging.getLogger(__name__)
|
|
10 |
logger.setLevel(logging.DEBUG)
|
11 |
|
12 |
|
13 |
-
|
14 |
class Processor(abc.ABC):
|
15 |
def get_name(self) -> str:
|
16 |
return self.__class__.__name__
|
|
|
10 |
logger.setLevel(logging.DEBUG)
|
11 |
|
12 |
|
|
|
13 |
class Processor(abc.ABC):
|
14 |
def get_name(self) -> str:
|
15 |
return self.__class__.__name__
|
src/gistillery/webservice.py
CHANGED
@@ -58,7 +58,8 @@ def recent() -> list[EntriesResult]:
|
|
58 |
# get the last 10 entries, join summary and tag, where each tag is
|
59 |
# joined to a comma separated str
|
60 |
cursor.execute("""
|
61 |
-
SELECT
|
|
|
62 |
FROM entries e
|
63 |
JOIN summaries s ON e.id = s.entry_id
|
64 |
JOIN tags t ON e.id = t.entry_id
|
@@ -86,7 +87,8 @@ def recent_tag(tag: str) -> list[EntriesResult]:
|
|
86 |
with get_db_cursor() as cursor:
|
87 |
cursor.execute(
|
88 |
"""
|
89 |
-
SELECT
|
|
|
90 |
FROM entries e
|
91 |
JOIN summaries s ON e.id = s.entry_id
|
92 |
JOIN tags t ON e.id = t.entry_id
|
|
|
58 |
# get the last 10 entries, join summary and tag, where each tag is
|
59 |
# joined to a comma separated str
|
60 |
cursor.execute("""
|
61 |
+
SELECT
|
62 |
+
e.id, e.author, s.summary, GROUP_CONCAT(t.tag, ",") tags, e.created_at
|
63 |
FROM entries e
|
64 |
JOIN summaries s ON e.id = s.entry_id
|
65 |
JOIN tags t ON e.id = t.entry_id
|
|
|
87 |
with get_db_cursor() as cursor:
|
88 |
cursor.execute(
|
89 |
"""
|
90 |
+
SELECT
|
91 |
+
e.id, e.author, s.summary, GROUP_CONCAT(t.tag, ",") tags, e.created_at
|
92 |
FROM entries e
|
93 |
JOIN summaries s ON e.id = s.entry_id
|
94 |
JOIN tags t ON e.id = t.entry_id
|
tests/test_app.py
CHANGED
@@ -43,6 +43,7 @@ class TestWebservice:
|
|
43 |
|
44 |
class DummySummarizer(Summarizer):
|
45 |
"""Returns the first 10 characters of the input"""
|
|
|
46 |
def __init__(self, *args, **kwargs):
|
47 |
pass
|
48 |
|
@@ -54,6 +55,7 @@ class TestWebservice:
|
|
54 |
|
55 |
class DummyTagger(Tagger):
|
56 |
"""Returns the first 3 words of the input"""
|
|
|
57 |
def __init__(self, *args, **kwargs):
|
58 |
pass
|
59 |
|
@@ -173,7 +175,8 @@ class TestWebservice:
|
|
173 |
"/submit", json={"author": "maxi", "content": "this is a first test"}
|
174 |
)
|
175 |
client.post(
|
176 |
-
"/submit",
|
|
|
177 |
)
|
178 |
self.process_jobs(mlregistry)
|
179 |
resp = client.get("/recent").json()
|
@@ -199,7 +202,8 @@ class TestWebservice:
|
|
199 |
"/submit", json={"author": "maxi", "content": "this is a first test"}
|
200 |
)
|
201 |
client.post(
|
202 |
-
"/submit",
|
|
|
203 |
)
|
204 |
self.process_jobs(mlregistry)
|
205 |
|
|
|
43 |
|
44 |
class DummySummarizer(Summarizer):
|
45 |
"""Returns the first 10 characters of the input"""
|
46 |
+
|
47 |
def __init__(self, *args, **kwargs):
|
48 |
pass
|
49 |
|
|
|
55 |
|
56 |
class DummyTagger(Tagger):
|
57 |
"""Returns the first 3 words of the input"""
|
58 |
+
|
59 |
def __init__(self, *args, **kwargs):
|
60 |
pass
|
61 |
|
|
|
175 |
"/submit", json={"author": "maxi", "content": "this is a first test"}
|
176 |
)
|
177 |
client.post(
|
178 |
+
"/submit",
|
179 |
+
json={"author": "mini", "content": "this would be something else"},
|
180 |
)
|
181 |
self.process_jobs(mlregistry)
|
182 |
resp = client.get("/recent").json()
|
|
|
202 |
"/submit", json={"author": "maxi", "content": "this is a first test"}
|
203 |
)
|
204 |
client.post(
|
205 |
+
"/submit",
|
206 |
+
json={"author": "mini", "content": "this would be something else"},
|
207 |
)
|
208 |
self.process_jobs(mlregistry)
|
209 |
|