Skip to content

Commit 104e247

Browse files
authored
chore: add pre-commit config and linting (#70) (#84)
* chore: add pre-commit config and linting * fix requirements for linting
1 parent 7b64e75 commit 104e247

File tree

17 files changed

+232
-90
lines changed

17 files changed

+232
-90
lines changed

.github/dependabot.yml

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

66
version: 2
77
updates:
8-
- package-ecosystem: "pip" # See documentation for possible values
9-
directory: "/" # Location of package manifests
8+
- package-ecosystem: "pip" # See documentation for possible values
9+
directory: "/" # Location of package manifests
1010
schedule:
1111
interval: "daily"

.github/workflows/publish-to-pypi.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ name: Publish releases to PyPI
22

33
on:
44
release:
5-
types: [published, prereleased]
5+
types:
6+
- published
7+
- prereleased
68

79
jobs:
810
build-and-publish:

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# This workflow will install Python dependencies, run tests and lint
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
32

43
name: Test
54

.pre-commit-config.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v2.31.0
4+
hooks:
5+
- id: pyupgrade
6+
args: ["--py39-plus"]
7+
- repo: https://github.com/ambv/black
8+
rev: 22.3.0
9+
hooks:
10+
- id: black
11+
language_version: python3
12+
args:
13+
- --safe
14+
- --quiet
15+
files: ^(openevsehttp/.+)?[^/]+\.py$
16+
- repo: https://github.com/codespell-project/codespell
17+
rev: v1.17.1
18+
hooks:
19+
- id: codespell
20+
args:
21+
- --ignore-words-list=hass,alot,datas,dof,dur,farenheit,hist,iff,ines,ist,lightsensor,mut,nd,pres,referer,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,iam,incomfort
22+
- --skip="./.*,*.csv,*.json"
23+
- --quiet-level=2
24+
exclude_types: [csv, json]
25+
- repo: https://gitlab.com/pycqa/flake8
26+
rev: 4.0.1
27+
hooks:
28+
- id: flake8
29+
additional_dependencies:
30+
- flake8-docstrings==1.5.0
31+
files: ^openevsehttp/.+\.py$
32+
args:
33+
- --max-line-length=500
34+
- --ignore=E203,E266,E501,W503
35+
- --max-complexity=18
36+
- --select=B,C,E,F,W,T4,B9
37+
- repo: https://github.com/pre-commit/mirrors-isort
38+
rev: v5.10.1
39+
hooks:
40+
- id: isort
41+
args:
42+
- --multi-line=3
43+
- --trailing-comma
44+
- --force-grid-wrap=0
45+
- --use-parentheses
46+
- --line-width=88
47+
- repo: https://github.com/pre-commit/pre-commit-hooks
48+
rev: v4.1.0
49+
hooks:
50+
- id: check-executables-have-shebangs
51+
stages: [manual]
52+
- id: no-commit-to-branch
53+
args:
54+
- --branch=main
55+
- id: trailing-whitespace
56+
- id: end-of-file-fixer
57+
- id: check-docstring-first
58+
- id: check-yaml
59+
- id: debug-statements
60+
- repo: https://github.com/PyCQA/pydocstyle
61+
rev: 6.1.1
62+
hooks:
63+
- id: pydocstyle
64+
- repo: https://github.com/adrienverge/yamllint.git
65+
rev: v1.24.2
66+
hooks:
67+
- id: yamllint
68+
- repo: https://github.com/prettier/prettier
69+
rev: 2.0.4
70+
hooks:
71+
- id: prettier
72+
stages: [manual]
73+
- repo: https://github.com/pre-commit/mirrors-mypy
74+
rev: "v0.930"
75+
hooks:
76+
- id: mypy
77+
files: ^openevsehttp/.+\.py$

.yamllint

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ignore: |
2+
release-drafter.yml
3+
rules:
4+
braces:
5+
level: error
6+
min-spaces-inside: 0
7+
max-spaces-inside: 1
8+
min-spaces-inside-empty: -1
9+
max-spaces-inside-empty: -1
10+
brackets:
11+
level: error
12+
min-spaces-inside: 0
13+
max-spaces-inside: 0
14+
min-spaces-inside-empty: -1
15+
max-spaces-inside-empty: -1
16+
colons:
17+
level: error
18+
max-spaces-before: 0
19+
max-spaces-after: 1
20+
commas:
21+
level: error
22+
max-spaces-before: 0
23+
min-spaces-after: 1
24+
max-spaces-after: 1
25+
comments:
26+
level: error
27+
require-starting-space: true
28+
min-spaces-from-content: 2
29+
comments-indentation:
30+
level: error
31+
document-end:
32+
level: error
33+
present: false
34+
document-start:
35+
level: error
36+
present: false
37+
empty-lines:
38+
level: error
39+
max: 1
40+
max-start: 0
41+
max-end: 1
42+
hyphens:
43+
level: error
44+
max-spaces-after: 1
45+
indentation:
46+
level: error
47+
spaces: 2
48+
indent-sequences: true
49+
check-multi-line-strings: false
50+
key-duplicates:
51+
level: error
52+
line-length: disable
53+
new-line-at-end-of-file:
54+
level: error
55+
new-lines:
56+
level: error
57+
type: unix
58+
trailing-spaces:
59+
level: error
60+
truthy: disable

openevsehttp/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import datetime
66
import json
77
import logging
8-
from typing import Any, Callable, Optional
8+
from typing import Any, Callable
99

1010
import aiohttp # type: ignore
1111
from aiohttp.client_exceptions import ContentTypeError, ServerTimeoutError
@@ -181,8 +181,8 @@ def __init__(self, host: str, user: str = None, pwd: str = None) -> None:
181181
self._config: dict = {}
182182
self._override = None
183183
self._ws_listening = False
184-
self.websocket: Optional[OpenEVSEWebsocket] = None
185-
self.callback: Optional[Callable] = None
184+
self.websocket: OpenEVSEWebsocket | None = None
185+
self.callback: Callable | None = None
186186
self._loop = None
187187

188188
async def process_request(
@@ -406,7 +406,7 @@ async def get_override(self) -> None:
406406
"""Get the manual override status."""
407407
url = f"{self.url}override"
408408

409-
_LOGGER.debug("Geting data from %s", url)
409+
_LOGGER.debug("Getting data from %s", url)
410410
response = await self.process_request(url=url, method="get")
411411
return response
412412

@@ -465,9 +465,9 @@ async def toggle_override(self) -> None:
465465

466466
async def clear_override(self) -> None:
467467
"""Clear the manual override status."""
468-
url = f"{self.url}overrride"
468+
url = f"{self.url}override"
469469

470-
_LOGGER.debug("Clearing manual overrride %s", url)
470+
_LOGGER.debug("Clearing manual override %s", url)
471471
response = await self.process_request(url=url, method="delete")
472472
_LOGGER.debug("Toggle response: %s", response["msg"])
473473

@@ -668,7 +668,7 @@ def usage_total(self) -> float:
668668

669669
@property
670670
def ambient_temperature(self) -> float | None:
671-
"""Return the temperature of the ambient sensor, in degrees Celcius."""
671+
"""Return the temperature of the ambient sensor, in degrees Celsius."""
672672
assert self._status is not None
673673
temp = None
674674
if "temp" in self._status and self._status["temp"]:
@@ -681,7 +681,7 @@ def ambient_temperature(self) -> float | None:
681681
def rtc_temperature(self) -> float | None:
682682
"""Return the temperature of the real time clock sensor.
683683
684-
In degrees Celcius.
684+
In degrees Celsius.
685685
"""
686686
assert self._status is not None
687687
temp = self._status["temp2"] if self._status["temp2"] else None
@@ -693,7 +693,7 @@ def rtc_temperature(self) -> float | None:
693693
def ir_temperature(self) -> float | None:
694694
"""Return the temperature of the IR remote sensor.
695695
696-
In degrees Celcius.
696+
In degrees Celsius.
697697
"""
698698
assert self._status is not None
699699
temp = self._status["temp3"] if self._status["temp3"] else None
@@ -703,7 +703,7 @@ def ir_temperature(self) -> float | None:
703703

704704
@property
705705
def esp_temperature(self) -> float | None:
706-
"""Return the temperature of the ESP sensor, in degrees Celcius."""
706+
"""Return the temperature of the ESP sensor, in degrees Celsius."""
707707
assert self._status is not None
708708
if "temp4" in self._status:
709709
temp = self._status["temp4"] if self._status["temp4"] else None
@@ -712,7 +712,7 @@ def esp_temperature(self) -> float | None:
712712
return None
713713

714714
@property
715-
def time(self) -> Optional[datetime.datetime]:
715+
def time(self) -> datetime.datetime | None:
716716
"""Get the RTC time."""
717717
assert self._status is not None
718718
if "time" in self._status:

pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ score=no
3737
ignored-classes=_CountingAttr
3838

3939
[FORMAT]
40-
expected-line-ending-format=LF
40+
expected-line-ending-format=LF

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
awesomeversion
1+
awesomeversion

requirements_lint.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ black==22.6.0
33
flake8==5.0.4
44
mypy==0.971
55
pydocstyle==6.1.1
6-
pylint==2.14.5
6+
isort==5.10.1
7+
pylint==2.14.5

requirements_test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
-r requirements.txt
2+
pre-commit==2.19.0
23
pytest==7.1.2
34
pytest-cov==3.0.0
45
pytest-timeout==2.1.0
56
pytest-asyncio
67
requests_mock
78
aiohttp
89
aioresponses
10+
tox==3.25.0

0 commit comments

Comments
 (0)