Skip to content

Commit 2f95275

Browse files
authored
Address Linting warnings (#254)
* lint fixes * re-enable CI failure on lint warnings * edit lint config * white list pydantic * allow fstring logging * allow TODO * temporarily allow duplicate code
1 parent 8129824 commit 2f95275

27 files changed

+123
-93
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TEST = tests
1717
test:
1818
pytest -v $(TEST) --cov-report term --cov-report xml --cov=$(APP)
1919
lint:
20-
pylint $(APP) || true
20+
pylint $(APP)
2121

2222
fmt:
2323
invoke fmt

app/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
"""
2+
Corona Virus Tracker API
3+
~~~~~~~~~~~~~~~~~~~~~~~~
4+
API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak.
5+
"""
16
# See PEP396.
2-
__version__ = "2.0"
7+
__version__ = "2.0.1"

app/config/settings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
"""app.config.settings.py"""
12
import os
23

34
# Load enviroment variables from .env file.
45
from dotenv import load_dotenv
56

67
load_dotenv()
78

8-
"""
9-
The port to serve the app application on.
10-
"""
11-
PORT = int(os.getenv("PORT", 5000))
9+
# The port to serve the app application on.
10+
PORT = int(os.getenv("PORT", "5000"))

app/coordinates.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""app.coordinates.py"""
2+
3+
14
class Coordinates:
25
"""
36
A position on earth using decimal coordinates (latitude and longitude).

app/data/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
"""app.data"""
12
from ..services.location.csbs import CSBSLocationService
23
from ..services.location.jhu import JhuLocationService
34

45
# Mapping of services to data-sources.
5-
data_sources = {"jhu": JhuLocationService(), "csbs": CSBSLocationService()}
6+
DATA_SOURCES = {"jhu": JhuLocationService(), "csbs": CSBSLocationService()}
67

78

89
def data_source(source):
@@ -12,4 +13,4 @@ def data_source(source):
1213
:returns: The service.
1314
:rtype: LocationService
1415
"""
15-
return data_sources.get(source.lower())
16+
return DATA_SOURCES.get(source.lower())

app/location/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
"""app.location"""
12
from ..coordinates import Coordinates
23
from ..utils import countries
34
from ..utils.populations import country_population
45

56

6-
class Location:
7+
# pylint: disable=redefined-builtin,invalid-name
8+
class Location: # pylint: disable=too-many-instance-attributes
79
"""
810
A location in the world affected by the coronavirus.
911
"""
1012

11-
def __init__(self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered):
13+
def __init__(
14+
self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered
15+
): # pylint: disable=too-many-arguments
1216
# General info.
1317
self.id = id
1418
self.country = country.strip()
@@ -31,7 +35,7 @@ def country_code(self):
3135
:returns: The country code.
3236
:rtype: str
3337
"""
34-
return (countries.country_code(self.country) or countries.default_country_code).upper()
38+
return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper()
3539

3640
@property
3741
def country_population(self):
@@ -71,6 +75,7 @@ class TimelinedLocation(Location):
7175
A location with timelines.
7276
"""
7377

78+
# pylint: disable=too-many-arguments
7479
def __init__(self, id, country, province, coordinates, last_updated, timelines):
7580
super().__init__(
7681
# General info.
@@ -88,6 +93,7 @@ def __init__(self, id, country, province, coordinates, last_updated, timelines):
8893
# Set timelines.
8994
self.timelines = timelines
9095

96+
# pylint: disable=arguments-differ
9197
def serialize(self, timelines=False):
9298
"""
9399
Serializes the location into a dict.

app/location/csbs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""app.locations.csbs.py"""
12
from . import Location
23

34

@@ -6,6 +7,7 @@ class CSBSLocation(Location):
67
A CSBS (county) location.
78
"""
89

10+
# pylint: disable=too-many-arguments,redefined-builtin
911
def __init__(self, id, state, county, coordinates, last_updated, confirmed, deaths):
1012
super().__init__(
1113
# General info.
@@ -23,7 +25,7 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat
2325
self.state = state
2426
self.county = county
2527

26-
def serialize(self, timelines=False):
28+
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
2729
"""
2830
Serializes the location into a dict.
2931

app/main.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from fastapi.responses import JSONResponse
1212

1313
from .data import data_source
14-
from .router.v1 import router as v1router
15-
from .router.v2 import router as v2router
14+
from .router.v1 import V1
15+
from .router.v2 import V2
1616

1717
# ############
1818
# FastAPI App
@@ -21,7 +21,10 @@
2121

2222
APP = FastAPI(
2323
title="Coronavirus Tracker",
24-
description="API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak. Project page: https://github.com/ExpDev07/coronavirus-tracker-api.",
24+
description=(
25+
"API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak."
26+
" Project page: https://github.com/ExpDev07/coronavirus-tracker-api."
27+
),
2528
version="2.0.1",
2629
docs_url="/",
2730
redoc_url="/docs",
@@ -36,7 +39,7 @@
3639
CORSMiddleware, allow_credentials=True, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"],
3740
)
3841

39-
# TODO this could probably just be a FastAPI dependency.
42+
4043
@APP.middleware("http")
4144
async def add_datasource(request: Request, call_next):
4245
"""
@@ -64,7 +67,9 @@ async def add_datasource(request: Request, call_next):
6467

6568

6669
@APP.exception_handler(pydantic.error_wrappers.ValidationError)
67-
async def handle_validation_error(request: Request, exc: pydantic.error_wrappers.ValidationError):
70+
async def handle_validation_error(
71+
request: Request, exc: pydantic.error_wrappers.ValidationError
72+
): # pylint: disable=unused-argument
6873
"""
6974
Handles validation errors.
7075
"""
@@ -77,12 +82,12 @@ async def handle_validation_error(request: Request, exc: pydantic.error_wrappers
7782

7883

7984
# Include routers.
80-
APP.include_router(v1router, prefix="", tags=["v1"])
81-
APP.include_router(v2router, prefix="/v2", tags=["v2"])
85+
APP.include_router(V1, prefix="", tags=["v1"])
86+
APP.include_router(V2, prefix="/v2", tags=["v2"])
8287

8388

8489
# Running of app.
8590
if __name__ == "__main__":
8691
uvicorn.run(
87-
"app.main:APP", host="127.0.0.1", port=int(os.getenv("PORT", 5000)), log_level="info",
92+
"app.main:APP", host="127.0.0.1", port=int(os.getenv("PORT", "5000")), log_level="info",
8893
)

app/router/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
"""app.router"""
12
from fastapi import APIRouter
23

4+
# pylint: disable=redefined-builtin
35
from .v1 import all, confirmed, deaths, recovered
46

57
# The routes.

app/router/v1/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""app.router.v1"""
12
from fastapi import APIRouter
23

3-
router = APIRouter()
4+
V1 = APIRouter()

0 commit comments

Comments
 (0)