Skip to content

Commit

Permalink
chore: add linting script & minor fixes (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
br-g authored Nov 23, 2024
1 parent a05ba21 commit a3bf85b
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 10 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tests

on: [push]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r testing_requirements.txt
- name: Lint with ruff
run: |
# Stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
# Default set of ruff rules with GitHub Annotations
ruff --format=github --ignore=E501 --target-version=py37 .
- name: Format with black
run: |
black --check --diff --color .
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dynamic = ["dependencies"]
dynamic = ["dependencies", "optional-dependencies"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
optional-dependencies.test = { file = ["testing_requirements.txt"] }
2 changes: 1 addition & 1 deletion src/openf1/services/ingestor_livetiming/core/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def decode(data: str) -> dict:
data = data.strip()
try:
return json.loads(data.strip('"'))
except:
except Exception:
s = zlib.decompress(base64.b64decode(data), -zlib.MAX_WBITS)
return json.loads(s.decode("utf-8-sig"))
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def process_message(
documents = list(collection.process_message(message))
if len(documents) > 0:
results[collection.__class__.name] = documents
except Exception as e:
except Exception:
traceback.print_exc()

return results
Expand Down
5 changes: 2 additions & 3 deletions src/openf1/services/ingestor_livetiming/historical/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
get_source_topics,
)
from openf1.services.ingestor_livetiming.core.processing.main import process_messages
from openf1.util import join_url
from openf1.util.db import DbBatchIngestor
from openf1.util.misc import join_url, json_serializer, to_datetime, to_timedelta
from openf1.util.schedule import get_meeting_keys
Expand Down Expand Up @@ -282,7 +281,7 @@ def _get_processed_documents(
logger.info(f"Fetched {len(messages)} messages")

if verbose:
logger.info(f"Starting processing")
logger.info("Starting processing")

docs_by_collection = process_messages(
messages=messages, meeting_key=meeting_key, session_key=session_key
Expand Down Expand Up @@ -344,7 +343,7 @@ def ingest_collections(
)

if verbose:
logger.info(f"Inserting documents to DB")
logger.info("Inserting documents to DB")
for collection, docs in tqdm(list(docs_by_collection.items()), disable=not verbose):
docs_mongo = [d.to_mongo_doc() for d in docs]
DbBatchIngestor().add_and_flush(collection=collection, docs=docs_mongo)
Expand Down
3 changes: 1 addition & 2 deletions src/openf1/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def timed_cache(expiration_time: float) -> Callable:
timestamps = {}

def decorator(func):

@wraps(func)
def wrapper(*args, **kwargs):
# Convert the arguments and keyword arguments to a single hashable key
Expand Down Expand Up @@ -138,7 +137,7 @@ def to_datetime(x: str | datetime) -> datetime | None:
int(msus),
)

except Exception as exc:
except Exception:
return None

elif isinstance(x, datetime):
Expand Down
1 change: 0 additions & 1 deletion src/openf1/util/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import requests

from openf1.util import join_url
from openf1.util.db import get_latest_session_info
from openf1.util.misc import join_url

Expand Down
2 changes: 1 addition & 1 deletion src/openf1/util/type_casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _try_parse_date(s: str) -> datetime | str:
"""Attempts to convert a string to a datetime object"""
try:
dt = parse_date(s)
except:
except Exception:
return s

if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None:
Expand Down
5 changes: 5 additions & 0 deletions testing_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black==23.7.0
coverage>=7.2.7
freezegun>=1.2.2
pytest>=7.4.0
ruff==0.0.283

0 comments on commit a3bf85b

Please sign in to comment.