Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff set python version and enable more rules #2551

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
313b80f27f525441c449593a3aeaf38389f63c13
# upgrade typing annotations using fix-future-annotations
b5324820b299b1fe7da0608f0cc8ec47f58b1e40
# upgrade code style to 3.8 using pyupgrade
60f3bceacc4ab9567433d40ae3ed280750f55ff1
4 changes: 2 additions & 2 deletions benchmarks/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ class User100(User):
print()
print(table)

with open(f"results-dispatch-benchmarks-{int(now)}.txt", "wt") as file:
with open(f"results-dispatch-benchmarks-{int(now)}.txt", "w") as file:
file.write(table.get_string())

with open(f"results-dispatch-benchmarks-{int(now)}.json", "wt") as file:
with open(f"results-dispatch-benchmarks-{int(now)}.json", "w") as file:
file.write(table.get_json_string())
2 changes: 1 addition & 1 deletion locust/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _sort_workers(self):
worker_nodes_by_id = sorted(self._worker_nodes, key=lambda w: w.id)

# Give every worker an index indicating how many workers came before it on that host
workers_per_host = defaultdict(lambda: 0)
workers_per_host = defaultdict(int)
for worker_node in worker_nodes_by_id:
host = worker_node.id.split("_")[0]
worker_node._index_within_host = workers_per_host[host]
Expand Down
11 changes: 5 additions & 6 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ def spawn_users(self, user_classes_spawn_count: dict[str, int], wait: bool = Fal
self.update_state(STATE_SPAWNING)

logger.debug(
"Spawning additional %s (%s already running)..."
% (json.dumps(user_classes_spawn_count), json.dumps(self.user_classes_count))
f"Spawning additional {json.dumps(user_classes_spawn_count)} ({json.dumps(self.user_classes_count)} already running)..."
)

def spawn(user_class: str, spawn_count: int) -> list[User]:
Expand Down Expand Up @@ -902,7 +901,7 @@ def quit(self) -> None:
self.stop(send_stop_to_client=False)
logger.debug("Quitting...")
for client in self.clients.all:
logger.debug("Sending quit message to worker %s (index %s)" % (client.id, self.get_worker_index(client.id)))
logger.debug(f"Sending quit message to worker {client.id} (index {self.get_worker_index(client.id)})")
self.server.send_to_client(Message("quit", None, client.id))
gevent.sleep(0.5) # wait for final stats report from all workers
self.greenlet.kill(block=True)
Expand Down Expand Up @@ -1123,7 +1122,7 @@ def worker_count(self) -> int:

@property
def reported_user_classes_count(self) -> dict[str, int]:
reported_user_classes_count: dict[str, int] = defaultdict(lambda: 0)
reported_user_classes_count: dict[str, int] = defaultdict(int)
for client in self.clients.ready + self.clients.spawning + self.clients.running:
for name, count in client.user_classes_count.items():
reported_user_classes_count[name] += count
Expand All @@ -1139,11 +1138,11 @@ def send_message(self, msg_type: str, data: dict[str, Any] | None = None, client
If None, will send to all attached workers
"""
if client_id:
logger.debug("Sending %s message to worker %s" % (msg_type, client_id))
logger.debug(f"Sending {msg_type} message to worker {client_id}")
self.server.send_to_client(Message(msg_type, data, client_id))
else:
for client in self.clients.all:
logger.debug("Sending %s message to worker %s" % (msg_type, client.id))
logger.debug(f"Sending {msg_type} message to worker {client.id}")
self.server.send_to_client(Message(msg_type, data, client.id))


Expand Down
6 changes: 1 addition & 5 deletions locust/user/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,7 @@ class Tasks(TaskSet):
return random.randint(self.min_wait, self.max_wait) / 1000.0
else:
raise MissingWaitTimeError(
"You must define a wait_time method on either the %s or %s class"
% (
type(self.user).__name__,
type(self).__name__,
)
"You must define a wait_time method on either the {type(self.user).__name__} or {type(self).__name__} class"
)

def wait(self):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ license-files = ["LICENSE"]
include-package-data = false

[tool.ruff]
target-version = "py38"
line-length = 120
extend-exclude = [
"build",
"examples/issue_*.py",
"src/readthedocs-sphinx-search/",
]
ignore = ["E402", "E501", "E713", "E731", "E741", "F401"]
select = ["E", "F", "W"]
select = ["E", "F", "W", "UP", "FA102"]

[tool.ruff.per-file-ignores]
"examples/*" = ["F841"]
Expand Down