Skip to content

Commit

Permalink
Switch code formatter and linter from Black to Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
homeworkprod committed Apr 20, 2024
1 parent 317ecdf commit 3fbf5bb
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -22,6 +22,8 @@ Changelog
- Publish Docker images for platform `linux/arm64` (in addition to
`linux/amd64`).

- Switched code formatter and linter from Black to Ruff.


0.9 (2022-05-07)
----------------
Expand Down
48 changes: 43 additions & 5 deletions pyproject.toml
Expand Up @@ -5,11 +5,6 @@ requires = [
]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 80
skip-string-normalization = true
target-version = [ "py38" ]

[tool.mypy]
python_version = "3.8"
ignore_missing_imports = true
Expand All @@ -18,3 +13,46 @@ no_implicit_optional = true
[tool.pytest.ini_options]
addopts = "-vv -ra --showlocals"
testpaths = [ "tests" ]

[tool.ruff]
line-length = 80

[tool.ruff.format]
quote-style = "single"
line-ending = "lf"

[tool.ruff.lint]
select = [
"B",
"E",
"EXE",
"F",
"G",
"ICN",
"ISC",
"PLE",
"PLW",
"PTH",
"PYI",
"Q",
"RSE",
"S",
"TID",
"UP",
"W",
"YTT",
]
ignore = [
"ISC001", # Conflict with Ruff's formatter
"Q001", # Conflict with Ruff's formatter
]

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"
multiline-quotes = "single"

[tool.ruff.lint.isort]
combine-as-imports = true
force-sort-within-sections = true
lines-after-imports = 2
order-by-type = false
2 changes: 1 addition & 1 deletion requirements-dev.txt
@@ -1,2 +1,2 @@
black==22.3.0
mypy==0.950
ruff==0.4.1
2 changes: 1 addition & 1 deletion src/weitersager/config.py
Expand Up @@ -109,7 +109,7 @@ def _get_http_config(data: dict[str, Any]) -> HttpConfig:


def _get_channel_tokens_to_channel_names(
data: dict[str, Any]
data: dict[str, Any],
) -> dict[str, str]:
channel_tokens_to_channel_names = {}

Expand Down
2 changes: 1 addition & 1 deletion tests/processor/test_message_handled.py
Expand Up @@ -27,7 +27,7 @@ def processor():
channels=set(),
)

config = Config(log_level="debug", http=http_config, irc=irc_config)
config = Config(log_level='debug', http=http_config, irc=irc_config)

return Processor(config)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_irc_channel.py
Expand Up @@ -11,9 +11,9 @@
@pytest.mark.parametrize(
'channel, expected_name, expected_password',
[
(IrcChannel('#example'), '#example', None ),
(IrcChannel('#example', password=None), '#example', None ),
(IrcChannel('#headquarters', password='secret'), '#headquarters', 'secret'),
(IrcChannel('#example'), '#example', None),
(IrcChannel('#example', password=None), '#example', None),
(IrcChannel('#whq', password='secret'), '#whq', 'secret'),
],
)
def test_irc_channel_creation(channel, expected_name, expected_password):
Expand Down
20 changes: 10 additions & 10 deletions tests/test_load_config.py
Expand Up @@ -14,7 +14,7 @@
)


TOML_CONFIG = '''\
TOML_CONFIG = """\
log_level = "warning"
[http]
Expand Down Expand Up @@ -42,15 +42,15 @@
{ name = "#elite-astrology", password = "twinkle-twinkle" },
{ name = "#hubblebubble" },
]
'''
"""


def test_load_config():
toml = StringIO(TOML_CONFIG)

config = load_config(toml)

assert config.log_level == "WARNING"
assert config.log_level == 'WARNING'

assert config.http == HttpConfig(
host='0.0.0.0',
Expand Down Expand Up @@ -80,21 +80,21 @@ def test_load_config():
)


TOML_CONFIG_WITH_DEFAULTS = '''\
TOML_CONFIG_WITH_DEFAULTS = """\
[irc.server]
host = "irc.onlinetalk.test"
[irc.bot]
nickname = "TownCrier"
'''
"""


def test_load_config_with_defaults():
toml = StringIO(TOML_CONFIG_WITH_DEFAULTS)

config = load_config(toml)

assert config.log_level == "DEBUG"
assert config.log_level == 'DEBUG'

assert config.http == HttpConfig(
host='127.0.0.1',
Expand All @@ -118,10 +118,10 @@ def test_load_config_with_defaults():
)


TOML_CONFIG_WITHOUT_IRC_SERVER_TABLE = '''\
TOML_CONFIG_WITHOUT_IRC_SERVER_TABLE = """\
[irc.bot]
nickname = "Lokalrunde"
'''
"""


def test_load_config_without_irc_server_table():
Expand All @@ -132,12 +132,12 @@ def test_load_config_without_irc_server_table():
assert config.irc.server is None


TOML_CONFIG_WITHOUT_IRC_SERVER_HOST = '''\
TOML_CONFIG_WITHOUT_IRC_SERVER_HOST = """\
[irc.server]
[irc.bot]
nickname = "Lokalrunde"
'''
"""


def test_load_config_without_irc_server_host():
Expand Down

0 comments on commit 3fbf5bb

Please sign in to comment.