Use ruff instead of black, flake8, autoflake, pyupgrade

Config adapted from pytest.
This commit is contained in:
Ran Benita
2024-04-02 23:23:31 +03:00
parent c01de1c73e
commit 816c9dcda1
15 changed files with 109 additions and 73 deletions

View File

@@ -230,9 +230,7 @@ class DSession:
)
if maximum_reached:
if self._max_worker_restart == 0:
msg = "worker {} crashed and worker restarting disabled".format(
node.gateway.id
)
msg = f"worker {node.gateway.id} crashed and worker restarting disabled"
else:
msg = "maximum crashed workers reached: %d" % self._max_worker_restart
self._summary_report = msg
@@ -463,7 +461,7 @@ class TerminalDistReporter:
rinfo = gateway._rinfo()
different_interpreter = rinfo.executable != sys.executable
if different_interpreter:
version = "%s.%s.%s" % rinfo.version_info[:3]
version = "{}.{}.{}".format(*rinfo.version_info[:3])
self.rewrite(
f"[{gateway.id}] {rinfo.platform} Python {version} cwd: {rinfo.cwd}",
newline=True,
@@ -504,7 +502,7 @@ def get_default_max_worker_restart(config):
def get_workers_status_line(
status_and_items: Sequence[tuple[WorkerStatus, int]]
status_and_items: Sequence[tuple[WorkerStatus, int]],
) -> str:
"""
Return the line to display during worker setup/collection based on the

View File

@@ -254,7 +254,7 @@ class StatRecorder:
return
time.sleep(checkinterval)
def check(self, removepycfiles: bool = True) -> bool: # noqa, too complex
def check(self, removepycfiles: bool = True) -> bool:
changed = False
newstat: Dict[Path, os.stat_result] = {}
for rootdir in self.rootdirlist:

View File

@@ -296,7 +296,7 @@ def pytest_cmdline_main(config):
if not val("collectonly") and _is_distribution_mode(config) and usepdb:
raise pytest.UsageError(
"--pdb is incompatible with distributing tests; try using -n0 or -nauto."
) # noqa: E501
)
# -------------------------------------------------------------------------

View File

@@ -325,7 +325,7 @@ def setup_config(config, basetemp):
if __name__ == "__channelexec__":
channel = channel # type: ignore[name-defined] # noqa: F821
channel = channel # type: ignore[name-defined] # noqa: F821, PLW0127
workerinput, args, option_dict, change_sys_path = channel.receive() # type: ignore[name-defined]
if change_sys_path is None:

View File

@@ -243,7 +243,7 @@ class LoadScheduling:
return
# Collections are identical, create the index of pending items.
self.collection = list(self.node2collection.values())[0]
self.collection = next(iter(self.node2collection.values()))
self.pending[:] = range(len(self.collection))
if not self.collection:
return
@@ -260,7 +260,7 @@ class LoadScheduling:
# to each node - which is suboptimal when you have less than
# 2 * len(nodes) tests.
nodes = cycle(self.nodes)
for i in range(len(self.pending)):
for _ in range(len(self.pending)):
self._send_tests(next(nodes), 1)
else:
# Send batches of consecutive tests. By default, pytest sorts tests

View File

@@ -208,7 +208,6 @@ class LoadScopeScheduling:
- ``DSession.worker_collectionfinish``.
"""
# Check that add_node() was called on the node before
assert node in self.assigned_work
@@ -301,7 +300,6 @@ class LoadScopeScheduling:
If there are any globally pending work units left then this will check
if the given node should be given any more tests.
"""
# Do not add more work to a node shutting down
if node.shutting_down:
return

View File

@@ -1,4 +1,7 @@
from collections import namedtuple
from __future__ import annotations
from typing import Any
from typing import NamedTuple
from _pytest.runner import CollectReport
@@ -7,7 +10,10 @@ from xdist.report import report_collection_diff
from xdist.workermanage import parse_spec_config
NodePending = namedtuple("NodePending", ["node", "pending"])
class NodePending(NamedTuple):
node: Any
pending: list[int]
# Every worker needs at least 2 tests in queue - the current and the next one.
MIN_PENDING = 2
@@ -285,7 +291,7 @@ class WorkStealingScheduling:
return
# Collections are identical, create the index of pending items.
self.collection = list(self.node2collection.values())[0]
self.collection = next(iter(self.node2collection.values()))
self.pending[:] = range(len(self.collection))
if not self.collection:
return

View File

@@ -175,7 +175,7 @@ class HostRSync(execnet.RSync):
sourcedir: PathLike,
*,
ignores: Optional[Sequence[PathLike]] = None,
**kwargs: object
**kwargs: object,
) -> None:
if ignores is None:
ignores = []
@@ -322,8 +322,8 @@ class WorkerController:
self.log(f"queuing {eventname}(**{kwargs})")
self.putevent((eventname, kwargs))
def process_from_remote(self, eventcall): # noqa too complex
"""this gets called for each object we receive from
def process_from_remote(self, eventcall):
"""This gets called for each object we receive from
the other side and if the channel closes.
Note that channel callbacks run in the receiver
@@ -400,7 +400,7 @@ class WorkerController:
except KeyboardInterrupt:
# should not land in receiver-thread
raise
except: # noqa
except BaseException:
from _pytest._code import ExceptionInfo
excinfo = ExceptionInfo.from_current()