Skip to content

Commit 23c7b2f

Browse files
alperbColdHeat
andauthored
use ruff instead of flake8 (CTFd#2278)
* add: use ruff instead of flake8 * Update ruff switches and remove flake8 plugins * fix: ignore linting rules * fix: ignore I001 * fix: spaces before noqa --------- Co-authored-by: Kevin Chung <[email protected]>
1 parent faa9370 commit 23c7b2f

24 files changed

+51
-54
lines changed

CTFd/__init__.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ def create_app(config="CTFd.config.Config"):
185185
app.jinja_loader = jinja2.ChoiceLoader(loaders)
186186

187187
from CTFd.models import ( # noqa: F401
188-
db,
189-
Teams,
190-
Solves,
191188
Challenges,
192189
Fails,
190+
Files,
193191
Flags,
192+
Solves,
194193
Tags,
195-
Files,
194+
Teams,
196195
Tracking,
196+
db,
197197
)
198198

199199
url = create_database()
@@ -214,8 +214,8 @@ def create_app(config="CTFd.config.Config"):
214214
# db.create_all call because tests use the in-memory SQLite
215215
# database (each connection, including db creation, is a new db).
216216
# https://docs.sqlalchemy.org/en/13/dialects/sqlite.html#foreign-key-support
217-
from sqlalchemy.engine import Engine
218217
from sqlalchemy import event
218+
from sqlalchemy.engine import Engine
219219

220220
@event.listens_for(Engine, "connect")
221221
def set_sqlite_pragma(dbapi_connection, connection_record):
@@ -275,16 +275,16 @@ def set_sqlite_pragma(dbapi_connection, connection_record):
275275
init_template_globals(app)
276276

277277
# Importing here allows tests to use sensible names (e.g. api instead of api_bp)
278-
from CTFd.views import views
279-
from CTFd.teams import teams
280-
from CTFd.users import users
281-
from CTFd.challenges import challenges
282-
from CTFd.scoreboard import scoreboard
283-
from CTFd.auth import auth
284278
from CTFd.admin import admin
285279
from CTFd.api import api
286-
from CTFd.events import events
280+
from CTFd.auth import auth
281+
from CTFd.challenges import challenges
287282
from CTFd.errors import render_error
283+
from CTFd.events import events
284+
from CTFd.scoreboard import scoreboard
285+
from CTFd.teams import teams
286+
from CTFd.users import users
287+
from CTFd.views import views
288288

289289
app.register_blueprint(views)
290290
app.register_blueprint(teams)

CTFd/admin/__init__.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import csv
1+
import csv # noqa: I001
22
import datetime
3-
import os
43
from io import StringIO
4+
import os
55

66
from flask import Blueprint, abort
77
from flask import current_app as app
@@ -18,14 +18,14 @@
1818
admin = Blueprint("admin", __name__)
1919

2020
# isort:imports-firstparty
21-
from CTFd.admin import challenges # noqa: F401
22-
from CTFd.admin import notifications # noqa: F401
23-
from CTFd.admin import pages # noqa: F401
24-
from CTFd.admin import scoreboard # noqa: F401
25-
from CTFd.admin import statistics # noqa: F401
26-
from CTFd.admin import submissions # noqa: F401
27-
from CTFd.admin import teams # noqa: F401
28-
from CTFd.admin import users # noqa: F401
21+
from CTFd.admin import challenges # noqa: F401,I001
22+
from CTFd.admin import notifications # noqa: F401,I001
23+
from CTFd.admin import pages # noqa: F401,I001
24+
from CTFd.admin import scoreboard # noqa: F401,I001
25+
from CTFd.admin import statistics # noqa: F401,I001
26+
from CTFd.admin import submissions # noqa: F401,I001
27+
from CTFd.admin import teams # noqa: F401,I001
28+
from CTFd.admin import users # noqa: F401,I001
2929
from CTFd.cache import (
3030
cache,
3131
clear_challenges,

CTFd/api/v1/challenges.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import List # noqa: I001
22

33
from flask import abort, render_template, request, url_for
44
from flask_restx import Namespace, Resource

CTFd/api/v1/statistics/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
)
66

77
# isort:imports-firstparty
8-
from CTFd.api.v1.statistics import challenges # noqa: F401
8+
from CTFd.api.v1.statistics import challenges # noqa: F401,I001
99
from CTFd.api.v1.statistics import scores # noqa: F401
1010
from CTFd.api.v1.statistics import submissions # noqa: F401
1111
from CTFd.api.v1.statistics import teams # noqa: F401

CTFd/auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import base64
1+
import base64 # noqa: I001
22

33
import requests
44
from flask import Blueprint, abort

CTFd/cache/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def clear_config():
6060

6161

6262
def clear_standings():
63-
from CTFd.models import Users, Teams
63+
from CTFd.models import Users, Teams # noqa: I001
6464
from CTFd.constants.static import CacheKeys
6565
from CTFd.utils.scores import get_standings, get_team_standings, get_user_standings
6666
from CTFd.api.v1.scoreboard import ScoreboardDetail, ScoreboardList
@@ -99,7 +99,7 @@ def clear_standings():
9999

100100

101101
def clear_challenges():
102-
from CTFd.utils.challenges import get_all_challenges
102+
from CTFd.utils.challenges import get_all_challenges # noqa: I001
103103
from CTFd.utils.challenges import get_solves_for_challenge_id
104104
from CTFd.utils.challenges import get_solve_ids_for_user_id
105105
from CTFd.utils.challenges import get_solve_counts_for_challenges
@@ -124,7 +124,7 @@ def clear_user_recent_ips(user_id):
124124

125125

126126
def clear_user_session(user_id):
127-
from CTFd.utils.user import (
127+
from CTFd.utils.user import ( # noqa: I001
128128
get_user_attrs,
129129
get_user_place,
130130
get_user_score,
@@ -138,7 +138,7 @@ def clear_user_session(user_id):
138138

139139

140140
def clear_all_user_sessions():
141-
from CTFd.utils.user import (
141+
from CTFd.utils.user import ( # noqa: I001
142142
get_user_attrs,
143143
get_user_place,
144144
get_user_score,

CTFd/models/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def get_place(self, admin=False, numeric=False):
501501
to no imports within the CTFd application as importing from the
502502
application itself will result in a circular import.
503503
"""
504-
from CTFd.utils.scores import get_user_standings
504+
from CTFd.utils.scores import get_user_standings # noqa: I001
505505
from CTFd.utils.humanize.numbers import ordinalize
506506

507507
standings = get_user_standings(admin=admin)
@@ -618,7 +618,7 @@ def get_fields(self, admin=False):
618618
]
619619

620620
def get_invite_code(self):
621-
from flask import current_app
621+
from flask import current_app # noqa: I001
622622
from CTFd.utils.security.signing import serialize, hmac
623623

624624
secret_key = current_app.config["SECRET_KEY"]
@@ -637,7 +637,7 @@ def get_invite_code(self):
637637

638638
@classmethod
639639
def load_invite_code(cls, code):
640-
from flask import current_app
640+
from flask import current_app # noqa: I001
641641
from CTFd.utils.security.signing import (
642642
unserialize,
643643
hmac,
@@ -736,7 +736,7 @@ def get_place(self, admin=False, numeric=False):
736736
to no imports within the CTFd application as importing from the
737737
application itself will result in a circular import.
738738
"""
739-
from CTFd.utils.scores import get_team_standings
739+
from CTFd.utils.scores import get_team_standings # noqa: I001
740740
from CTFd.utils.humanize.numbers import ordinalize
741741

742742
standings = get_team_standings(admin=admin)

CTFd/plugins/migrations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import inspect
1+
import inspect # noqa: I001
22
import os
33

44
from alembic.config import Config

CTFd/utils/initialization/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def init_template_filters(app):
5252

5353

5454
def init_template_globals(app):
55-
from CTFd.constants import JINJA_ENUMS
55+
from CTFd.constants import JINJA_ENUMS # noqa: I001
5656
from CTFd.constants.assets import Assets
5757
from CTFd.constants.config import Configs
5858
from CTFd.constants.plugins import Plugins

CTFd/utils/user/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import datetime
1+
import datetime # noqa: I001
22
import re
33

44
from flask import abort

CTFd/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import os # noqa: I001
22

33
from flask import Blueprint, abort
44
from flask import current_app as app

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
lint:
2-
flake8 --ignore=E402,E501,E712,W503,E203 --exclude=CTFd/uploads CTFd/ migrations/ tests/
2+
ruff check --select E,F,W,B,C4,I --ignore E402,E501,E712,B904,B905 --exclude=CTFd/uploads CTFd/ migrations/ tests/
33
yarn lint
44
black --check --diff --exclude=CTFd/uploads --exclude=node_modules .
55
prettier --check 'CTFd/themes/**/assets/**/*'

development.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pip-tools==5.4.0
33
pytest==5.4.2
44
pytest-randomly==3.4.0
55
coverage==5.1
6-
flake8==3.8.2
6+
ruff==0.0.260
77
psycopg2-binary==2.8.6
88
codecov==2.1.7
99
moto==1.3.16
@@ -14,10 +14,7 @@ pytest-cov==2.9.0
1414
sphinx_rtd_theme==0.4.3
1515
flask-debugtoolbar==0.11.0
1616
isort==4.3.21
17-
flake8-isort==3.0.0
1817
Faker==4.1.0
1918
pipdeptree==2.2.0
2019
black==19.10b0
2120
pytest-sugar==0.9.4
22-
flake8-comprehensions==3.3.1
23-
flake8-bugbear==20.11.1

migrations/env.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import with_statement
1+
from __future__ import with_statement # noqa: I001
22

33
import logging
44
from logging.config import fileConfig

migrations/versions/0366ba6575ca_add_table_for_comments.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2020-08-14 00:46:54.161120
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
import sqlalchemy as sa
1010

1111

migrations/versions/07dfbe5e1edc_add_format_to_pages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2021-06-15 19:57:37.410152
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
import sqlalchemy as sa
1010

1111

migrations/versions/46a278193a94_enable_millisecond_precision_in_mysql_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2022-11-01 23:27:44.620893
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
from sqlalchemy.dialects import mysql
1010

1111

migrations/versions/4d3c1b59d011_add_next_id_to_challenges_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2022-04-07 03:53:27.554190
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
import sqlalchemy as sa
1010

1111

migrations/versions/6012fe8de495_add_connection_info_column_to_challenges.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2021-07-30 03:50:54.219124
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
import sqlalchemy as sa
1010

1111

migrations/versions/75e8ab9a0014_add_fields_and_fieldentries_tables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2020-08-19 00:36:17.579497
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
import sqlalchemy as sa
1010

1111

migrations/versions/a03403986a32_add_theme_code_injections_to_configs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2020-02-13 01:10:16.430424
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
from sqlalchemy.sql import column, table
1010

1111
from CTFd.models import db

migrations/versions/ef87d69ec29a_add_topics_and_challenge_topics_tables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create Date: 2021-07-29 23:22:39.345426
66
77
"""
8-
from alembic import op
8+
from alembic import op # noqa: I001
99
import sqlalchemy as sa
1010

1111

tests/cache/test_challenges.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_deleting_challenge_clears_cache_solves():
6060
data = req.get_json()["data"]
6161
challenge = data[0]
6262
assert challenge["solves"] == 1
63-
from CTFd.utils.challenges import (
63+
from CTFd.utils.challenges import ( # noqa: I001
6464
get_solves_for_challenge_id,
6565
get_solve_counts_for_challenges,
6666
)
@@ -100,7 +100,7 @@ def test_deleting_solve_clears_cache():
100100
data = req.get_json()["data"]
101101
challenge = data[0]
102102
assert challenge["solves"] == 1
103-
from CTFd.utils.challenges import (
103+
from CTFd.utils.challenges import ( # noqa: I001
104104
get_solves_for_challenge_id,
105105
get_solve_counts_for_challenges,
106106
)

tests/constants/test_constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Numbers(str, RawEnum):
2424

2525

2626
def test_JSEnum():
27-
from CTFd.constants import JS_ENUMS
27+
from CTFd.constants import JS_ENUMS # noqa: I001
2828
import json
2929

3030
@JSEnum

0 commit comments

Comments
 (0)