In this document we will describe how to create a simple task, that checks that a code in Python returns “Hello World!”.
Creating the task description¶
Using the webapp¶
If you are using the webapp, this procedure can be done using the graphical interface:
- Go to the Course administration/Tasks page, enter
helloworldas a new task id and click on Create new task.
- In the Basic settings tab, set the task name to
Hello World!and put some context and author name. Container setup can be left with default parameters.
- In the Subproblems tab, add a new code-type problem with problem id
- Set some problem name and context, and set language to
- Save changes and go to Task files tab.
This is only possible if the administrator has given access to the course directory to the course administrator.
The task description is a YAML file describing everything that INGInious needs to know to verify the input of the student.
Here is a simple task description. Put this file with the name
task.yaml in a newly created
helloworld folder in
your course directory.
author: "The INGInious authors" accessible: true name: "Hello World!" context: "In this task, you will have to write a python script that displays 'Hello World!'." problems: question1: name: "Let's print it" header: "def func():" type: "code" language: "python" limits: time: 10 memory: 50 output: 1000 environment: default
Most of the fields are self-explanatory. Some remarks:
- The field
problemsis a dictionary of problems. Each problem must have an unique id, for example here
typefield that equals to
code, which means the student must enter some code to answer the question. Other types exists, such as multiple-choice.
- The field
limitsare the limits that the task cannot exceed. The
timeis in seconds, and
outputare in MB.
environmentfield is intended to change the environment where the tasks run. The available environments are those you downloaded during installation or those you created by creating a grading container. Please see Creating a new container image.
More documentation is available here: Creating a new task.
Creating the run file¶
In your task folder, you will put every file needed to test the input of the student. This folder content can be shown in the webapp in the Task files tab of the Edit task page.
Create a template file
template.py, where we will put the code of the student.
def func(): @ @question1@@ func()
The syntax is very simple: put a first
@on the line where you want to put the code of the student. Then indent the line and write a second
@. Now write the problem id of the problem you want to take the input from (
question1) then write another
@, write a possible suffix (not used here), and then finish the line with a last
runfile. This file will be the script that is launched when the task is started. Here we will create a bash script, that parses the template and verifies its content.
#! /bin/bash # This line parses the template and put the result in studentcode.py parsetemplate --output student/studentcode.py template.py # Verify the output of the code... output=$(run_student python student/studentcode.py) if [ "$output" = "Hello World!" ]; then # The student succeeded feedback-result success feedback-msg -m "You solved this difficult task!" else # The student failed feedback-result failed feedback-msg -m "Your output is $output" fi
Here we use three commands provided by INGInious,
feedback. The code is self-explanatory; just notice the usage of
run_studentthat ask INGInious (precisely the Docker agent) to start a new student container and run inside the command
Please note that the
run_studentcommand is fully configurable: you can change the environment on which you run the task, define new timeouts, memory limits, … See run_student for more details.
If not using the webapp, don’t forget to give the
runfile the execution rights:
$ chmod +x helloworld/run
More documentation is available here: Run file.