Skip to content

Commit

Permalink
Merge pull request #3034 from insspb/feature/cq-imports
Browse files Browse the repository at this point in the history
Code quality: Fix unused imports and switch on related ruff check
  • Loading branch information
cyberw authored Jan 26, 2025
2 parents c2bc7ef + a8302fc commit 67fa859
Show file tree
Hide file tree
Showing 26 changed files with 32 additions and 37 deletions.
1 change: 0 additions & 1 deletion examples/custom_shape/wait_user_count.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from locust import HttpUser, LoadTestShape, TaskSet, constant, task

import math
import random
import time
from collections import namedtuple
Expand Down
2 changes: 0 additions & 2 deletions examples/dispatch_test_scripts/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from locust import HttpUser, LoadTestShape, constant, task

import math


class UserA(HttpUser):
wait_time = constant(600)
Expand Down
2 changes: 1 addition & 1 deletion examples/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
track the sum of the content-length header in all successful HTTP responses
"""

from locust import HttpUser, TaskSet, between, events, task, web
from locust import HttpUser, TaskSet, between, events, task


class MyTaskSet(TaskSet):
Expand Down
4 changes: 2 additions & 2 deletions examples/extend_web_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
successful HTTP responses and display them in the web UI.
"""

from locust import HttpUser, TaskSet, between, events, task, web
from locust import HttpUser, TaskSet, between, events, task

import json
import os
from html import escape
from time import time

from flask import Blueprint, jsonify, make_response, render_template, request
from flask import Blueprint, make_response, render_template, request


class MyTaskSet(TaskSet):
Expand Down
2 changes: 1 addition & 1 deletion examples/manual_stats_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def my_task(self):
from locust import User, constant, events, task

import random
from contextlib import ContextDecorator, contextmanager
from contextlib import contextmanager
from time import sleep, time


Expand Down
2 changes: 1 addition & 1 deletion examples/mongodb/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import between, task
from locust import task
from locust.contrib.mongodb import MongoDBUser

import os
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import TaskSet, between, task
from locust import task
from locust.contrib.postgres import PostgresUser

import os
Expand Down
2 changes: 0 additions & 2 deletions examples/terraform/aws/plan/basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from locust import HttpUser, between, task

import time


