Skip to content

Commit be46d7b

Browse files
authored
Switch to ruff (#449)
1 parent 57bcaa7 commit be46d7b

21 files changed

Lines changed: 80 additions & 240 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ jobs:
1616
- name: Install dependencies
1717
run: uv sync
1818

19-
- name: Lint
20-
run: uv run pylint *.py
21-
22-
- name: Black
23-
run: uv run black --version && uv run black . --check
19+
- name: Ruff
20+
run: uv run ruff check
2421

2522
- name: Tests
2623
run: uv run pytest .

bot.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
2-
# pylint: disable=too-many-lines
2+
33
"""Slack bot for managing releases"""
4+
45
import asyncio
56
from asyncio import sleep as async_sleep # importing separately for simpler mocking
67
from collections import namedtuple
@@ -118,7 +119,6 @@ def get_envs():
118119
return env_dict
119120

120121

121-
# pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-public-methods
122122
class Bot:
123123
"""Slack bot used to manage the release"""
124124

@@ -179,7 +179,7 @@ async def translate_slack_usernames(self, names):
179179
slack_users = await self.lookup_users()
180180
return {match_user(slack_users, author) for author in names}
181181

182-
except: # pylint: disable=bare-except
182+
except: # noqa: E722
183183
log.exception(
184184
"Exception during translate_slack_usernames, continuing with untranslated names..."
185185
)
@@ -982,7 +982,7 @@ async def commits_since_last_release(self, command_args):
982982
],
983983
)
984984

