CONTESTER.Driver - is a Docker-based system that runs students' code written on different programming languages.
- Python (Python 3.8)
- PyPy (7.3.12)
- C++ (GCC Latest)
- PascalABC (Free Pascal 3.2.2)
Every time user wants to execute some code Driver creates appropriate file and Docker container.
Then, depending on programming language type (compiled of interpreted) it executes all necessary commands.
In order to create a file context manager FileCreator is invoked. Based on programming language type it will
create file with unique name and proper extension. Note that after a file is no more needed it is deleted automatically.
As for Docker containers, once again, depending on programming language type Driver will create Container.
Container is a class inherited either from CompiledContainer or InterpretedContainer.
It implements only those methods, that do something very language specific, for example return compilation or execution command.
Now, let's take a look at how Driver deals with source file with C++ code :
- First of all, source code has to be compiled. To do this,
Driverwill run the following command:g++ user-scripts-dir/source-file.cpp -o compiled-files-dir/sourse-file-compiled
- As a result, there is sourse-file-compiled in a compiled-files-dir. Now, compiled file can be executed:
sh -c 'echo -e "7 8" | time -f "%e" -o time-stdout-file timeout 2 compiled-files-dir/sourse-file-compiled && cat time-stdout-file'
Here are some explanations of this long command:
7 8is input of the program.time -f "%e" -o time-stdout-filesaves execution time in time-stdout-filetimeout 2 compiled-files-dir/sourse-file-compiledensures that the program is limited to 2 seconds&& cat time-stdout-file: If no error has occurred, execution time goes to the last line of stdout
After execution of this command, Driver will receive ExecResult with raw exit code, stdout and stderr.
Then it will thoroughly process this result and return uniform ProcessedContainerExecutionResult object.
Examples:
ProcessedContainerExecutionResult(exit_code=0, output='1\n2\n3', execution_time=0.06, error_message='') ProcessedContainerExecutionResult( exit_code=1, output="""File "user-scripts-dir/62b16cbd-b2b7-44cb-8d35-7c4cf1ddd517.py", line 1 print( ^ SyntaxError: '(' was never closed Command exited with non-zero status 1""", execution_time=0, error_message='Run-Time Error' )
More details about all those mechanisms can be found in the source code.
β The vast majority of methods are documented.
Important
If you don't have Poetry installed, please follow this official guide
- Clone this project:
git clone https://github.com/CONTESTER-reborn/driver.git
- Create venv and install dependencies:
poetry config virtualenvs.in-project true poetry env use path/to/your/python.exe poetry install - Run
entrypoint.py(this step will be adjusted later)
If you want to add new feature or suggest better solution for some aspect of this application, you can always create a new Pull Request. In order to get a bug you noticed fixed create a GitHub Issue, and we will discuss possible solutions.
If you liked this repository, give it a π !
Ankudinov Kirill - kirill.ankudinov.94@mail.ru
My social medias: