Skip to content

Commit

Permalink
Merge pull request #15 from SvenskaSpel/switch-from-pylint-and-black-…
Browse files Browse the repository at this point in the history
…to-ruff

Switch from pylint and black to ruff
  • Loading branch information
cyberw authored Jan 19, 2024
2 parents 654ab55 + 60b5927 commit da68e94
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"charliermarsh.ruff",
"ms-python.mypy-type-checker"
]
}
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"python.formatting.provider": "black",
"files.exclude": {
"**/env": true,
"**/__pycache__": true,
Expand All @@ -12,14 +11,13 @@
"**/_version.py": true,
"**/.eggs": true
},
"python.linting.pylintEnabled": true,
"files.watcherExclude": {
"**/target": true
},
"editor.formatOnSave": true,
"[python]": {
"editor.formatOnPaste": false,
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "basic",
Expand Down
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ If you want to talk about a contribution before you start writing code & making

In order to maintain a good level of quality, please ensure that your code:

* Is formatted using black (https://github.com/psf/black)

* Passes linting with pylint (https://www.pylint.org/)
* Is formatted and linted using [ruff](https://docs.astral.sh/ruff/)
22 changes: 13 additions & 9 deletions locust_swarm/swarm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
try:
import svs_locust # pylint: disable=import-outside-toplevel
import svs_locust
except ModuleNotFoundError:
# svs-locust is a library that is only used internally at Svenska Spel, please ignore it
# We need to import it here to get some variables and the path to the installed package
Expand All @@ -15,7 +15,6 @@
from datetime import datetime, timezone
import psutil
import configargparse
import locust_plugins
import locust.util.timespan
from locust_swarm._version import version

Expand Down Expand Up @@ -190,7 +189,7 @@ def check_output_multiple(list_of_commands):
for process in running_procs:
retcode = process.poll()
if retcode is not None: # Process finished.
running_procs.remove(process) # pylint: disable=modified-iterating-list
running_procs.remove(process)
if retcode != 0:
raise Exception(f"Bad return code {retcode} from command: {process.args}")
break
Expand Down Expand Up @@ -251,11 +250,16 @@ def cleanup(server_list):
def upload(server):
files = [args.locustfile or "locustfile.py"] + args.extra_files
if not args.skip_plugins:
files.append(os.path.dirname(locust_plugins.__file__))
try:
files.append(os.path.dirname(svs_locust.__file__))
except NameError:
pass
import locust_plugins

files.append(os.path.dirname(locust_plugins.__file__))
try:
files.append(os.path.dirname(svs_locust.__file__))
except NameError:
pass
except ImportError:
pass # locust-plugins wasnt installed
if len(files) > 1:
filestr = "{" + ",".join(files) + "}"
else:
Expand Down Expand Up @@ -371,7 +375,7 @@ def main():
locustfile = args.locustfile or "locustfile.py"

if "/" in locustfile:
parser.error( # pylint: disable=not-callable
parser.error(
"Locustfile (-f) must be a file in the current directory (I'm lazy and havent fixed support for this yet)"
)

Expand Down Expand Up @@ -523,7 +527,7 @@ def get_available_servers_and_lock_them():
if max_run_time + args.exit_timeout < time.time() - start_time:
logging.error(
f"Locust exceeded the run time specified ({max_run_time}) by more than 30 seconds, giving up"
) # pylint: disable=raise-missing-from
)
master_proc.send_signal(1)
except KeyboardInterrupt:
pass
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tool.black]
[tool.ruff]
line-length = 120
8 changes: 3 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ envlist = py{38,39,310,311}

[testenv]
deps =
black
pylint
locust-plugins # not strictly a requirement, but probably better to have it than not
ruff
commands =
pylint locust_swarm/
black --check locust_swarm/
ruff check
ruff format --check
swarm --help

0 comments on commit da68e94

Please sign in to comment.