Skip to content

Commit

Permalink
Upgrade pre-commit and migrate config to pyproject.toml (#82)
Browse files Browse the repository at this point in the history
* Fix pre-commit

* Drop unnecessary testing requirements
  • Loading branch information
puddly authored Oct 7, 2024
1 parent 2e302a2 commit 5cee8a2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 89 deletions.
55 changes: 12 additions & 43 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,22 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/PyCQA/autoflake
rev: v2.0.2
hooks:
- id: autoflake

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args:
- --quiet

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- Flake8-pyproject==1.2.3

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.3.0
hooks:
- id: codespell
args:
- --ignore-words-list=zigpy,hass
- --skip="./.*"
- --quiet-level=2
additional_dependencies: [tomli]
args: ["--toml", "pyproject.toml"]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix", "--config", "pyproject.toml"]
- id: ruff-format
args: ["--config", "pyproject.toml"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
- zigpy

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
hooks:
- id: ruff
args:
- --fix
59 changes: 30 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,10 @@ enabled = true
[project.scripts]
universal-silabs-flasher = "universal_silabs_flasher.__main__:main"

[tool.ruff]
select = [
# Pyflakes
"F",
# Pycodestyle
"E",
"W"
]
src = ["universal_silabs_flasher", "tests"]
[tool.codespell]
ignore-words-list = ["zigpy", "hass"]
skip = ["./.*", "pyproject.toml"]
quiet-level = 2

[tool.pytest.ini_options]
addopts = "--showlocals --verbose"
Expand All @@ -70,27 +65,33 @@ disable_error_code = [
"arg-type",
]

[tool.isort]
profile = "black"
# will group `import x` and `from x import` of the same module.
force_sort_within_sections = true
known_first_party = ["universal_silabs_flasher", "tests"]
forced_separate = "tests"
combine_as_imports = true

[tool.flake8]
exclude = [".venv", ".git", ".tox", "docs", "venv", "bin", "lib", "deps", "build"]
# To work with Black
max-line-length = 88
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# E501: line too long
# D202 No blank lines allowed after function docstring
ignore = ["W503", "E203", "E501", "D202"]
per-file-ignores = ["tests/*:F811,F401,F403"]
[tool.ruff]
src = ["universal_silabs_flasher", "tests"]

[tool.ruff.lint]
select = [
"F", # Pyflakes
"E", # Pycodestyle
"W",
"I", # isort
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
]

ignore = [
"TRY003",
]

[tool.ruff.lint.isort]
force-sort-within-sections = true
known-first-party = [
"universal_silabs_flasher",
"tests",
]
combine-as-imports = true
split-on-trailing-comma = false

[tool.coverage.run]
source = ["universal_silabs_flasher"]

[tool.pyupgrade]
py37plus = true
7 changes: 0 additions & 7 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Test dependencies

asynctest
coveralls
coverage[toml]
pytest
pytest-asyncio
pytest-cov
pytest-timeout
freezegun
ruff==0.0.261
tomli
6 changes: 3 additions & 3 deletions universal_silabs_flasher/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def __init__(self, states: set[str], initial: str) -> None:
self._states = states
self._state = initial

self._futures_for_state: typing.DefaultDict[
str, list[asyncio.Future]
] = collections.defaultdict(list)
self._futures_for_state: collections.defaultdict[str, list[asyncio.Future]] = (
collections.defaultdict(list)
)

@property
def state(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions universal_silabs_flasher/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def serialize(self) -> bytes:
]
),
4,
b"\xFF",
b"\xff",
)

def get_nabucasa_metadata(self) -> NabuCasaMetadata:
Expand Down Expand Up @@ -199,7 +199,7 @@ def serialize(self) -> bytes:
]
),
64,
b"\xFF",
b"\xff",
)

def get_nabucasa_metadata(self) -> NabuCasaMetadata:
Expand Down
2 changes: 1 addition & 1 deletion universal_silabs_flasher/flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def flash_firmware(
data = firmware.serialize()

# Pad the image to the XMODEM block size
data = pad_to_multiple(data, XMODEM_BLOCK_SIZE, b"\xFF")
data = pad_to_multiple(data, XMODEM_BLOCK_SIZE, b"\xff")

async with self._connect_gecko_bootloader(self.bootloader_baudrate) as gecko:
await gecko.probe()
Expand Down
6 changes: 2 additions & 4 deletions universal_silabs_flasher/spinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ async def send_frame(
retries: int,
timeout: float,
retry_delay: float,
) -> None:
...
) -> None: ...

@typing.overload
async def send_frame(
Expand All @@ -169,8 +168,7 @@ async def send_frame(
retries: int,
timeout: float,
retry_delay: float,
) -> SpinelFrame:
...
) -> SpinelFrame: ...

async def send_frame(
self,
Expand Down

0 comments on commit 5cee8a2

Please sign in to comment.