Skip to content

Commit bf6c189

Browse files
authored
fixes from Ruff (#549)
1 parent bd69144 commit bf6c189

File tree

643 files changed

+20418
-26031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

643 files changed

+20418
-26031
lines changed

conftest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99

1010
def pytest_addoption(parser):
11-
parser.addoption(
12-
'--runslow', action='store_true', default=False, help="run slow tests"
13-
)
14-
parser.addoption(
15-
'--strict-template-vars', action='store_true', help="Raise errors for undefined template variables")
11+
parser.addoption("--runslow", action="store_true", default=False, help="run slow tests")
12+
parser.addoption("--strict-template-vars", action="store_true", help="Raise errors for undefined template variables")
1613

1714

1815
# called for running each test
@@ -24,12 +21,12 @@ def pytest_runtest_setup(item):
2421
def pytest_configure(config):
2522
if config.getoption("--strict-template-vars"):
2623
# this will raise an error if a template variable is not defined
27-
settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] = '{% templatetag openvariable %} INVALID_VAR: %s {% templatetag closevariable %}'
28-
24+
settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"] = "{% templatetag openvariable %} INVALID_VAR: %s {% templatetag closevariable %}"
25+
2926

3027
def pytest_collection_modifyitems(config, items):
3128
# --runslow flag: do not skip slow tests
32-
if config.getoption('--runslow', False):
29+
if config.getoption("--runslow", False):
3330
return
3431
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
3532
for item in items:
@@ -48,6 +45,7 @@ def pytest_html_results_table_header(cells):
4845
def pytest_html_results_table_row(report, cells):
4946
cells.pop()
5047

48+
5149
@pytest.fixture()
5250
def require_migrations_flag(request):
5351
config = request.config

easy_toolbox.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,40 @@
1919
import sys
2020
from shlex import quote
2121

22-
BASE_DOCKER_COMMAND = "OIOIOI_UID=$(id -u) docker compose" + \
23-
" -f docker-compose-dev.yml"
22+
BASE_DOCKER_COMMAND = "OIOIOI_UID=$(id -u) docker compose" + " -f docker-compose-dev.yml"
2423

2524
RAW_COMMANDS = [
2625
("build", "Build OIOIOI container from source.", "build", True),
2726
("up", "Run all SIO2 containers", "up -d"),
2827
("down", "Stop and remove all SIO2 containers", "down"),
2928
("wipe", "Stop all SIO2 containers and DESTROY all data", "down -v", True),
30-
("run", "Run django server and webpack",
31-
'{exec} web conc -n js,py -c yellow,green -k "npm --prefix ../oioioi run -s watch" "python3 manage.py runserver 0.0.0.0:8000"'),
29+
(
30+
"run",
31+
"Run django server and webpack",
32+
'{exec} web conc -n js,py -c yellow,green -k "npm --prefix ../oioioi run -s watch" "python3 manage.py runserver 0.0.0.0:8000"',
33+
),
3234
("stop", "Stop all SIO2 containers", "stop"),
3335
("bash", "Open command prompt on web container.", "{exec} web bash"),
3436
("exec", "Run a command in the web container.", "{exec} web {extra_args}"),
3537
("bash-db", "Open command prompt on database container.", "{exec} db bash"),
3638
# This one CLEARS the database. Use wisely.
3739
("flush-db", "Clear database.", "{exec} web python manage.py flush --noinput", True),
38-
("add-superuser", "Create admin_admin.",
39-
"{exec} web python manage.py loaddata ../oioioi/oioioi_cypress/cypress/fixtures/admin_admin.json"),
40+
("add-superuser", "Create admin_admin.", "{exec} web python manage.py loaddata ../oioioi/oioioi_cypress/cypress/fixtures/admin_admin.json"),
4041
("test", "Run unit tests.", "{exec} web ../oioioi/test.sh {extra_args}"),
4142
("test-slow", "Run unit tests. (--runslow)", "{exec} web ../oioioi/test.sh --runslow {extra_args}"),
42-
("test-coverage", "Run coverage tests.",
43-
"{exec} 'web' ../oioioi/test.sh oioioi/problems --cov-report term --cov-report xml:coverage.xml --cov=oioioi {extra_args}"),
44-
("cypress-apply-settings", "Apply settings for CyPress.",
45-
'{exec} web bash -c "echo CAPTCHA_TEST_MODE=True >> settings.py"'),
43+
(
44+
"test-coverage",
45+
"Run coverage tests.",
46+
"{exec} 'web' ../oioioi/test.sh oioioi/problems --cov-report term --cov-report xml:coverage.xml --cov=oioioi {extra_args}",
47+
),
48+
("cypress-apply-settings", "Apply settings for CyPress.", '{exec} web bash -c "echo CAPTCHA_TEST_MODE=True >> settings.py"'),
4649
("npm", "Run npm command.", "{exec} web npm --prefix ../oioioi {extra_args}"),
4750
("eslint", "Run javascript linter.", "{exec} web npm --prefix ../oioioi run lint"),
48-
("ruff", "Run Ruff, a linter and formatter. You can add `--fix` to automatically fix some errors.","{exec} -w /sio2/oioioi web bash -c 'ruff check . {extra_args} ; echo ; ruff format .'",
49-
)
51+
(
52+
"ruff",
53+
"Run Ruff, a linter and formatter. You can add `--fix` to automatically fix some errors.",
54+
"{exec} -w /sio2/oioioi web bash -c 'ruff check . {extra_args} ; echo ; ruff format .'",
55+
),
5056
]
5157