class Quickstart(HttpUser):
wait_time = between(1, 5)
Expand Down
4 changes: 2 additions & 2 deletions examples/web_ui_cache_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
and display them in the web UI.
"""

from locust import HttpUser, TaskSet, between, events, task, web
from locust import HttpUser, TaskSet, between, events, task

import json
import os
from html import escape
from time import time

from flask import Blueprint, jsonify, make_response, render_template, request
from flask import Blueprint, make_response, render_template, request


class MyTaskSet(TaskSet):
Expand Down
5 changes: 4 additions & 1 deletion locust/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
print("Uninstall trio package and remove the setting.")
try:
# preserve backwards compatibility for now
import trio
import trio # noqa: F401
except ModuleNotFoundError:
# dont show a massive callstack if trio is not installed
os._exit(1)
Expand Down Expand Up @@ -50,6 +50,9 @@
"events",
"LoadTestShape",
"run_single_user",
"HttpLocust",
"Locust",
"__version__",
)

# Used for raising a DeprecationWarning if old Locust/HttpLocust is used
Expand Down
1 change: 0 additions & 1 deletion locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os
import platform
import socket
import ssl
import sys
import tempfile
import textwrap
Expand Down
2 changes: 1 addition & 1 deletion locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from locust.env import Environment
from locust.exception import CatchResponseError, LocustError, ResponseError
from locust.user import User
from locust.util.deprecation import DeprecatedFastHttpLocustClass as FastHttpLocust
from locust.util.deprecation import DeprecatedFastHttpLocustClass as FastHttpLocust # noqa: F401

import json
import json as unshadowed_json # some methods take a named parameter called json
Expand Down
3 changes: 0 additions & 3 deletions locust/html.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import glob
import os
import pathlib
from html import escape
from itertools import chain
from json import dumps

from jinja2 import Environment as JinjaEnvironment
from jinja2 import FileSystemLoader
Expand Down
5 changes: 2 additions & 3 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import importlib.metadata
import inspect
import itertools
import json
import logging
import os
import signal
Expand Down Expand Up @@ -39,12 +38,12 @@

# import external plugins if installed to allow for registering custom arguments etc
try:
import locust_plugins # pyright: ignore[reportMissingImports]
import locust_plugins # pyright: ignore[reportMissingImports] # noqa: F401
except ModuleNotFoundError as e:
if e.msg != "No module named 'locust_plugins'":
raise
try:
import locust_cloud # pyright: ignore[reportMissingImports]
import locust_cloud # pyright: ignore[reportMissingImports] # noqa: F401

locust_cloud_version = f" (locust-cloud {importlib.metadata.version('locust-cloud')})"
except ModuleNotFoundError as e:
Expand Down
5 changes: 5 additions & 0 deletions locust/rpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
__all__ = (
"Message",
"rpc",
)

from . import zmqrpc as rpc
from .protocol import Message
1 change: 0 additions & 1 deletion locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from locust import FastHttpUser
from locust.argument_parser import parse_options
from locust.contrib.fasthttp import FastHttpSession
from locust.exception import CatchResponseError, InterruptTaskSet, LocustError, ResponseError
from locust.user import TaskSet, task
Expand Down
1 change: 0 additions & 1 deletion locust/test/test_load_locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import filecmp
import os
import pathlib
import textwrap

from .mock_locustfile import MOCK_LOCUSTFILE_CONTENT, mock_locustfile
Expand Down
2 changes: 1 addition & 1 deletion locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
import textwrap
import unittest
from subprocess import DEVNULL, PIPE, STDOUT
from subprocess import PIPE, STDOUT
from tempfile import TemporaryDirectory
from unittest import TestCase

Expand Down
1 change: 0 additions & 1 deletion locust/test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os
import unittest
from io import StringIO
from random import randint
from tempfile import NamedTemporaryFile, TemporaryDirectory
from unittest import mock

Expand Down
2 changes: 1 addition & 1 deletion locust/test/test_sequential_taskset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import User, constant, task
from locust import User, task
from locust.exception import RescheduleTask
from locust.user.sequential_taskset import SequentialTaskSet

Expand Down
1 change: 0 additions & 1 deletion locust/test/test_wait_time.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from locust import TaskSet, User, between, constant, constant_throughput
from locust.exception import MissingWaitTimeError

import random
import time
Expand Down
7 changes: 1 addition & 6 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@
from locust.user import User, task
from locust.web import WebUI

import copy
import csv
import json
import logging
import os
import re
import textwrap
import traceback
from io import StringIO
from tempfile import NamedTemporaryFile, TemporaryDirectory
from tempfile import NamedTemporaryFile

import gevent
import requests
from flask_login import UserMixin
from pyquery import PyQuery as pq

from ..util.load_locustfile import load_locustfile
from .mock_locustfile import mock_locustfile
from .testcases import LocustTestCase
from .util import create_tls_cert

Expand Down
2 changes: 1 addition & 1 deletion locust/test/test_zmqrpc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust.exception import RPCError, RPCReceiveError, RPCSendError
from locust.exception import RPCError, RPCSendError
from locust.rpc import Message, zmqrpc
from locust.test.testcases import LocustTestCase

Expand Down
7 changes: 7 additions & 0 deletions locust/user/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
__all__ = (
"HttpUser",
"tag",
"task",
"TaskSet",
"User",
)
from .task import TaskSet, tag, task
from .users import HttpUser, User
1 change: 0 additions & 1 deletion locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from io import StringIO
from itertools import chain
from json import dumps
from time import time
from typing import TYPE_CHECKING, Any, TypedDict

import gevent
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ extend-exclude = [
"examples/issue_*.py",
"src/readthedocs-sphinx-search/",
]
lint.ignore = ["E402", "E501", "E713", "E731", "E741", "F401"]
lint.ignore = ["E402", "E501", "E713", "E731", "E741"]
lint.select = ["E", "F", "W", "UP", "FA102", "I001"]

[tool.ruff.lint.per-file-ignores]
Expand Down

0 comments on commit 67fa859

Please sign in to comment.