Skip to content

Commit 69886aa

Browse files
some fixes
1 parent 04157b3 commit 69886aa

17 files changed

Lines changed: 126 additions & 104 deletions

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ name = "pypi"
77
boto3 = "1.42.71"
88
docker = "7.1.0"
99
psycopg2-binary = "2.9.11"
10+
boto3-stubs = {extras = ["s3"], version = "*"}
1011

1112
[dev-packages]
1213

Pipfile.lock

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from rcc import main
22

3-
4-
main()
3+
main()

src/rcc/__init__.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from __future__ import unicode_literals
22

3-
from six.moves import range
4-
53
import argparse
64
import logging
75
import logging.handlers
8-
import sys
96
import multiprocessing as mp
7+
import sys
8+
9+
from six.moves import range
10+
1011
import rcc.config
1112
import rcc.engine
1213
import rcc.provider
1314
import rcc.provider.data
14-
import rcc.provider.storage
1515
import rcc.util
1616

1717

@@ -26,14 +26,16 @@ def parse_args():
2626
return parser.parse_args()
2727

2828

29-
def setup_logger(name, log_config, slack_config=None):
29+
def setup_logger(name, log_config):
3030
# NOTE: should we handle multiprocessing?
3131
logger = logging.getLogger(name)
3232
logger.setLevel(logging.DEBUG)
3333

3434
# Console Logger
3535
console_handler = logging.StreamHandler(sys.stderr)
36-
console_fmt = logging.Formatter("[%(asctime)s] %(module)s:%(lineno)d: <%(process)d> %(message)s")
36+
console_fmt = logging.Formatter(
37+
"[%(asctime)s] %(module)s:%(lineno)d: <%(process)d> %(message)s"
38+
)
3739
console_handler.setFormatter(console_fmt)
3840
logger.addHandler(console_handler)
3941

@@ -47,22 +49,11 @@ def setup_logger(name, log_config, slack_config=None):
4749
handler.setLevel(log_config["level"])
4850
handler.setFormatter(formatter)
4951
logger.addHandler(handler)
50-
51-
# Slack Logger
52-
if slack_config is not None:
53-
fmt = "[%(asctime)s] %(module)s:%(lineno)d: <%(process)d> %(message)s"
54-
formatter = logging.Formatter(fmt)
55-
handler = rcc.util.SlackLogHandler(
56-
slack_config["webhook_url"], slack_config["sender_name"]
57-
)
58-
handler.setLevel(slack_config["level"])
59-
handler.setFormatter(formatter)
60-
logger.addHandler(handler)
6152

6253
return logger
6354

6455

65-
def commit_filter(commit):
56+
def commit_filter(_):
6657
return True
6758

6859

@@ -73,7 +64,7 @@ def main():
7364
else:
7465
cfg = rcc.config.from_json(rcc.config.DEFAULT_CONFIG, args.config)
7566

76-
logger = setup_logger(rcc.config.DEFAULT_LOGGER, cfg.log, cfg.slack)
67+
logger = setup_logger(rcc.config.DEFAULT_LOGGER, cfg.log)
7768

7869
with rcc.util.SingletonContext(cfg.lock_file):
7970
logger.info("Started")
@@ -89,7 +80,7 @@ def main():
8980
mp.Process(
9081
target=rcc.engine.process_commits, args=(data_provider, task_queue)
9182
)
92-
for i in range(cfg.num_workers)
83+
for _ in range(cfg.num_workers)
9384
]
9485

9586
# Poll for new commits and put them in our internal processing queue
@@ -111,7 +102,7 @@ def main():
111102
task_queue.join()
112103
sleeper.reset()
113104
sleeper.sleep()
114-
except KeyboardInterrupt as e:
105+
except KeyboardInterrupt:
115106
logger.info("Interrupted; waiting for workers")
116107
try:
117108
for worker in engine_workers:
@@ -122,7 +113,7 @@ def main():
122113
# Join each worker to ensure all of them are done
123114
for worker in engine_workers:
124115
worker.join()
125-
except KeyboardInterrupt as e:
116+
except KeyboardInterrupt:
126117
# Give up and terminate everything
127118
logger.info("Aborted")
128119
for worker in engine_workers:

src/rcc/cmp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def text_cmp(file1, file2):
1515
return text_cmp(file1, f2)
1616
try:
1717
for line1, line2 in zip_longest(file1, file2):
18-
if line1 == None or line2 == None:
18+
if line1 is None or line2 is None:
1919
return False
2020
if line1.rstrip() != line2.rstrip():
2121
return False
@@ -35,15 +35,15 @@ def text_cmp2(file1, file2):
3535
while True:
3636
line1 = next(file1, None)
3737
line2 = next(file2, None)
38-
if line1 == None or line2 == None:
38+
if line1 is None or line2 is None:
3939
break
4040
while line1.strip() == "":
4141
line1 = next(file1, None)
42-
if line1 == None:
42+
if line1 is None:
4343
return False
4444
while line2.strip() == "":
4545
line2 = next(file2, None)
46-
if line2 == None:
46+
if line2 is None:
4747
return False
4848
if line1 != line2:
4949
tokens1 = line1.lower().split()
@@ -75,7 +75,7 @@ def is_float(s):
7575
raise ValueError("Error must be positive")
7676
try:
7777
for line1, line2 in zip_longest(file1, file2):
78-
if line1 == None or line2 == None:
78+
if line1 is None or line2 is None:
7979
return False
8080
tokens1 = line1.split()
8181
tokens2 = line2.split()

