Skip to content

Commit

Permalink
Merge pull request #1 from NitorCreations/config
Browse files Browse the repository at this point in the history
Add formatting and linting config
  • Loading branch information
Jalle19 authored Sep 5, 2024
2 parents 64e06c8 + a674b18 commit 25594ce
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 8 deletions.
16 changes: 8 additions & 8 deletions custom_components/vinx/lw3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import re

from asyncio import StreamReader, StreamWriter
from dataclasses import dataclass
from typing import Optional


@dataclass
Expand Down Expand Up @@ -33,8 +33,8 @@ def __init__(self, hostname: str, port: int, timeout: int = 5):
self._hostname = hostname
self._port = port
self._timeout = timeout
self._reader: Optional[StreamReader] = None
self._writer: Optional[StreamWriter] = None
self._reader: StreamReader | None = None
self._writer: StreamWriter | None = None
self._semaphore = asyncio.Semaphore()

async def _read_until(self, phrase: str) -> str | None:
Expand All @@ -52,22 +52,22 @@ async def connect(self):

@staticmethod
def _is_error_response(response: str) -> bool:
return response[1] == 'E'
return response[1] == "E"

@staticmethod
def parse_response(response: str) -> PropertyResponse | ErrorResponse:
if LW3._is_error_response(response):
matches = re.search(r'^(.E) (.*) %(E[0-9]+):(.*)$', response)
matches = re.search(r"^(.E) (.*) %(E[0-9]+):(.*)$", response)
return ErrorResponse(matches.group(1), matches.group(2), matches.group(3), matches.group(4))

matches = re.fullmatch(r'^(.*) (.*)=(.*)$', response)
matches = re.fullmatch(r"^(.*) (.*)=(.*)$", response)
return PropertyResponse(matches.group(1), matches.group(2), matches.group(3))

async def _read_and_parse_response(self) -> PropertyResponse:
response = (await self._read_until("\r\n"))
response = await self._read_until("\r\n")

if response is None:
raise EOFError('Reached EOF while reading, connection probably lost')
raise EOFError("Reached EOF while reading, connection probably lost")

result = self.parse_response(response.strip())

Expand Down
127 changes: 127 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
[tool.black]
# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
line-length = 120
target-version = ["py311", "py312"]
include = '\.pyi?$'
extend-exclude = '''
(
venv*
)
'''

[tool.ruff]
# https://github.com/astral-sh/ruff#configuration
include = ["*.py", "*.pyi", "**/pyproject.toml"]
extend-include = ["*.ipynb"]
target-version = "py311"
line-length = 120

[tool.ruff.lint]
exclude = [
"__pypackages__",
"_build",
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".ruff_cache",
".svn",
".tox",
".venv",
"*.ipynb",
"buck-out",
"build",
"dist",
"node_modules",
"venv*",
]
ignore = []
per-file-ignores = {}
# https://docs.astral.sh/ruff/rules/
select = ["E4", "E7", "E9", "F", "W", "N", "UP", "I"]

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"I",
"N",
"Q",
"S",
"T",
"W",
"ANN",
"ARG",
"BLE",
"COM",
"DJ",
"DTZ",
"EM",
"ERA",
"EXE",
"FBT",
"ICN",
"INP",
"ISC",
"NPY",
"PD",
"PGH",
"PIE",
"PL",
"PT",
"PTH",
"PYI",
"RET",
"RSE",
"RUF",
"SIM",
"SLF",
"TCH",
"TID",
"TRY",
"UP",
"YTT",
]
unfixable = []

[tool.ruff.lint.isort]
# https://docs.astral.sh/ruff/settings/#lintisort
combine-as-imports = true
lines-between-types = 1
order-by-type = true
known-first-party = ["src"]
section-order = [
"future",
"standard-library",
"third-party",
"first-party",
"local-folder",
]

[tool.isort]
# https://pycqa.github.io/isort/docs/configuration/options.html
# profile = "black"
# manually specifying black compatibility to override line length
combine_as_imports = true
ensure_newline_before_comments = true
extend_skip = [".idea", ".vscode", ".venv", "venv"]
extend_skip_glob = ["venv*"]
force_grid_wrap = 0
include_trailing_comma = true
line_length = 120
multi_line_output = 3
py_version = 311
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
use_parentheses = true

0 comments on commit 25594ce

Please sign in to comment.