Skip to content

Commit abd5b67

Browse files
committed
fix: added ruff linting, fixed lints
1 parent 1d5394c commit abd5b67

File tree

7 files changed

+50
-37
lines changed

7 files changed

+50
-37
lines changed

aw_server/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
logger = _logging.getLogger(__name__)
44

5-
from . import __about__
65
from .__about__ import __version__
7-
8-
from .server import create_app
9-
10-
from . import api
11-
from . import rest
12-
136
from .main import main
7+
8+
__all__ = [
9+
"__version__",
10+
"main",
11+
]

aw_server/api.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
from typing import Dict, List, Any, Optional
2-
from datetime import datetime
3-
from socket import gethostname
4-
from pathlib import Path
5-
from uuid import uuid4
61
import functools
72
import json
83
import logging
9-
import iso8601
4+
from datetime import datetime
5+
from pathlib import Path
6+
from socket import gethostname
7+
from typing import (
8+
Any,
9+
Dict,
10+
List,
11+
Optional,
12+
)
13+
from uuid import uuid4
1014

11-
from aw_core.models import Event
12-
from aw_core.log import get_log_file_path
15+
import iso8601
1316
from aw_core.dirs import get_data_dir
14-
17+
from aw_core.log import get_log_file_path
18+
from aw_core.models import Event
1519
from aw_query import query2
1620
from aw_transform import heartbeat_merge
1721

1822
from .__about__ import __version__
19-
20-
from .exceptions import BadRequest, NotFound, Unauthorized
21-
23+
from .exceptions import NotFound
2224

2325
logger = logging.getLogger(__name__)
2426

@@ -201,7 +203,10 @@ def create_events(self, bucket_id: str, events: List[Event]) -> Optional[Event]:
201203

202204
@check_bucket_exists
203205
def get_eventcount(
204-
self, bucket_id: str, start: Optional[datetime] = None, end: Optional[datetime] = None
206+
self,
207+
bucket_id: str,
208+
start: Optional[datetime] = None,
209+
end: Optional[datetime] = None,
205210
) -> int:
206211
"""Get eventcount from a bucket"""
207212
logger.debug(f"Received get request for eventcount in bucket '{bucket_id}'")

aw_server/custom_static.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
See https://github.com/ActivityWatch/activitywatch/issues/453#issuecomment-910567848
2121
2222
"""
23-
import logging
2423

25-
from flask import Blueprint, send_from_directory, jsonify, escape
24+
from flask import (
25+
Blueprint,
26+
escape,
27+
jsonify,
28+
send_from_directory,
29+
)
2630

2731

2832
def get_custom_static_blueprint(custom_static_directories):

aw_server/server.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import os
21
import logging
3-
from typing import List, Dict
4-
5-
from flask import Flask, Blueprint, current_app, send_from_directory
6-
from flask_cors import CORS
2+
import os
3+
from typing import Dict, List
74

85
import aw_datastore
96
from aw_datastore import Datastore
10-
from .custom_static import get_custom_static_blueprint
7+
from flask import (
8+
Blueprint,
9+
Flask,
10+
current_app,
11+
send_from_directory,
12+
)
13+
from flask_cors import CORS
1114

12-
from .log import FlaskLogHandler
13-
from .api import ServerAPI
1415
from . import rest
16+
from .api import ServerAPI
17+
from .custom_static import get_custom_static_blueprint
18+
from .log import FlaskLogHandler
1519

1620
logger = logging.getLogger(__name__)
1721

@@ -26,7 +30,7 @@ def __init__(self, name, *args, **kwargs):
2630
Flask.__init__(self, name, *args, **kwargs)
2731

2832
# Is set on later initialization
29-
self.api = None # type: ServerAPI
33+
self.api: ServerAPI = None # type: ignore
3034

3135

3236
def create_app(
@@ -76,9 +80,8 @@ def static_js(path):
7680
def _config_cors(cors_origins: List[str], testing: bool):
7781
if cors_origins:
7882
logger.warning(
79-
"Running with additional allowed CORS origins specified through config or CLI argument (could be a security risk): {}".format(
80-
cors_origins
81-
)
83+
"Running with additional allowed CORS origins specified through config "
84+
"or CLI argument (could be a security risk): {}".format(cors_origins)
8285
)
8386

8487
if testing:

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ minversion = "6.0"
3838
addopts = "--cov-report=term --cov-report=xml --cov-report=html --cov=aw_server"
3939
python_files = ["*.py",]
4040

41+
[tool.ruff]
42+
ignore = ["E402", "E501"]
43+
4144
[build-system]
4245
requires = ["poetry-core"]
4346
build-backend = "poetry.core.masonry.api"

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_queued_heartbeat(aw_client, queued_bucket):
151151
sleep(0.5)
152152

153153
assert i != max_tries - 1
154-
print("Done on the {}th try".format(i + 1))
154+
print(f"Done on the {i + 1}th try")
155155

156156
assert len(events) == 1
157157
event = events[0]

tests/test_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ def bucket(flask_client):
1010
try:
1111
bucket_id = "test"
1212
r = flask_client.post(
13-
"/api/0/buckets/{}".format(bucket_id),
13+
f"/api/0/buckets/{bucket_id}",
1414
json={"client": "test", "type": "test", "hostname": "test"},
1515
)
1616
assert r.status_code == 200
1717
yield bucket_id
1818
finally:
19-
r = flask_client.delete("/api/0/buckets/{}".format(bucket_id))
19+
r = flask_client.delete(f"/api/0/buckets/{bucket_id}")
2020
assert r.status_code == 200
2121

2222

0 commit comments

Comments
 (0)