src/rcc/engine.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
from __future__ import division, print_function, unicode_literals
22

33
import asyncio
4-
import asyncio.subprocess
54
import configparser
6-
import contextlib
75
import datetime
86
import filecmp
97
import itertools as it
108
import logging
11-
import multiprocessing as mp
129
import os
1310
import shutil
1411
import zipfile
@@ -23,8 +20,6 @@
2320
import rcc.util
2421
from rcc.model import Commit, TestCase, TestCaseResult
2522

26-
from .languages import language_from_extension
27-
2823
DEFAULT_MKDIR_PERMISSIONS = 0o777
2924

3025

@@ -302,11 +297,11 @@ def is_correct(test_result):
302297
def cleanup_tests(base_dir):
303298
if os.path.isdir(base_dir):
304299

305-
def rmtree_handler(func, path, exc_info):
300+
def rmtree_handler(_func, _path, exc_info):
306301
exc_type, exc_value, _ = exc_info
307302
raise exc_type(exc_value)
308303

309-
shutil.rmtree(base_dir, onerror=rmtree_handler)
304+
shutil.rmtree(base_dir, onexc=rmtree_handler)
310305

311306

312307
def process_commit(data_provider, commit):
@@ -321,22 +316,22 @@ def process_commit(data_provider, commit):
321316

322317
try:
323318
storage_provider = rcc.provider.storage.from_config(cfg)
324-
except:
319+
except Exception:
325320
logger.error("[{c.id}] Storage provider error".format(c=commit), exc_info=True)
326321
commit.status = Commit.STATUS_INTERNAL_ERROR
327322
data_provider.update_commit(commit)
328323
return
329324

330325
try:
331326
test_cases = data_provider.fetch_test_cases(commit)
332-
except:
327+
except Exception:
333328
logger.error(
334329
"[{c.id}] Failed to fetch test cases".format(c=commit), exc_info=True
335330
)
336331
commit.status = Commit.STATUS_INTERNAL_ERROR
337332
data_provider.update_commit(commit)
338333
if cfg.cleanup_on_error:
339-
cleanup_tests(base_dir)
334+
cleanup_tests(os.path.join(cfg.exec_dir, "commit_{}".format(commit.id)))
340335
return
341336

342337
# Delete results already produced by this commit, if any
@@ -355,7 +350,7 @@ def process_commit(data_provider, commit):
355350
create_container_cfg_file(commit, test_cases, base_dir)
356351
copy_source_files(data_provider, storage_provider, commit, base_dir)
357352
copy_test_case_files(storage_provider, test_cases, base_dir)
358-
except:
353+
except Exception:
359354
logger.error("[{c.id}] Failed to prepare runs".format(c=commit), exc_info=True)
360355
commit.status = Commit.STATUS_INTERNAL_ERROR
361356
data_provider.update_commit(commit)
@@ -368,7 +363,7 @@ def process_commit(data_provider, commit):
368363
test_results = run_tests(
369364
data_provider, storage_provider, commit, test_cases, base_dir, remote_dir
370365
)
371-
except:
366+
except Exception:
372367
logger.error("[{c.id}] Failed to run tests".format(c=commit), exc_info=True)
373368
commit.status = Commit.STATUS_INTERNAL_ERROR
374369
data_provider.update_commit(commit)
@@ -386,7 +381,7 @@ def process_commit(data_provider, commit):
386381
output_fname = prepare_output_file(commit, base_dir)
387382
storage_provider.store_commit_output(commit, output_fname)
388383
cleanup_tests(base_dir)
389-
except:
384+
except Exception:
390385
logger.error(
391386
"[{c.id}] Could not save results, commit data might be inconsistent".format(
392387
c=commit

src/rcc/model/commit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22

3+
34
class Commit:
45
STATUS_IN_QUEUE = 0
56
STATUS_COMPILING = 1

src/rcc/provider/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/rcc/provider/data/data_provider.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ class DataProvider(object):
22
def fetch_commits_in_queue(self):
33
raise NotImplementedError()
44

5-
def update_commit(self, commit):
5+
def update_commit(self, _commit):
66
raise NotImplementedError()
77

8-
def store_commit_test_results(self, commit, test_results):
8+
def store_commit_test_results(self, _commit, _test_results):
99
raise NotImplementedError()
1010

11-
def delete_commit_test_results(self, commit):
11+
def delete_commit_test_results(self, _commit):
1212
raise NotImplementedError()
1313

14-
def fetch_exercise_files(self, commit):
14+
def fetch_exercise_files(self, _commit):
1515
raise NotImplementedError()
1616

17-
def fetch_test_cases(self, commit):
17+
def fetch_test_cases(self, _commit):
1818
raise NotImplementedError()

0 commit comments

Comments
 (0)