Skip to content

Commit

Permalink
fix: added ruff linting, fixed lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Mar 11, 2023
1 parent 1d5394c commit abd5b67
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 37 deletions.
12 changes: 5 additions & 7 deletions aw_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

logger = _logging.getLogger(__name__)

from . import __about__
from .__about__ import __version__

from .server import create_app

from . import api
from . import rest

from .main import main

__all__ = [
"__version__",
"main",
]
31 changes: 18 additions & 13 deletions aw_server/api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from typing import Dict, List, Any, Optional
from datetime import datetime
from socket import gethostname
from pathlib import Path
from uuid import uuid4
import functools
import json
import logging
import iso8601
from datetime import datetime
from pathlib import Path
from socket import gethostname
from typing import (
Any,
Dict,
List,
Optional,
)
from uuid import uuid4

from aw_core.models import Event
from aw_core.log import get_log_file_path
import iso8601
from aw_core.dirs import get_data_dir

from aw_core.log import get_log_file_path
from aw_core.models import Event
from aw_query import query2
from aw_transform import heartbeat_merge

from .__about__ import __version__

from .exceptions import BadRequest, NotFound, Unauthorized

from .exceptions import NotFound

logger = logging.getLogger(__name__)

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

@check_bucket_exists
def get_eventcount(
self, bucket_id: str, start: Optional[datetime] = None, end: Optional[datetime] = None
self,
bucket_id: str,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
) -> int:
"""Get eventcount from a bucket"""
logger.debug(f"Received get request for eventcount in bucket '{bucket_id}'")
Expand Down
8 changes: 6 additions & 2 deletions aw_server/custom_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
See https://github.com/ActivityWatch/activitywatch/issues/453#issuecomment-910567848
"""
import logging

from flask import Blueprint, send_from_directory, jsonify, escape
from flask import (
Blueprint,
escape,
jsonify,
send_from_directory,
)


def get_custom_static_blueprint(custom_static_directories):
Expand Down
27 changes: 15 additions & 12 deletions aw_server/server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import os
import logging
from typing import List, Dict

from flask import Flask, Blueprint, current_app, send_from_directory
from flask_cors import CORS
import os
from typing import Dict, List

import aw_datastore
from aw_datastore import Datastore
from .custom_static import get_custom_static_blueprint
from flask import (
Blueprint,
Flask,
current_app,
send_from_directory,
)
from flask_cors import CORS

from .log import FlaskLogHandler
from .api import ServerAPI
from . import rest
from .api import ServerAPI
from .custom_static import get_custom_static_blueprint
from .log import FlaskLogHandler

logger = logging.getLogger(__name__)

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

# Is set on later initialization
self.api = None # type: ServerAPI
self.api: ServerAPI = None # type: ignore


def create_app(
Expand Down Expand Up @@ -76,9 +80,8 @@ def static_js(path):
def _config_cors(cors_origins: List[str], testing: bool):
if cors_origins:
logger.warning(
"Running with additional allowed CORS origins specified through config or CLI argument (could be a security risk): {}".format(
cors_origins
)
"Running with additional allowed CORS origins specified through config "
"or CLI argument (could be a security risk): {}".format(cors_origins)
)

if testing:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ minversion = "6.0"
addopts = "--cov-report=term --cov-report=xml --cov-report=html --cov=aw_server"
python_files = ["*.py",]

[tool.ruff]
ignore = ["E402", "E501"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_queued_heartbeat(aw_client, queued_bucket):
sleep(0.5)

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

assert len(events) == 1
event = events[0]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def bucket(flask_client):
try:
bucket_id = "test"
r = flask_client.post(
"/api/0/buckets/{}".format(bucket_id),
f"/api/0/buckets/{bucket_id}",
json={"client": "test", "type": "test", "hostname": "test"},
)
assert r.status_code == 200
yield bucket_id
finally:
r = flask_client.delete("/api/0/buckets/{}".format(bucket_id))
r = flask_client.delete(f"/api/0/buckets/{bucket_id}")
assert r.status_code == 200


Expand Down

0 comments on commit abd5b67

Please sign in to comment.