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 enable isort (with custom sections) #2556

Merged
merged 3 commits into from
Jan 23, 2024
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 @@ -9,3 +9,5 @@
b5324820b299b1fe7da0608f0cc8ec47f58b1e40
# upgrade code style to 3.8 using pyupgrade
60f3bceacc4ab9567433d40ae3ed280750f55ff1
# sort imports using ruff
f99e9df700a8020e4c1967eb42dcb37ddd26e296
8 changes: 4 additions & 4 deletions benchmarks/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
by people working on Locust's development.
"""

from locust import User
from locust.dispatch import UsersDispatcher
from locust.runners import WorkerNode

import itertools
import statistics
import time

from prettytable import PrettyTable

from locust import User
from locust.dispatch import UsersDispatcher
from locust.runners import WorkerNode


class User1(User):
weight = 5
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
# All configuration values have a default value; values that are commented out
# serve to show the default value.

from locust.argument_parser import get_empty_argument_parser, setup_parser_arguments

import os
import subprocess
import sphinx_rtd_theme

from locust.argument_parser import get_empty_argument_parser, setup_parser_arguments
import sphinx_rtd_theme


# Run command `locust --help` and store output in cli-help-output.txt which is included in the docs
Expand Down
2 changes: 1 addition & 1 deletion examples/add_command_line_argument.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import HttpUser, task, events
from locust import HttpUser, events, task


@events.init_command_line_parser.add_listener
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import HttpUser, TaskSet, task, between
from locust import HttpUser, TaskSet, between, task


def index(l):
Expand Down
4 changes: 3 additions & 1 deletion examples/browse_docs_sequence_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# This locust test script example will simulate a user
# browsing the Locust documentation on https://docs.locust.io/

from locust import HttpUser, SequentialTaskSet, between, task

import random
from locust import HttpUser, SequentialTaskSet, task, between

from pyquery import PyQuery


Expand Down
4 changes: 3 additions & 1 deletion examples/browse_docs_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# This locust test script example will simulate a user
# browsing the Locust documentation on https://docs.locust.io/

from locust import HttpUser, TaskSet, between, task

import random
from locust import HttpUser, TaskSet, task, between

from pyquery import PyQuery


Expand Down
2 changes: 1 addition & 1 deletion examples/custom_messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import HttpUser, task, events, between
from locust import HttpUser, between, events, task
from locust.runners import MasterRunner, WorkerRunner

usernames = []
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_shape/double_wave.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from locust import HttpUser, LoadTestShape, TaskSet, constant, task

import math
from locust import HttpUser, TaskSet, task, constant
from locust import LoadTestShape


class UserTasks(TaskSet):
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_shape/stages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from locust import HttpUser, TaskSet, task, constant
from locust import LoadTestShape
from locust import HttpUser, LoadTestShape, TaskSet, constant, task


class UserTasks(TaskSet):
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_shape/staging_user_classes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from locust import HttpUser, TaskSet, task, constant
from locust import LoadTestShape
from locust import HttpUser, LoadTestShape, TaskSet, constant, task


class UserTasks(TaskSet):
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_shape/step_load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from locust import HttpUser, LoadTestShape, TaskSet, constant, task

import math
from locust import HttpUser, TaskSet, task, constant
from locust import LoadTestShape


class UserTasks(TaskSet):
Expand Down
9 changes: 4 additions & 5 deletions examples/custom_shape/wait_user_count.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from collections import namedtuple
from locust import HttpUser, LoadTestShape, TaskSet, constant, task

import math
import time
import random

from locust import HttpUser, TaskSet, task, constant
from locust import LoadTestShape
import time
from collections import namedtuple


class UserTasks(TaskSet):
Expand Down
1 change: 1 addition & 0 deletions examples/custom_wait_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from locust import HttpUser, TaskSet, task

import random


Expand Down
6 changes: 3 additions & 3 deletions examples/custom_xmlrpc_client/xmlrpc_locustfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import time
from xmlrpc.client import ServerProxy, Fault

from locust import User, task

import time
from xmlrpc.client import Fault, ServerProxy


class XmlRpcClient(ServerProxy):
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/debugging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import HttpUser, task, run_single_user
from locust import HttpUser, run_single_user, task


class QuickstartUser(HttpUser):
Expand Down
2 changes: 1 addition & 1 deletion examples/debugging_advanced.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import HttpUser, task, run_single_user
from locust import HttpUser, run_single_user, task
from locust.exception import StopUser


Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_user_credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# locustfile.py

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

USER_CREDENTIALS = [
("user1", "password"),
Expand Down
3 changes: 1 addition & 2 deletions examples/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
track the sum of the content-length header in all successful HTTP responses
"""

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


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

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

import json
from time import time
import os
from html import escape
from locust import HttpUser, TaskSet, task, web, between, events
from flask import Blueprint, render_template, jsonify, make_response, request
from time import time

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


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

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

