diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef1c6fe..c165334 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,27 +2,22 @@ default_language_version: python: python3.9 default_install_hook_types: [pre-commit,pre-push] default_stages: [commit] +exclude: ^docs/ repos: - repo: local hooks: - id: ruff name: ruff - entry: ruff check + entry: ruff check -n language: system - types_or: [python] + types_or: [ python ] - - id: black - name: black formatter + - id: ruff format + name: ruff format + entry: ruff format --check . language: system - entry: black --check - types_or: [python] - - - id: isort - name: isort - language: system - entry: isort --filter-files --check - types_or: [python] + types_or: [ python ] - id: pylint name: pylint static code analyzer diff --git a/pyproject.toml b/pyproject.toml index 4149835..db17242 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,17 +38,25 @@ disable = [ ] [tool.ruff] -target-version = 'py39' +target-version = 'py38' +line-length = 120 +exclude = [ + "docs/" +] +[tool.ruff.format] +preview = true + +[tool.ruff.lint] # See complete list : https://beta.ruff.rs/docs/rules select = [ # "F", # pyflakes -# "E", # pycodestyle errors + "E", # pycodestyle errors "W", # pycodestyle warnings "C90", # mccabe + "I", # isort # "N", # pep8-naming "UP", # pyupgrade "YTT", # flake8-2020 - "CPY", # Copyright-related rules "C4", # flake8-comprehensions "T10", # flake8-debugger "DJ", # flake8-django @@ -60,12 +68,12 @@ select = [ "PIE", # flake8-pie "T20", # flake8-print # "PYI", # flake8-pyi -# "PT", # flake8-pytest-style + "PT", # flake8-pytest-style "Q", # flake8-quotes "RSE", # flake8-raise # "SLF", # flake8-self "SLOT", # flake8-slots -# "SIM", # flake8-simplify + "SIM", # flake8-simplify "TID", # flake8-tidy-imports "TCH", # flake8-type-checking "INT", # flake8-gettext @@ -90,18 +98,24 @@ fixable = [ # Never enforce some rules ignore = [ "E501", # line length violations + "ISC001" # Implicitly concatenated string literals on one line (conflict with ruff format) ] ## Ignore some rules for some files -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "**/*test*.py" = [ "SLF001", # Private member accessed "T201", # print found ] -[tool.ruff.mccabe] +[tool.ruff.lint.isort] +case-sensitive = true +force-wrap-aliases = true +combine-as-imports = true + +[tool.ruff.lint.mccabe] max-complexity = 15 -[tool.ruff.pyupgrade] +[tool.ruff.lint.pyupgrade] # Preserve types, even if a file imports `from __future__ import annotations`. keep-runtime-typing = true \ No newline at end of file diff --git a/tests-requirements.txt b/tests-requirements.txt index 194531f..00e9cc8 100644 --- a/tests-requirements.txt +++ b/tests-requirements.txt @@ -1,7 +1,5 @@ aiohttp asynctest -black -isort pre-commit pyOpenSSL pylint @@ -13,6 +11,8 @@ pytest-xdist ruff setuptools tox +tox-uv treq +uv virtualenv wheel \ No newline at end of file diff --git a/tests/test_aio.py b/tests/test_aio.py index 60fb212..8f1c375 100644 --- a/tests/test_aio.py +++ b/tests/test_aio.py @@ -10,14 +10,14 @@ Check = consul.Check -@pytest.fixture +@pytest.fixture() async def consul_obj(consul_port): c = consul.aio.Consul(port=consul_port) yield c await c.close() -@pytest.fixture +@pytest.fixture() async def consul_acl_obj(acl_consul): c = consul.aio.Consul(port=acl_consul.port, token=acl_consul.token) yield c diff --git a/tests/test_base.py b/tests/test_base.py index ac80bcd..5adfba8 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -112,7 +112,8 @@ def test_node_meta(self): for r in _should_support_node_meta(c): assert r().params == [] assert sorted(r(node_meta={"env": "prod", "net": 1}).params) == sorted([ - ("node-meta", "net:1"), ("node-meta", "env:prod") + ("node-meta", "net:1"), + ("node-meta", "env:prod"), ]) diff --git a/tests/test_std.py b/tests/test_std.py index d862d82..b351724 100644 --- a/tests/test_std.py +++ b/tests/test_std.py @@ -18,10 +18,10 @@ def test_uri(self): assert http.uri("/v1/kv", params={"index": 1}) == "http://127.0.0.1:8500/v1/kv?index=1" -@pytest.fixture +@pytest.fixture() def consul_obj(consul_port): c = consul.std.Consul(port=consul_port) - yield c + return c class TestConsul: @@ -369,8 +369,8 @@ def test_agent_members(self, consul_obj): members = c.agent.members() for x in members: assert x["Status"] == 1 - assert not x["Name"] is None - assert not x["Tags"] is None + assert x["Name"] is not None + assert x["Tags"] is not None assert c.agent.self()["Member"] in members wan_members = c.agent.members(wan=True)