Skip to content
Open
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
14 changes: 14 additions & 0 deletions tests/worker/testWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def testLanguageOverride(self):
assert language == expectedLanguage
assert errors == None

def testVirtualenv(self):
'''Use a LANGUAGE file to override the detected language'''
VIRTUALENV_BOT_PATH = "virtualenvBot"

bot_dir = os.path.join(OUR_PATH, VIRTUALENV_BOT_PATH)

expectedLanguage = "Python"
language, errors = compiler.compile_anything(bot_dir)
if errors is not None: print("Errors: " + "\n".join(errors))
print("Language: " + language)

assert language == expectedLanguage
assert errors == None

class GameTests(unittest.TestCase):
def testNormalGame(self):
'''Test the parsing of the output of runGame.sh'''
Expand Down
4 changes: 4 additions & 0 deletions tests/worker/virtualenvBot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
bin/
include/
pip-selfcheck.json
1 change: 1 addition & 0 deletions tests/worker/virtualenvBot/MyBot.py
1 change: 1 addition & 0 deletions tests/worker/virtualenvBot/hlt.py
10 changes: 10 additions & 0 deletions tests/worker/virtualenvBot/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

virtualenv ./

source bin/activate
pip install numpy scipy scikit-learn pillow h5py
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
pip install keras
deactivate

1 change: 1 addition & 0 deletions tests/worker/virtualenvBot/networking.py
6 changes: 6 additions & 0 deletions tests/worker/virtualenvBot/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

source bin/activate
python3 MyBot.py
deactivate

4 changes: 4 additions & 0 deletions worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ RUN apt-get install -y ocaml
RUN sh -c 'echo "$(curl -fsSL https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein)" > /usr/bin/lein'
RUN chmod a+x /usr/bin/lein
RUN lein

RUN pip3 install virtualenv

RUN apt-get install -y git
53 changes: 30 additions & 23 deletions worker/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def _run_cmd(cmd, working_dir, timelimit):
try:
rawOut, rawErrors = process.communicate(timeout=timelimit)
outString = rawOut.decode("utf-8").strip()
print(outString)
out = outString.split("\n") if outString.isspace() == False and outString != "" else None

errorsString = rawErrors.decode("utf-8").strip()
Expand Down Expand Up @@ -509,8 +510,33 @@ def get_run_lang(submission_dir):
return line[1:-1]

def compile_anything(bot_dir, installTimeLimit=600, timelimit=600, max_error_len = 3072):
def limitErrors(errors):
# limit length of reported errors
if len(errors) > 0 and sum(map(len, errors)) > max_error_len:
first_errors = []
cur_error = 0
length = len(errors[0])
while length < (max_error_len / 3): # take 1/3 from start
first_errors.append(errors[cur_error])
cur_error += 1
length += len(errors[cur_error])
first_errors.append("...")
length += 3
end_errors = []
cur_error = -1
while length <= max_error_len:
end_errors.append(errors[cur_error])
cur_error -= 1
length += len(errors[cur_error])
end_errors.reverse()
errors = first_errors + end_errors
return errors

if os.path.exists(os.path.join(bot_dir, "install.sh")):
_, errors = _run_cmd("chmod +x install.sh; ./install.sh", bot_dir, installTimeLimit)
if errors is not None:
return "Unknown", limitErrors(errors)

detected_language, errors = detect_language(bot_dir)
print("detected language")
if detected_language:
Expand All @@ -524,8 +550,9 @@ def compile_anything(bot_dir, installTimeLimit=600, timelimit=600, max_error_len
print("filename:")
print(run_filename)
try:
with open(run_filename, 'wb') as f:
f.write(bytes('#%s\n%s\n' % (name, run_cmd), 'UTF-8'))
if os.path.isfile(run_filename) == False:
with open(run_filename, 'wb') as f:
f.write(bytes('#%s\n%s\n' % (name, run_cmd), 'UTF-8'))
print("file:")
with open(run_filename, 'r') as f:
for line in f:
Expand All @@ -540,27 +567,7 @@ def compile_anything(bot_dir, installTimeLimit=600, timelimit=600, max_error_len
name = override_name
return name, None
else:
# limit length of reported errors
if len(errors) > 0 and sum(map(len, errors)) > max_error_len:
first_errors = []
cur_error = 0
length = len(errors[0])
while length < (max_error_len / 3): # take 1/3 from start
first_errors.append(errors[cur_error])
cur_error += 1
length += len(errors[cur_error])
first_errors.append("...")
length += 3
end_errors = []
cur_error = -1
while length <= max_error_len:
end_errors.append(errors[cur_error])
cur_error -= 1
length += len(errors[cur_error])
end_errors.reverse()
errors = first_errors + end_errors

return detected_language.name, errors
return detected_language.name, limitErrors(errors)
else:
return "Unknown", errors

Expand Down
3 changes: 0 additions & 3 deletions worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ def executeCompileTask(user, backend):
shutil.move(os.path.join(bufferFolder, filename), os.path.join(workingPath, filename))
os.rmdir(bufferFolder)

# Rm symlinks
os.system("find "+workingPath+" -type l -delete")

language, errors = compile_anything(workingPath)
didCompile = True if errors == None else False
except Exception as e:
Expand Down