985-
async def start_new_releases(self, command_args): # pylint: disable=too-many-locals
985+
async def start_new_releases(self, command_args):
986986
"""
987987
Start new releases for all projects with new commits
988988
@@ -1314,7 +1314,6 @@ def make_commands(self):
13141314
),
13151315
]
13161316

1317-
# pylint: disable=too-many-locals
13181317
async def run_command(self, *, manager, channel_id, words):
13191318
"""
13201319
Run a command
@@ -1339,7 +1338,7 @@ async def run_command(self, *, manager, channel_id, words):
13391338
for arg, parser in zip(args, command.parsers):
13401339
try:
13411340
parsed_args.append(parser.func(arg))
1342-
except: # pylint: disable=bare-except
1341+
except: # noqa: E722
13431342
await self.say(
13441343
channel_id=channel_id,
13451344
text=(
@@ -1403,7 +1402,7 @@ async def handle_message(self, *, manager, channel_id, words):
14031402
except (InputException, ReleaseException) as ex:
14041403
log.exception("A BotException was raised:")
14051404
await self.say(channel_id=channel_id, text=f"Oops! {ex}")
1406-
except: # pylint: disable=bare-except
1405+
except: # noqa: E722
14071406
log.exception("Exception found when handling a message")
14081407
await self.say(
14091408
channel_id=channel_id,

bot_local.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
"""Run the bot locally to test it out"""
3+
34
import asyncio
45
import sys
56

@@ -14,9 +15,7 @@
1415
class ConsoleBot(Bot):
1516
"""Fake console bot"""
1617

17-
async def say(
18-
self, *, channel_id, text="", attachments=None, message_type=""
19-
): # pylint: disable=unused-argument
18+
async def say(self, *, channel_id, text="", attachments=None, message_type=""):
2019
"""Print messages to stdout"""
2120
attachment_text = ""
2221
if attachments is not None:

bot_local_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
pytestmark = pytest.mark.asyncio
99

1010

11-
# pylint: disable=unused-argument
1211
async def test_bot_local(mocker, test_repo):
1312
"""
1413
bot_local should execute a command

bot_test.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
NPM_TOKEN = "npm-token"
4747

4848

49-
# pylint: disable=redefined-outer-name, too-many-lines
5049
class DoofSpoof(Bot):
5150
"""Testing bot"""
5251

@@ -129,7 +128,7 @@ def sleep_sync_mock(mocker):
129128

130129

131130
@pytest.fixture
132-
def doof(sleep_sync_mock): # pylint: disable=unused-argument
131+
def doof(sleep_sync_mock):
133132
"""Create a Doof"""
134133
yield DoofSpoof()
135134

@@ -140,11 +139,11 @@ def mock_labels(mocker):
140139

141140
_label = None
142141

143-
def _set_label(*args, label, **kwargs): # pylint: disable=unused-argument
142+
def _set_label(*args, label, **kwargs):
144143
nonlocal _label
145144
_label = label
146145

147-
def _get_label(*args, **kwargs): # pylint: disable=unused-argument
146+
def _get_label(*args, **kwargs):
148147
return _label
149148

150149
mock_set = mocker.async_patch("bot.set_release_label", side_effect=_set_label)
@@ -392,11 +391,8 @@ async def test_hash(doof, test_repo, mocker, deployment_server_type, expected_ur
392391
)
393392

394393

395-
# pylint: disable=too-many-locals
396394
@pytest.mark.parametrize("command", ["release", "start release"])
397-
async def test_release(
398-
doof, test_repo, mocker, command, mock_labels
399-
): # pylint: disable=unused-argument
395+
async def test_release(doof, test_repo, mocker, command, mock_labels):
400396
"""
401397
Doof should do a release when asked
402398
"""
@@ -453,10 +449,9 @@ async def test_release(
453449
assert wait_for_checkboxes_sync_mock.called is True
454450

455451

456-
# pylint: disable=too-many-locals
457452
async def test_hotfix_release(
458453
doof, test_repo, test_repo_directory, mocker, mock_labels
459-
): # pylint: disable=unused-argument
454+
):
460455
"""
461456
Doof should do a hotfix when asked
462457
"""
@@ -643,9 +638,7 @@ async def test_release_library(doof, library_test_repo, mocker):
643638

644639

645640
@pytest.mark.parametrize("project_type", [WEB_APPLICATION_TYPE, LIBRARY_TYPE])
646-
async def test_finish_release(
647-
doof, mocker, project_type, mock_labels
648-
): # pylint: disable=unused-argument
641+
async def test_finish_release(doof, mocker, project_type, mock_labels):
649642
"""
650643
Doof should finish a release when asked
651644
"""
@@ -736,10 +729,9 @@ async def test_webhook_different_callback_id(doof, mocker):
736729
assert finish_release_mock.called is False
737730

738731

739-
# pylint: disable=too-many-arguments
740732
async def test_webhook_finish_release(
741733
doof, mocker, test_repo, library_test_repo, mock_labels
742-
): # pylint: disable=unused-argument
734+
):
743735
"""
744736
Finish the release
745737
"""
@@ -965,7 +957,7 @@ async def test_publish(doof, library_test_repo, mocker, packaging_tool):
965957
["wait for checkboxes", LIBRARY_TYPE],
966958
["publish 1.2.3", WEB_APPLICATION_TYPE],
967959
],
968-
) # pylint: disable=too-many-arguments
960+
)
969961
async def test_invalid_project_type(
970962
doof, test_repo, library_test_repo, command, project_type
971963
):
@@ -1030,7 +1022,7 @@ async def test_help(doof):
10301022
@pytest.mark.parametrize("has_checkboxes", [True, False])
10311023
async def test_wait_for_checkboxes(
10321024
mocker, doof, sleep_sync_mock, test_repo, has_checkboxes, mock_labels
1033-
): # pylint: disable=unused-argument,too-many-positional-arguments
1025+
):
10341026
"""wait_for_checkboxes should poll github, parse checkboxes and see if all are checked"""
10351027
org, repo = get_org_and_repo(test_repo.repo_url)
10361028
channel_id = test_repo.channel_id
@@ -1114,10 +1106,10 @@ async def test_wait_for_checkboxes(
11141106

11151107
async def test_wait_for_checkboxes_no_pr(
11161108
mocker, doof, test_repo, mock_labels, sleep_sync_mock
1117-
): # pylint: disable=unused-argument
1109+
):
11181110
"""wait_for_checkboxes should exit without error if the PR doesn't exist"""
11191111
org, repo = get_org_and_repo(test_repo.repo_url)
1120-
mock_set, mock_get = mock_labels # pylint: disable=unused-variable
1112+
mock_set, mock_get = mock_labels
11211113
mock_set(label=WAITING_FOR_CHECKBOXES)
11221114

11231115
pr = ReleasePR(
@@ -1139,7 +1131,6 @@ async def test_wait_for_checkboxes_no_pr(
11391131
sleep_sync_mock.assert_called_once_with(10)
11401132

11411133

1142-
# pylint: disable=too-many-arguments
11431134
@pytest.mark.parametrize(
11441135
"repo_info, has_release_pr, has_expected",
11451136
[
@@ -1190,9 +1181,7 @@ async def test_startup(doof, mocker, repo_info, has_release_pr, has_expected):
11901181
assert run_release_lifecycle_mock.called is False
11911182

11921183

1193-
async def test_wait_for_deploy_rc(
1194-
doof, test_repo, mocker, mock_labels
1195-
): # pylint: disable=unused-argument
1184+
async def test_wait_for_deploy_rc(doof, test_repo, mocker, mock_labels):
11961185
"""Bot._wait_for_deploy_prod should wait until repo has been deployed to RC"""
11971186
wait_for_deploy_mock = mocker.async_patch("bot.wait_for_deploy")
11981187
org, repo = get_org_and_repo(test_repo.repo_url)
@@ -1209,7 +1198,7 @@ async def test_wait_for_deploy_rc(
12091198
)
12101199
wait_for_checkboxes_sync_mock = mocker.async_patch("bot.Bot.wait_for_checkboxes")
12111200

1212-
await doof._wait_for_deploy_rc( # pylint: disable=protected-access
1201+
await doof._wait_for_deploy_rc(
12131202
repo_info=test_repo, manager="me", release_pr=release_pr
12141203
)
12151204

@@ -1233,9 +1222,7 @@ async def test_wait_for_deploy_rc(
12331222
)
12341223

12351224

1236-
async def test_wait_for_deploy_prod(
1237-
doof, test_repo, mocker, mock_labels
1238-
): # pylint: disable=unused-argument
1225+
async def test_wait_for_deploy_prod(doof, test_repo, mocker, mock_labels):
12391226
"""Bot._wait_for_deploy_prod should wait until repo has been deployed to production"""
12401227
wait_for_deploy_mock = mocker.async_patch("bot.wait_for_deploy")
12411228
version = "1.2.345"
@@ -1247,7 +1234,7 @@ async def test_wait_for_deploy_prod(
12471234
"version", "https://github.com/org/repo/pulls/123456", "body", 123456, False
12481235
)
12491236

1250-
await doof._wait_for_deploy_prod( # pylint: disable=protected-access
1237+
await doof._wait_for_deploy_prod(
12511238
repo_info=test_repo, manager="me", release_pr=release_pr
12521239
)
12531240

@@ -1388,7 +1375,7 @@ async def test_start_new_releases(
13881375
expected_version,
13891376
has_release_pr,
13901377
has_new_commits,
1391-
): # pylint: disable=too-many-positional-arguments
1378+
):
13921379
"""start new releases command should iterate through releases and start ones without an existing PR"""
13931380
old_version = "1.2.3"
13941381
default_branch = "default"

conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
)
5959

6060

61-
# pylint: disable=redefined-outer-name, unused-argument
6261
@pytest.fixture
6362
def test_repo_directory():
6463
"""Helper function to make a repo for testing"""
@@ -130,7 +129,7 @@ def timezone():
130129

131130

132131
@pytest.fixture
133-
def mocker(mocker): # pylint: disable=redefined-outer-name
132+
def mocker(mocker):
134133
"""Override to add async_patch"""
135134

136135
def async_patch(*args, **kwargs):

finish_release_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
pytestmark = pytest.mark.asyncio
2525

2626

27-
# pylint: disable=unused-argument, redefined-outer-name
2827
async def test_check_release_tag(test_repo_directory):
2928
"""check_release_tag should error if the most recent release commit doesn't match the version given"""
3029
await check_call(
@@ -88,7 +87,6 @@ async def test_tag_release(mocker, test_repo_directory):
8887
)
8988

9089

91-
# pylint: disable=too-many-locals
9290
async def test_finish_release(mocker, timezone, test_repo_directory, test_repo):
9391
"""finish_release should tag, merge and push the release"""
9492
token = "token"

github.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ def github_auth_headers(github_access_token):
8686
}
8787

8888

89-
async def create_pr(
90-
*, github_access_token, repo_url, title, body, head, base
91-
): # pylint: disable=too-many-arguments
89+
async def create_pr(*, github_access_token, repo_url, title, body, head, base):
9290
"""
9391
Create a pull request
9492

lib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,9 @@ async def virtualenv(python_interpreter, env):
299299
cwd=virtualenv_dir,
300300
)
301301
output = output_bytes.decode()
302-
yield virtualenv_dir, dict(
303-
line.split("=", 1) for line in output.splitlines() if "=" in line
302+
yield (
303+
virtualenv_dir,
304+
dict(line.split("=", 1) for line in output.splitlines() if "=" in line),
304305
)
305306

306307

publish.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ async def upload_to_pypi(project_dir):
4040
)
4141

4242

43-
async def upload_with_twine(
44-
*, project_dir, virtualenv_dir, environ
45-
): # pylint: disable=too-many-locals
43+
async def upload_with_twine(*, project_dir, virtualenv_dir, environ):
4644
"""
4745
Upload a version of a project to PYPI
4846

0 commit comments

Comments
 (0)