import os
from time import time
from html import escape
from locust import HttpUser, TaskSet, task, web, between, events
from flask import Blueprint, render_template, jsonify, make_response
from time import time

from flask import Blueprint, jsonify, make_response, render_template


class MyTaskSet(TaskSet):
Expand Down
6 changes: 4 additions & 2 deletions examples/grpc/grpc_user.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from locust import User
from locust.exception import LocustError

import time
from typing import Any, Callable

import grpc
import grpc.experimental.gevent as grpc_gevent
from grpc_interceptor import ClientInterceptor
from locust import User
from locust.exception import LocustError

# patch grpc so that it uses gevent instead of asyncio
grpc_gevent.init_gevent()
Expand Down
1 change: 0 additions & 1 deletion examples/grpc/hello_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

import hello_pb2 as hello__pb2


Expand Down
9 changes: 5 additions & 4 deletions examples/grpc/hello_server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import hello_pb2_grpc
import hello_pb2
import grpc
from concurrent import futures
import logging
import time
from concurrent import futures

import grpc
import hello_pb2
import hello_pb2_grpc

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion examples/grpc/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from locust import events, task

import gevent
import grpc_user
import hello_pb2
import hello_pb2_grpc
from hello_server import start_server
from locust import events, task


# Start the dummy server. This is not something you would do in a real test.
Expand Down
3 changes: 2 additions & 1 deletion examples/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from locust import HttpUser, between, task

import time
from locust import HttpUser, task, between


class QuickstartUser(HttpUser):
Expand Down
8 changes: 4 additions & 4 deletions examples/manual_stats_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def my_task(self):
# If an Exception is raised, it'll be reported as a failure
"""

import random
from contextlib import contextmanager, ContextDecorator
from time import time, sleep
from locust import User, constant, events, task

from locust import User, task, constant, events
import random
from contextlib import ContextDecorator, contextmanager
from time import sleep, time


@contextmanager
Expand Down
6 changes: 3 additions & 3 deletions examples/multiple_hosts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

from locust import HttpUser, TaskSet, task, between
from locust import HttpUser, TaskSet, between, task
from locust.clients import HttpSession

import os


class MultipleHostsUser(HttpUser):
abstract = True
Expand Down
2 changes: 1 addition & 1 deletion examples/nested_inline_tasksets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import HttpUser, TaskSet, task, between
from locust import HttpUser, TaskSet, between, task


class WebsiteUser(HttpUser):
Expand Down
5 changes: 3 additions & 2 deletions examples/rest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from contextlib import contextmanager
from locust import task, run_single_user, FastHttpUser
from locust import FastHttpUser, run_single_user, task
from locust.contrib.fasthttp import RestResponseContextManager
from locust.user.wait_time import constant

from contextlib import contextmanager
from typing import Generator


Expand Down
1 change: 1 addition & 0 deletions examples/sdk_session_patching/session_patch_locustfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import locust
from locust.user import task

from archivist.archivist import Archivist # Example library under test


Expand Down
2 changes: 1 addition & 1 deletion examples/semaphore_wait.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from locust import HttpUser, TaskSet, task, events, between
from locust import HttpUser, TaskSet, between, events, task

from gevent.lock import Semaphore

Expand Down
6 changes: 4 additions & 2 deletions examples/stop_on_threshold.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# An example of how to stop locust if a threshold (in this case the fail ratio) is exceeded
from locust import task, HttpUser, events
from locust.runners import STATE_STOPPING, STATE_STOPPED, STATE_CLEANUP, WorkerRunner
from locust import HttpUser, events, task
from locust.runners import STATE_CLEANUP, STATE_STOPPED, STATE_STOPPING, WorkerRunner

import time

import gevent


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

import time
from locust import HttpUser, task, between


class Quickstart(HttpUser):
Expand Down
9 changes: 5 additions & 4 deletions examples/test_data_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
#
# try it out by running:
# locust -f test_data_management.py --headless -u 2 -t 5
from locust.user.wait_time import constant
from locust import HttpUser, task
from locust import events
from locust import HttpUser, events, task
from locust.runners import MasterRunner
import requests
from locust.user.wait_time import constant

import datetime

import requests


def timestring():
now = datetime.datetime.now()
Expand Down
7 changes: 4 additions & 3 deletions examples/use_as_lib.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
import gevent
from locust import HttpUser, task, events
from locust import HttpUser, events, task
from locust.env import Environment
from locust.stats import stats_printer, stats_history
from locust.log import setup_logging
from locust.stats import stats_history, stats_printer

import gevent

setup_logging("INFO", None)

Expand Down
8 changes: 5 additions & 3 deletions examples/web_ui_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

For more information, see https://docs.locust.io/en/stable/extending-locust.html#authentication
"""
import os
import json
from locust import HttpUser, events
from flask import url_for, Blueprint, request, make_response, redirect, session

import json
import os

from flask import Blueprint, make_response, redirect, request, session, url_for
from flask_login import UserMixin, login_user


Expand Down
Loading