Skip to content

Commit

Permalink
Fixing missing entry-point parameter for ref. solution submit.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Sep 30, 2023
1 parent 71a9e71 commit 88e0e47
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions recodex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def update_reference_solution_visibility(self, solution_id, visibility):
def delete_reference_solution_evaluation(self, evaluation_id):
self.delete('/reference-solutions/evaluation/{}'.format(evaluation_id))

def presubmit_check(self, exercise_id, files):
return self.post('/reference-solutions/exercise/{}/pre-submit'.format(exercise_id), data={"files": files})

def create_reference_solution(self, exercise_id, data):
return self.post('/reference-solutions/exercise/{}/submit'.format(exercise_id), data=data)

Expand Down
31 changes: 28 additions & 3 deletions recodex/plugins/exercises/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import sys
import io
import os
from datetime import datetime, timedelta

import click
Expand Down Expand Up @@ -157,15 +158,39 @@ def add_localization(api: ApiClient, locale, exercise_id, include_name):
@click.argument("files", nargs=-1)
@click.option("exercise_id", "-e")
@click.option("note", "-n", default="")
@click.option("runtime_environment", "-r", required=True)
@click.option("runtime_environment", "-r", default=None)
@pass_api_client
def add_reference_solution(api: ApiClient, exercise_id, note, runtime_environment, files):
if len(files) == 0:
print('No files given.', file=sys.stderr)
return

uploaded_files = [api.upload_file(file, open(file, "r"))["id"] for file in files]
result = api.create_reference_solution(exercise_id, {

preflight = api.presubmit_check(exercise_id, uploaded_files)
if (preflight["environments"] is None or len(preflight["environments"]) == 0):
print('No valid environments found for given files.', file=sys.stderr)
return

if runtime_environment is None:
runtime_environment = preflight["environments"][0]

if runtime_environment not in preflight["environments"]:
print('Selected runtime {} is not allowed by the preflight check.'.format(runtime_environment), file=sys.stderr)
return

submit_data = {
"note": note,
"runtimeEnvironmentId": runtime_environment,
"files": uploaded_files
})
}
variables = next((sv for sv in preflight['submitVariables'] if sv.get(
"runtimeEnvironmentId") == runtime_environment), {}).get('variables', [])
entry_point = next((v for v in variables if v.get('name') == 'entry-point'), None)
if entry_point is not None:
submit_data["solutionParams"] = {"variables": [{"name": "entry-point", "value": os.path.basename(files[0])}]}

result = api.create_reference_solution(exercise_id, submit_data)
click.echo(result["referenceSolution"]["id"])


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='recodex-cli',
version='0.0.20',
version='0.0.23',
description='ReCodEx CLI',
long_description='A command line frontend to the ReCodEx programmer evaluation system',
classifiers=[
Expand Down

0 comments on commit 88e0e47

Please sign in to comment.