Skip to content

Commit dd99933

Browse files
Add pre-commit and linting actions
1 parent d156642 commit dd99933

File tree

11 files changed

+74
-56
lines changed

11 files changed

+74
-56
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ exclude_lines =
1111
if __name__ == .__main__.:
1212
ignore_errors = True
1313
omit =
14-
tests/*
14+
tests/*

.flake8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
max-complexity = 10
3-
max-line-length = 80
3+
max-line-length = 88
44
extend-select = B950
55
extend-ignore = E203,E501,E701
6-
exclude = .git,__pycache__,build,dist
6+
exclude = .git,__pycache__,build,dist

.readthedocs.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build:
1212

1313
# Build documentation in the "docs/" directory with Sphinx
1414
sphinx:
15-
configuration: docs/conf.py
15+
configuration: "docs/conf.py"
1616
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
1717
# builder: "dirhtml"
1818
# Fail on all warnings to avoid broken references
@@ -22,6 +22,6 @@ sphinx:
2222
# Optional but recommended, declare the Python requirements required
2323
# to build your documentation
2424
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
25-
python:
26-
install:
27-
- requirements: docs/requirements.txt
25+
python:
26+
install:
27+
- requirements: "docs/requirements.txt"

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1818
## [0.9.8] - 2020-07-03
1919

2020
+ Remove f-string in test
21-
21+
2222
## [0.9.7] - 2020-07-03
2323

2424
+ Bugfix for `get_observation_sites`

docs/source/conf.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,28 @@
55

66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8-
9-
project = 'datapoint-python'
10-
copyright = '2024, Emily Price, Jacob Tomlinson'
11-
author = 'Emily Price, Jacob Tomlinson'
12-
138
import importlib
149

15-
import datapoint
10+
project = "datapoint-python"
11+
copyright = "2024, Emily Price, Jacob Tomlinson"
12+
author = "Emily Price, Jacob Tomlinson"
1613

17-
release = importlib.metadata.version('datapoint')
18-
version = importlib.metadata.version('datapoint')
14+
release = importlib.metadata.version("datapoint")
15+
version = importlib.metadata.version("datapoint")
1916

2017
# -- General configuration ---------------------------------------------------
2118
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
2219

23-
extensions = ['sphinx.ext.autodoc',]
20+
extensions = [
21+
"sphinx.ext.autodoc",
22+
]
2423

25-
templates_path = ['_templates']
24+
templates_path = ["_templates"]
2625
exclude_patterns = []
2726

2827

29-
3028
# -- Options for HTML output -------------------------------------------------
3129
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3230

33-
html_theme = 'alabaster'
34-
html_static_path = ['_static']
31+
html_theme = "alabaster"
32+
html_static_path = ["_static"]

examples/tube_bike/tube_bike.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,30 @@
2828

2929
# Check whether there are any problems with rain or the tube
3030
if (
31-
my_house_now['probOfPrecipitation']['value'] < 40
32-
and work_now['probOfPrecipitation']['value'] < 40
31+
my_house_now["probOfPrecipitation"]["value"] < 40
32+
and work_now["probOfPrecipitation"]["value"] < 40
3333
and waterloo_status.description == "Good Service"
3434
):
3535
print("Rain is unlikely and tube service is good, the decision is yours.")
3636

3737
# If it is going to rain then suggest the tube
3838
elif (
39-
my_house_now['probOfPrecipitation']['value'] >= 40 or work_now['probOfPrecipitation']['value'] >= 40
39+
my_house_now["probOfPrecipitation"]["value"] >= 40
40+
or work_now["probOfPrecipitation"]["value"] >= 40
4041
) and waterloo_status.description == "Good Service":
4142
print("Looks like rain, better get the tube")
4243

4344
# If the tube isn't running then suggest cycling
4445
elif (
45-
my_house_now['probOfPrecipitation']['value'] < 40
46-
and work_now['probOfPrecipitation']['value'] < 40
46+
my_house_now["probOfPrecipitation"]["value"] < 40
47+
and work_now["probOfPrecipitation"]["value"] < 40
4748
and waterloo_status.description != "Good Service"
4849
):
4950
print("Bad service on the tube, cycling it is!")
5051

5152
# Else if both are bad then suggest cycling in the rain
5253
else:
5354
print(
54-
"The tube has poor service so you'll have to cycle, but it's raining so take your waterproofs."
55+
"The tube has poor service so you'll have to cycle,"
56+
" but it's raining so take your waterproofs."
5557
)

examples/washing/washing.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
them and print out the best.
99
"""
1010

11-
from datetime import datetime
12-
1311
import datapoint
1412

1513
# Set thresholds
@@ -42,8 +40,8 @@
4240
timestep_score = timestep.wind_speed.value + timestep.temperature.value
4341

4442
# If this timestep scores better than the current best replace it
45-
if timestep_score > best_day_score:
46-
best_day_score = timestep_score
43+
if timestep_score > best_score:
44+
best_score = timestep_score
4745
best_day = day.date
4846

4947
for timestep in forecast.timesteps:
@@ -54,12 +52,14 @@
5452
and timestep.wind_gust.value < MAX_WIND
5553
):
5654
# Calculate the score for this timestep
57-
timestep_score = timestep['windSpeed10m']['value'] + timestep['screenTemperature']['value']
55+
timestep_score = (
56+
timestep["windSpeed10m"]["value"] + timestep["screenTemperature"]["value"]
57+
)
5858

5959
# If this timestep scores better than the current best replace it
60-
if timestep_score > best_day_score:
60+
if timestep_score > best_score:
6161
best_score = timestep_score
62-
best_time = timestep['time']
62+
best_time = timestep["time"]
6363

6464

6565
# If best_day is still None then there are no good days
@@ -68,6 +68,4 @@
6868

6969
# Otherwise print out the day
7070
else:
71-
print(
72-
f"{best_time} is the best day with a score of {best_score}"
73-
)
71+
print(f"{best_time} is the best day with a score of {best_score}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ default-tag = "0.0.1"
5858
[tool.pytest.ini_options]
5959
addopts = [
6060
"--import-mode=importlib",
61-
]
61+
]

src/datapoint/Forecast.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ def __init__(self, frequency, api_data):
124124
] #: The distance of the location of the provided forecast from the requested location
125125
self.name = api_data["features"][0]["properties"]["location"][
126126
"name"
127-
] #: The name of the location of the provided forecast
127+
] #: The name of the location of the provided forecast
128128

129129
# N.B. Elevation is in metres above or below the WGS 84 reference
130130
# ellipsoid as per GeoJSON spec.
131131
self.elevation = api_data["features"][0]["geometry"]["coordinates"][
132132
2
133-
] #: The elevation of the location of the provided forecast
133+
] #: The elevation of the location of the provided forecast
134134

135135
forecasts = api_data["features"][0]["properties"]["timeSeries"]
136136
parameters = api_data["parameters"][0]
@@ -260,7 +260,8 @@ def _check_requested_time(self, target):
260260
] - datetime.timedelta(hours=0, minutes=30):
261261
err_str = (
262262
"There is no forecast available for the requested time. "
263-
+ "The requested time is more than 30 minutes before the first available forecast"
263+
"The requested time is more than 30 minutes before the "
264+
"first available forecast."
264265
)
265266
raise APIException(err_str)
266267

@@ -271,7 +272,8 @@ def _check_requested_time(self, target):
271272
] - datetime.timedelta(hours=1, minutes=30):
272273
err_str = (
273274
"There is no forecast available for the requested time. "
274-
+ "The requested time is more than 1 hour and 30 minutes before the first available forecast"
275+
"The requested time is more than 1 hour and 30 minutes "
276+
"before the first available forecast."
275277
)
276278
raise APIException(err_str)
277279

@@ -282,7 +284,8 @@ def _check_requested_time(self, target):
282284
] - datetime.timedelta(hours=6):
283285
err_str = (
284286
"There is no forecast available for the requested time. "
285-
+ "The requested time is more than 6 hours before the first available forecast"
287+
"The requested time is more than 6 hours before the first "
288+
"available forecast."
286289
)
287290

288291
raise APIException(err_str)
@@ -292,7 +295,11 @@ def _check_requested_time(self, target):
292295
if self.frequency == "hourly" and target > (
293296
self.timesteps[-1]["time"] + datetime.timedelta(hours=0, minutes=30)
294297
):
295-
err_str = "There is no forecast available for the requested time. The requested time is more than 30 minutes after the first available forecast"
298+
err_str = (
299+
"There is no forecast available for the requested time. The "
300+
"requested time is more than 30 minutes after the first "
301+
"available forecast"
302+
)
296303

297304
raise APIException(err_str)
298305

@@ -301,7 +308,11 @@ def _check_requested_time(self, target):
301308
if self.frequency == "three-hourly" and target > (
302309
self.timesteps[-1]["time"] + datetime.timedelta(hours=1, minutes=30)
303310
):
304-
err_str = "There is no forecast available for the requested time. The requested time is more than 1.5 hours after the first available forecast"
311+
err_str = (
312+
"There is no forecast available for the requested time. The "
313+
"requested time is more than 1.5 hours after the first "
314+
"available forecast."
315+
)
305316

306317
raise APIException(err_str)
307318

@@ -310,7 +321,11 @@ def _check_requested_time(self, target):
310321
if self.frequency == "daily" and target > (
311322
self.timesteps[-1]["time"] + datetime.timedelta(hours=6)
312323
):
313-
err_str = "There is no forecast available for the requested time. The requested time is more than 6 hours after the first available forecast"
324+
err_str = (
325+
"There is no forecast available for the requested time. The "
326+
"requested time is more than 6 hours after the first available "
327+
"forecast."
328+
)
314329

315330
raise APIException(err_str)
316331

src/datapoint/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from datapoint.Manager import Manager

0 commit comments

Comments
 (0)