Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff instead of another linters #126

Merged
merged 14 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

41 changes: 1 addition & 40 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ repos:
- id: ruff
args:
- --fix
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py310-plus]
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
hooks:
- id: autoflake
args:
- --in-place
- --remove-duplicate-keys
- --ignore-init-module-imports
- --remove-all-unused-imports
- --remove-unused-variables
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
Expand All @@ -38,30 +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: ^(gios|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args:
- --quiet
files: ^(gios)/.+\.py$
- repo: https://github.com/pre-commit/mirrors-isort
rev: "v5.10.1"
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -78,7 +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
files: ^(gios)/.+\.py$
6 changes: 3 additions & 3 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Example for GIOS"""
"""Example for GIOS."""
import asyncio
import logging

Expand All @@ -12,13 +12,13 @@


async def main() -> None:
"""Main function."""
"""Run main function."""
async with ClientSession() as websession:
gios = Gios(GIOS_STATION_ID, websession)
try:
data = await gios.async_update()
except (ApiError, NoStationError, InvalidSensorsData, ClientError) as error:
print(f"{error}")
print(error)
return

latitude = gios.latitude
Expand Down
12 changes: 7 additions & 5 deletions gios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
URL_STATION,
URL_STATIONS,
)
from .exceptions import ApiError, InvalidSensorsData, NoStationError
from .exceptions import ApiError, InvalidSensorsDataError, NoStationError
from .model import GiosSensors

_LOGGER: Final = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,7 +64,9 @@ async def async_update(self) -> GiosSensors:
self._station_data = await self._get_station()

if not self._station_data:
raise InvalidSensorsData("Invalid measuring station data from GIOS API")
raise InvalidSensorsDataError(
"Invalid measuring station data from GIOS API"
)

for sensor_dict in self._station_data:
data[sensor_dict["param"]["paramCode"].lower()] = {
Expand Down Expand Up @@ -93,7 +95,7 @@ async def async_update(self) -> GiosSensors:
data.pop(sensor)

if not data:
raise InvalidSensorsData("Invalid sensor data from GIOS API")
raise InvalidSensorsDataError("Invalid sensor data from GIOS API")

indexes = await self._get_indexes()

Expand Down Expand Up @@ -151,5 +153,5 @@ async def _async_get(self, url: str) -> Any:
if resp.status != HTTPStatus.OK.value:
_LOGGER.warning("Invalid response from GIOS API: %s", resp.status)
raise ApiError(str(resp.status))
data = await resp.json()
return data

return await resp.json()
2 changes: 1 addition & 1 deletion gios/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ApiError(GiosError):
"""Raised when GIOS API request ended in error."""


class InvalidSensorsData(GiosError):
class InvalidSensorsDataError(GiosError):
"""Raised when sensors data is invalid."""


Expand Down
2 changes: 1 addition & 1 deletion gios/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Sensor:
"""Data class for sensor."""

name: str
id: int | None
id: int | None # noqa: A003
index: str | None = None
value: float | str | None = None

Expand Down
27 changes: 0 additions & 27 deletions pylintrc

This file was deleted.

102 changes: 102 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[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
"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]
"tests/*" = [
"PLR2004", # Magic value used in comparison
"S101", # Use of `assert` detected
]
"example.py" = [
"T201", # `print` found
]

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

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

[tool.coverage.run]
source = ["gios"]
6 changes: 1 addition & 5 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.0
pydocstyle==6.3.0
pylint_strict_informational==0.1
pylint==2.16.1
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
ruff==0.0.247
40 changes: 0 additions & 40 deletions setup.cfg

This file was deleted.

9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

PROJECT_DIR = Path(__file__).parent.resolve()
README_FILE = PROJECT_DIR / "README.md"
VERSION = "3.0.0"
VERSION = "3.1.0"

with open("requirements.txt", encoding="utf-8") as file:
requirements = file.read().splitlines()

setup(
name="gios",
Expand All @@ -20,9 +23,7 @@
packages=["gios"],
package_data={"gios": ["py.typed"]},
python_requires=">=3.10",
install_requires=list(
val.strip() for val in open("requirements.txt", encoding="utf-8")
),
install_requires=requirements,
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
Expand Down
Loading