Skip to content

Commit

Permalink
Use ruff in CI (#109)
Browse files Browse the repository at this point in the history
* Use ruff in CI

* Fix lint errors
  • Loading branch information
bieniu committed Feb 21, 2023
1 parent c307976 commit 043a5f5
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 147 deletions.
50 changes: 7 additions & 43 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.247
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
hooks:
- id: autoflake
- id: ruff
args:
- --in-place
- --remove-duplicate-keys
- --ignore-init-module-imports
- --remove-all-unused-imports
- --remove-unused-variables
- --fix
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((nextdns|tests)/.+)?[^/]+\.py$
files: ^((gios|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
Expand All @@ -32,31 +23,6 @@ repos:
- --quiet-level=2
exclude_types: [csv, json]
exclude: ^tests/fixtures/
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- pycodestyle
- pyflakes
- flake8-docstrings
- pydocstyle
- flake8-comprehensions
- flake8-noqa
- mccabe
files: ^(nextdns|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args:
- --quiet
- --configfile=bandit.yaml
files: ^(nextdns|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -73,9 +39,7 @@ repos:
- id: prettier
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.0.0"
rev: "v1.0.1"
hooks:
- id: mypy
additional_dependencies:
- types-orjson
files: ^(nextdns)/.+\.py$
files: ^(gios)/.+\.py$
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"files.associations": {
"*.yaml": "home-assistant"
},
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 Maciej Bieniek
Copyright 2023 Maciej Bieniek

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
1 change: 0 additions & 1 deletion bandit.yaml

This file was deleted.

12 changes: 8 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


async def main():
"""Main function."""
"""Run main function."""
async with ClientSession() as websession:
try:
nextdns = await NextDns.create(websession, API_KEY)
Expand All @@ -39,7 +39,9 @@ async def main():

# get CSV logs and save to file
# logs = await nextdns.get_logs(profile_id)
# with open(f"nextdns_{profile_id}_logs.csv", "w", encoding="utf-8") as file:
# with open(
# f"nextdns_{profile_id}_logs.csv", "w", encoding="utf-8"
# ) as file:
# file.write(logs)

# enable block page
Expand All @@ -54,10 +56,12 @@ async def main():
print(f"ClientConnectorError: {error}")
else:
print(
f"Profile: {profile_name} (id: {profile_id}, fingerprint: {profile_fingerprint})"
f"Profile: {profile_name} "
f"(id: {profile_id}, fingerprint: {profile_fingerprint})"
)
print(
f"Does this device use NextDNS?: {connection_status.connected}, using profile: {connection_status.profile_id}"
f"Does this device use NextDNS?: {connection_status.connected}, "
f"using profile: {connection_status.profile_id}"
)
print(status)
print(dnssec)
Expand Down
6 changes: 4 additions & 2 deletions nextdns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ async def set_logs_location(self, profile_id: str, location: str) -> bool:
"""Set logs location."""
if location not in ALLOWED_LOGS_LOCATION:
raise ValueError(
f"Invalid logs location value. Allowed values are: {ALLOWED_LOGS_LOCATION}"
"Invalid logs location value. "
f"Allowed values are: {ALLOWED_LOGS_LOCATION}"
)

url = MAP_SETTING[ATTR_LOGS_LOCATION].url.format(profile_id=profile_id)
Expand All @@ -300,7 +301,8 @@ async def set_logs_retention(self, profile_id: str, hours: int) -> bool:
"""Set logs retention."""
if hours not in ALLOWED_LOGS_RETENTION:
raise ValueError(
f"Invalid logs retention value. Allowed values are: {ALLOWED_LOGS_RETENTION}"
"Invalid logs retention value. "
f"Allowed values are: {ALLOWED_LOGS_RETENTION}"
)

url = MAP_SETTING[ATTR_LOGS_RETENTION].url.format(profile_id=profile_id)
Expand Down
4 changes: 2 additions & 2 deletions nextdns/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class Profile(NextDnsData):
allowlist: list[dict[str, Any]]
denylist: list[dict[str, Any]]
fingerprint: str
id: str
id: str # noqa: A003
name: str
parental_control: dict[str, Any]
privacy: dict[str, Any]
Expand Down Expand Up @@ -280,7 +280,7 @@ class Settings(NextDnsData):
class ProfileInfo(NextDnsData):
"""ProfileInfo class."""

id: str
id: str # noqa: A003
fingerprint: str
name: str

Expand Down
24 changes: 0 additions & 24 deletions pylintrc

This file was deleted.

113 changes: 113 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
[tool.pytest.ini_options]
asyncio_mode = "strict"

[tool.mypy]
python_version = "3.10"
show_error_codes = true
follow_imports = "silent"
ignore_missing_imports = true
warn_incomplete_stub = true
warn_redundant_casts = true
warn_unused_configs = true
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
strict_equality = true
warn_return_any = true
warn_unused_ignores = true
warn_unreachable = true

[tool.ruff]
target-version = "py310"

select = [
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C", # complexity
"C4", # flake8-comprehensions
"C90", # mccabe
"D", # docstrings
"DJ", # flake8-django
"DTZ", # flake8-datetimez
"E", # pycodestyle
"ERA", # eradicate
"EXE", # flake8-executable
"F", # pyflakes/autoflake
"FBT", # flake8-boolean-trap
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
"NPY", # NumPy-specific rules
"PD", # pandas-vet
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # Pylint
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"Q", # flake8-quotes
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"S", # flake8-bandit
"SIM", # flake8-simplify
"SLF", # flake8-self
"T10", # flake8-debugger
"T20", # flake8-print
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]

ignore = [
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D404", # First word of the docstring should not be This
"D406", # Section name should end with a newline
"D407", # Section name underlining
"D411", # Missing blank line before section
"E731", # Do not assign a lambda expression, use a def
"FBT001", # Boolean positional arg in function definition
"PLR0912", # Too many branches
"PLR0915", # Too many statements
"PT023", # Use `@pytest.mark.asyncio()` over `@pytest.mark.asyncio`
"TRY003", # Avoid specifying long messages outside the exception class
]

[tool.ruff.per-file-ignores]
"const.py" = [
"E501", # Line too long
"S105", # Possible hardcoded password
]
"model.py" = [
"ARG004", # Unused static method argument
"S105", # Possible hardcoded password
]
"tests/*" = [
"FBT003", # Boolean positional value in function call
"PLR2004", # Magic value used in comparison
"S101", # Use of `assert` detected
]
"example.py" = [
"ERA001", # Found commented-out code
"T201", # `print` found
]

[tool.ruff.pyupgrade]
keep-runtime-typing = true

[tool.ruff.mccabe]
max-complexity = 25

[tool.coverage.run]
source = ["gios"]
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
-r requirements-test.txt
pre-commit==3.0.4
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability

-e .
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
8 changes: 2 additions & 6 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
aioresponses==0.7.4
black==23.1.0
coverage==7.1.0
flake8==6.0.0
isort==5.12.0
mypy==1.0.1
pydocstyle==6.3.0
pylint_strict_informational==0.1
pylint==2.16.2
pytest-asyncio==0.20.3
pytest-cov==4.0.0
pytest-error-for-skips==2.0.2
pytest-timeout==2.1.0
pytest==7.2.1
pytest==7.2.1
ruff==0.0.247
41 changes: 0 additions & 41 deletions setup.cfg

This file was deleted.

0 comments on commit 043a5f5

Please sign in to comment.