Skip to content

Commit

Permalink
code-style & ci: update workflow
Browse files Browse the repository at this point in the history
Move from black/isort to ruff format and ruff linter "I" rules
Use uv and tox-uv for faster dependencies installation
  • Loading branch information
Mathias Brulatout authored and mbrulatout committed Mar 15, 2024
1 parent 1e3692a commit 261e9e0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
19 changes: 7 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 22 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
aiohttp
asynctest
black
isort
pre-commit
pyOpenSSL
pylint
Expand All @@ -13,6 +11,8 @@ pytest-xdist
ruff
setuptools
tox
tox-uv
treq
uv
virtualenv
wheel
4 changes: 2 additions & 2 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
])


Expand Down
8 changes: 4 additions & 4 deletions tests/test_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 261e9e0

Please sign in to comment.