Skip to content

Commit

Permalink
Merge pull request #255 from backend-developers-ltd/bugbear
Browse files Browse the repository at this point in the history
Add bugbear ruleset to ruff config
  • Loading branch information
olzhasar-reef authored Sep 26, 2024
2 parents 6533ed3 + c750a70 commit dec5045
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion compute_horde/compute_horde/test_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def start_process(cls, args, additional_env: dict[str, str]):

@classmethod
def wait_for_process_start(cls, process_name, probe_function, process: subprocess.Popen):
for i in range(300):
for _ in range(300):
if probe_function():
return
if process.poll() is not None:
Expand Down
5 changes: 3 additions & 2 deletions compute_horde/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ line-length = 100

[tool.ruff.lint]
# TODO add D
select = ["E", "F", "I", "UP"]
select = ["E", "F", "I", "UP", "B"]
# TODO: remove E501 once docstrings are formatted
ignore = [
"D100", "D105", "D107", "D200", "D202", "D203", "D205", "D212", "D400", "D401", "D415",
"D101", "D102","D103", "D104", # TODO remove once we have docstring for all public methods
"E501", # TODO: remove E501 once docstrings are formatted
"B027", "B904", "B905",
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"test/**" = ["D", "F403", "F405"]
"**/tests/**" = ["D", "F403", "F405", "B018"]

[tool.codespell]
skip = 'pdm.lock'
Expand Down
2 changes: 1 addition & 1 deletion executor/bin/rotate-local-backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def rotate_backups(path, file_count):
files = files[:-file_count]
if files:
print(f"Removing {len(files)} old files")
for mtime, f in files:
for _mtime, f in files:
f.unlink()
else:
print("No old files to remove")
Expand Down
5 changes: 3 additions & 2 deletions executor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ line-length = 100

[tool.ruff.lint]
# TODO add D
select = ["E", "F", "I", "UP"]
select = ["E", "F", "I", "UP", "B"]
# TODO: remove E501 once docstrings are formatted
ignore = [
"D100", "D105", "D107", "D200", "D202", "D203", "D205", "D212", "D400", "D401", "D415",
"D101", "D102","D103", "D104", # TODO remove once we have docstring for all public methods
"E501", # TODO: remove E501 once docstrings are formatted
"B027", "B904", "B905",
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"test/**" = ["D", "F403", "F405"]
"**/tests/**" = ["D", "F403", "F405", "B018"]

[tool.codespell]
skip = '*.min.js,*.lock,*/monitoring_certs/*'
Expand Down
2 changes: 1 addition & 1 deletion miner/bin/rotate-local-backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def rotate_backups(path, file_count):
files = files[:-file_count]
if files:
print(f"Removing {len(files)} old files")
for mtime, f in files:
for _mtime, f in files:
f.unlink()
else:
print("No old files to remove")
Expand Down
5 changes: 3 additions & 2 deletions miner/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ line-length = 100

[tool.ruff.lint]
# TODO add D
select = ["E", "F", "I", "UP"]
select = ["E", "F", "I", "UP", "B"]
# TODO: remove E501 once docstrings are formatted
ignore = [
"D100", "D105", "D107", "D200", "D202", "D203", "D205", "D212", "D400", "D401", "D415",
"D101", "D102","D103", "D104", # TODO remove once we have docstring for all public methods
"E501", # TODO: remove E501 once docstrings are formatted
"B027", "B904", "B905",
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"test/**" = ["D", "F403", "F405"]
"**/tests/**" = ["D", "F403", "F405", "B018"]

[tool.codespell]
skip = '*.min.js,*.lock,*/monitoring_certs/*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def __init__(self, reason: str, errors: list[Error]):
self.errors = errors


async def save_facilitator_event(subtype: str, long_description: str, data={}, success=False):
async def save_facilitator_event(
subtype: str, long_description: str, data: dict[str, str] | None = None, success=False
):
await SystemEvent.objects.using(settings.DEFAULT_DB_ALIAS).acreate(
type=SystemEvent.EventType.FACILITATOR_CLIENT_ERROR,
subtype=subtype,
long_description=long_description,
data=data,
data=data or {},
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ def __init__(
mocked_commit_weights=lambda: (True, ""),
mocked_reveal_weights=lambda: (True, ""),
mocked_metagraph=lambda: MockMetagraph(),
hyperparameters=MockHyperparameters(
commit_reveal_weights_enabled=False,
commit_reveal_weights_interval=1000,
max_weight_limit=65535,
),
hyperparameters=None,
block_duration=timedelta(seconds=1),
override_block_number=None,
increase_block_number_with_each_call=False,
Expand All @@ -222,7 +218,11 @@ def __init__(
self.mocked_commit_weights = mocked_commit_weights
self.mocked_reveal_weights = mocked_reveal_weights
self.mocked_metagraph = mocked_metagraph
self.hyperparameters = hyperparameters
self.hyperparameters = hyperparameters or MockHyperparameters(
commit_reveal_weights_enabled=False,
commit_reveal_weights_interval=1000,
max_weight_limit=65535,
)
self.weights_set: list[list[numbers.Number]] = []
self.weights_committed: list[list[numbers.Number]] = []
self.weights_revealed: list[list[numbers.Number]] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_debug_run_organic_job_command__job_not_created():
Miner.objects.create(hotkey="miner_client")

with redirect_stdout(io.StringIO()) as buf:
with pytest.raises(BaseException):
with pytest.raises(SystemExit):
management.call_command(
"debug_run_organic_job", docker_image="noop", timeout=4, cmd_args=""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def test_facilitator_client(ws_server_cls):
facilitator_client.specs_task.cancel()
task.cancel()
if ws_server.facilitator_error:
assert False, ws_server.facilitator_error
pytest.fail(str(ws_server.facilitator_error))


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ async def interaction_callback(miner_client, after_job_sent):
miner_client = mocked_synthetic_miner_client.instance
async for job in SyntheticJob.objects.filter(job_uuid__in=job_uuids):
receipt = miner_client._query_sent_models(
lambda m: m.payload.job_uuid == str(job.job_uuid), V0JobFinishedReceiptRequest
lambda m, j=job: m.payload.job_uuid == str(j.job_uuid), V0JobFinishedReceiptRequest
)[0]
time_took = receipt.payload.time_took_us / 1_000_000
assert abs(job.score * time_took - expected_multiplier) < 0.0001
Expand Down Expand Up @@ -555,7 +555,7 @@ async def interaction_callback(miner_client, after_job_sent):
miner_client = mocked_synthetic_miner_client.instance
for job in SyntheticJob.objects.filter(job_uuid__in=job_uuids):
receipt = miner_client._query_sent_models(
lambda m: m.payload.job_uuid == str(job.job_uuid), V0JobFinishedReceiptRequest
lambda m, j=job: m.payload.job_uuid == str(j.job_uuid), V0JobFinishedReceiptRequest
)[0]
time_took = receipt.payload.time_took_us / 1_000_000
assert abs(job.score * time_took - expected_multiplier) < 0.0001
Expand Down
2 changes: 1 addition & 1 deletion validator/bin/rotate-local-backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def rotate_backups(path, file_count):
files = files[:-file_count]
if files:
print(f"Removing {len(files)} old files")
for mtime, f in files:
for _mtime, f in files:
f.unlink()
else:
print("No old files to remove")
Expand Down
5 changes: 3 additions & 2 deletions validator/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@ line-length = 100
[tool.ruff.lint]
# TODO add D
select = [
"E", "F", "I", "UP",
"E", "F", "I", "UP", "B",
"TCH005",
]
# TODO: remove E501 once docstrings are formatted
ignore = [
"D100", "D105", "D107", "D200", "D202", "D203", "D205", "D212", "D400", "D401", "D415",
"D101", "D102","D103", "D104", # TODO remove once we have docstring for all public methods
"E501", # TODO: remove E501 once docstrings are formatted
"B027", "B904", "B905",
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"test/**" = ["D", "F403", "F405"]
"**/tests/**" = ["D", "F403", "F405", "B018"]

[tool.codespell]
skip = '*.min.js,*.lock,*/monitoring_certs/*'
Expand Down

0 comments on commit dec5045

Please sign in to comment.