5258
longest_command_arg = max([len(command[0]) for command in RAW_COMMANDS])
@@ -117,6 +123,7 @@ def get_action_from_args() -> Option:
117123

118124
def get_action_from_gui() -> Option:
119125
import inquirer
126+
120127
questions = [
121128
inquirer.List(
122129
"action",
@@ -160,10 +167,14 @@ def run() -> None:
160167

161168
def print_help() -> None:
162169
print(
163-
"OIOIOI helper toolbox", "", "This script allows to control OIOIOI with Docker commands.",
170+
"OIOIOI helper toolbox",
171+
"",
172+
"This script allows to control OIOIOI with Docker commands.",
164173
f"Commands are always being run with '{BASE_DOCKER_COMMAND}' prefix.",
165-
"Available commands are: ", "",
166-
*COMMANDS.values(), "",
174+
"Available commands are: ",
175+
"",
176+
*COMMANDS.values(),
177+
"",
167178
"Example `build`:",
168179
f"{sys.argv[0]} build",
169180
sep="\n",

extra/sample-configs/runnable-test-settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
COMPRESS_ENABLED = True
88
COMPRESS_PRECOMPILERS = oioioi.default_settings.COMPRESS_PRECOMPILERS
99
FILETRACKER_CLIENT_FACTORY = oioioi.default_settings.FILETRACKER_CLIENT_FACTORY
10-
FILETRACKER_CACHE_ROOT = '/tmp/oioioi-filetracker-cache'
11-
STATIC_ROOT = '/tmp/oioioi-static-root'
10+
FILETRACKER_CACHE_ROOT = "/tmp/oioioi-filetracker-cache"
11+
STATIC_ROOT = "/tmp/oioioi-static-root"
1212

1313
DATABASES = {
14-
'default': {
15-
'NAME': '/tmp/oioioi.sqlite3',
16-
'ENGINE': 'django.db.backends.sqlite3',
17-
'ATOMIC_REQUESTS': True,
14+
"default": {
15+
"NAME": "/tmp/oioioi.sqlite3",
16+
"ENGINE": "django.db.backends.sqlite3",
17+
"ATOMIC_REQUESTS": True,
1818
}
1919
}
2020

ez_setup.py

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
This file can also be run as a script to install or upgrade setuptools.
1515
"""
16+
1617
from __future__ import print_function
1718

1819
import os
@@ -27,48 +28,48 @@
2728
DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]
2829

2930
md5_data = {
30-
'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
31-
'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
32-
'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b',
33-
'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a',
34-
'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618',
35-
'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac',
36-
'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5',
37-
'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4',
38-
'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c',
39-
'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b',
40-
'setuptools-0.6c10-py2.3.egg': 'ce1e2ab5d3a0256456d9fc13800a7090',
41-
'setuptools-0.6c10-py2.4.egg': '57d6d9d6e9b80772c59a53a8433a5dd4',
42-
'setuptools-0.6c10-py2.5.egg': 'de46ac8b1c97c895572e5e8596aeb8c7',
43-
'setuptools-0.6c10-py2.6.egg': '58ea40aef06da02ce641495523a0b7f5',
44-
'setuptools-0.6c11-py2.3.egg': '2baeac6e13d414a9d28e7ba5b5a596de',
45-
'setuptools-0.6c11-py2.4.egg': 'bd639f9b0eac4c42497034dec2ec0c2b',
46-
'setuptools-0.6c11-py2.5.egg': '64c94f3bf7a72a13ec83e0b24f2749b2',
47-
'setuptools-0.6c11-py2.6.egg': 'bfa92100bd772d5a213eedd356d64086',
48-
'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27',
49-
'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277',
50-
'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa',
51-
'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e',
52-
'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e',
53-
'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f',
54-
'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2',
55-
'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc',
56-
'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167',
57-
'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64',
58-
'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d',
59-
'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20',
60-
'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab',
61-
'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53',
62-
'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2',
63-
'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e',
64-
'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372',
65-
'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902',
66-
'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de',
67-
'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b',
68-
'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03',
69-
'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a',
70-
'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6',
71-
'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a',
31+
"setuptools-0.6b1-py2.3.egg": "8822caf901250d848b996b7f25c6e6ca",
32+
"setuptools-0.6b1-py2.4.egg": "b79a8a403e4502fbb85ee3f1941735cb",
33+
"setuptools-0.6b2-py2.3.egg": "5657759d8a6d8fc44070a9d07272d99b",
34+
"setuptools-0.6b2-py2.4.egg": "4996a8d169d2be661fa32a6e52e4f82a",
35+
"setuptools-0.6b3-py2.3.egg": "bb31c0fc7399a63579975cad9f5a0618",
36+
"setuptools-0.6b3-py2.4.egg": "38a8c6b3d6ecd22247f179f7da669fac",
37+
"setuptools-0.6b4-py2.3.egg": "62045a24ed4e1ebc77fe039aa4e6f7e5",
38+
"setuptools-0.6b4-py2.4.egg": "4cb2a185d228dacffb2d17f103b3b1c4",
39+
"setuptools-0.6c1-py2.3.egg": "b3f2b5539d65cb7f74ad79127f1a908c",
40+
"setuptools-0.6c1-py2.4.egg": "b45adeda0667d2d2ffe14009364f2a4b",
41+
"setuptools-0.6c10-py2.3.egg": "ce1e2ab5d3a0256456d9fc13800a7090",
42+
"setuptools-0.6c10-py2.4.egg": "57d6d9d6e9b80772c59a53a8433a5dd4",
43+
"setuptools-0.6c10-py2.5.egg": "de46ac8b1c97c895572e5e8596aeb8c7",
44+
"setuptools-0.6c10-py2.6.egg": "58ea40aef06da02ce641495523a0b7f5",
45+
"setuptools-0.6c11-py2.3.egg": "2baeac6e13d414a9d28e7ba5b5a596de",
46+
"setuptools-0.6c11-py2.4.egg": "bd639f9b0eac4c42497034dec2ec0c2b",
47+
"setuptools-0.6c11-py2.5.egg": "64c94f3bf7a72a13ec83e0b24f2749b2",
48+
"setuptools-0.6c11-py2.6.egg": "bfa92100bd772d5a213eedd356d64086",
49+
"setuptools-0.6c2-py2.3.egg": "f0064bf6aa2b7d0f3ba0b43f20817c27",
50+
"setuptools-0.6c2-py2.4.egg": "616192eec35f47e8ea16cd6a122b7277",
51+
"setuptools-0.6c3-py2.3.egg": "f181fa125dfe85a259c9cd6f1d7b78fa",
52+
"setuptools-0.6c3-py2.4.egg": "e0ed74682c998bfb73bf803a50e7b71e",
53+
"setuptools-0.6c3-py2.5.egg": "abef16fdd61955514841c7c6bd98965e",
54+
"setuptools-0.6c4-py2.3.egg": "b0b9131acab32022bfac7f44c5d7971f",
55+
"setuptools-0.6c4-py2.4.egg": "2a1f9656d4fbf3c97bf946c0a124e6e2",
56+
"setuptools-0.6c4-py2.5.egg": "8f5a052e32cdb9c72bcf4b5526f28afc",
57+
"setuptools-0.6c5-py2.3.egg": "ee9fd80965da04f2f3e6b3576e9d8167",
58+
"setuptools-0.6c5-py2.4.egg": "afe2adf1c01701ee841761f5bcd8aa64",
59+
"setuptools-0.6c5-py2.5.egg": "a8d3f61494ccaa8714dfed37bccd3d5d",
60+
"setuptools-0.6c6-py2.3.egg": "35686b78116a668847237b69d549ec20",
61+
"setuptools-0.6c6-py2.4.egg": "3c56af57be3225019260a644430065ab",
62+
"setuptools-0.6c6-py2.5.egg": "b2f8a7520709a5b34f80946de5f02f53",
63+
"setuptools-0.6c7-py2.3.egg": "209fdf9adc3a615e5115b725658e13e2",
64+
"setuptools-0.6c7-py2.4.egg": "5a8f954807d46a0fb67cf1f26c55a82e",
65+
"setuptools-0.6c7-py2.5.egg": "45d2ad28f9750e7434111fde831e8372",
66+
"setuptools-0.6c8-py2.3.egg": "50759d29b349db8cfd807ba8303f1902",
67+
"setuptools-0.6c8-py2.4.egg": "cba38d74f7d483c06e9daa6070cce6de",
68+
"setuptools-0.6c8-py2.5.egg": "1721747ee329dc150590a58b3e1ac95b",
69+
"setuptools-0.6c9-py2.3.egg": "a83c4020414807b496e4cfbe08507c03",
70+
"setuptools-0.6c9-py2.4.egg": "260a2be2e5388d66bdaee06abec6342a",
71+
"setuptools-0.6c9-py2.5.egg": "fe67c3e5a17b12c0e7c541b7ea43a8e6",
72+
"setuptools-0.6c9-py2.6.egg": "ca37b1ff16fa2ede6e19383e7b59245a",
7273
}
7374

7475

@@ -77,10 +78,7 @@ def _validate_md5(egg_name, data):
7778
digest = md5(data).hexdigest()
7879
if digest != md5_data[egg_name]:
7980
print(
80-
(
81-
"md5 validation of %s failed! (Possible download problem?)"
82-
% egg_name
83-
),
81+
("md5 validation of %s failed! (Possible download problem?)" % egg_name),
8482
file=sys.stderr,
8583
)
8684
sys.exit(2)
@@ -104,7 +102,7 @@ def use_setuptools(
104102
this routine will print a message to ``sys.stderr`` and raise SystemExit in
105103
an attempt to abort the calling script.
106104
"""
107-
was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
105+
was_imported = "pkg_resources" in sys.modules or "setuptools" in sys.modules
108106

109107
def do_download():
110108
egg = download_setuptools(version, download_base, to_dir, download_delay)
@@ -136,13 +134,11 @@ def do_download():
136134
except pkg_resources.DistributionNotFound:
137135
pass
138136

139-
del pkg_resources, sys.modules['pkg_resources'] # reload ok
137+
del pkg_resources, sys.modules["pkg_resources"] # reload ok
140138
return do_download()
141139

142140

143-
def download_setuptools(
144-
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay=15
145-
):
141+
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay=15):
146142
"""Download setuptools from a specified location and return its filename
147143
148144
`version` should be a valid setuptools version number that is available
@@ -215,12 +211,9 @@ def main(argv, version=DEFAULT_VERSION):
215211
if egg and os.path.exists(egg):
216212
os.unlink(egg)
217213
else:
218-
if setuptools.__version__ == '0.0.1':
214+
if setuptools.__version__ == "0.0.1":
219215
print(
220-
(
221-
"You have an obsolete version of setuptools installed. Please\n"
222-
"remove it from your system entirely before rerunning this script."
223-
),
216+
("You have an obsolete version of setuptools installed. Please\nremove it from your system entirely before rerunning this script."),
224217
file=sys.stderr,
225218
)
226219
sys.exit(2)
@@ -254,7 +247,7 @@ def update_md5(filenames):
254247

255248
for name in filenames:
256249
base = os.path.basename(name)
257-
f = open(name, 'rb')
250+
f = open(name, "rb")
258251
md5_data[base] = md5(f.read()).hexdigest()
259252
f.close()
260253

@@ -265,7 +258,7 @@ def update_md5(filenames):
265258
import inspect
266259

267260
srcfile = inspect.getsourcefile(sys.modules[__name__])
268-
f = open(srcfile, 'rb')
261+
f = open(srcfile, "rb")
269262
src = f.read()
270263
f.close()
271264

@@ -275,13 +268,13 @@ def update_md5(filenames):
275268
sys.exit(2)
276269

277270
src = src[: match.start(1)] + repl + src[match.end(1) :]
278-
f = open(srcfile, 'w')
271+
f = open(srcfile, "w")
279272
f.write(src)
280273
f.close()
281274

282275

283-
if __name__ == '__main__':
284-
if len(sys.argv) > 2 and sys.argv[1] == '--md5update':
276+
if __name__ == "__main__":
277+
if len(sys.argv) > 2 and sys.argv[1] == "--md5update":
285278
update_md5(sys.argv[2:])
286279
else:
287280
main(sys.argv[1:])

oioioi/_locale/apps.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33

44
class LocaleConfig(AppConfig):
5-
default_auto_field = 'django.db.models.AutoField'
6-
name = 'oioioi._locale'
7-
5+
default_auto_field = "django.db.models.AutoField"
6+
name = "oioioi._locale"

oioioi/acm/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class AcmAppConfig(AppConfig):
5-
default_auto_field = 'django.db.models.AutoField'
5+
default_auto_field = "django.db.models.AutoField"
66
name = "oioioi.acm"

0 commit comments

Comments
 (0)