Skip to main content

A Docker Based Online Judge Engine

Project description

Piterator
Made by Piterator with <3

dockerjudge

Maintainability Python package Upload Python Package Transifex Build Status Azure DevOps tests Build Status CodeCov Documentation Status Python Version GitHub pre-release PyPI Wheel License FOSSA Status

🎌 🇺🇸 English | 🇨🇳 大陆简体

A LXC based online judge engine, which supports 10+ programming language processors:

Supported processors

Read the docs for more information.

Processor Language(s)* Required Docker image
Bash Shell bash
Clang
  • C (c)
  • C++ (cpp)
clangbuiltlinux/ubuntu
GCC
  • C (c)
  • C++ (cpp)
  • Go (go)
gcc
Go Go golang
Mono
  • Visual Basic (vb)
  • C# (csharp)
mono
Node Node.js node
OpenJDK Java openjdk
PHP PHP php
PyPy Python pypy
Python Python python
Ruby Ruby ruby
Swift Swift swift

* The language argumnets of the processors which support multiple languages should be provided, or the source will be judged in the default language (usually C++ or C#, emboldened in the table).

Installation

Read the docs for more information.

Docker

To run dockerjudge, Docker Engine is required.

Install using the convenience script (for servers)

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

See Install Docker Engine | Docker Documentation for more information.

Package

From the Python Package Index (PyPI)

dockerjudge · PyPI

Via pip
pip install dockerjudge
Via Easy install (deprecated)
easy_install dockerjudge

From GitHub

wxh06/dockerjudge: A Docker Based Online Judge Engine

  • HTTPS: https://github.com/wxh06/dockerjudge.git
  • SSH: git@github.com:wxh06/dockerjudge.git
git clone https://github.com/wxh06/dockerjudge.git
cd dockerjudge

make pip && make  # python3 -m pip install -Ur requirements.txt && python3 setup.py build
sudo make install  # python3 setup.py install

Usage

Read the docs for more information.

>>> from dockerjudge import judge
>>> from dockerjudge.processor import GCC, Clang, Bash, Python, Node, OpenJDK, PHP, Ruby, Mono, Swift
>>>
>>> judge(
...     GCC(GCC.Language.c),  # or `GCC('c')` / `GCC('C')`, which means compile the source code in the C programming language with `gcc` command
...     b'''
...         #include <stdio.h>
...         int main() {
...             int a, b;
...             scanf("%d %d", &a, &b);
...             printf("%d", a / b);
...             return 0;
...         }
...     ''',
...     [
...         (b'1 1', b'1'),  # AC
...         (b'1 2', b'0.5'),  # WA
...         (b'0 0', b'')  # RE
...     ]
... )
[
    [
        (<Status.AC: 'Accepted'>, (b'1', b''), 0.001),
        (<Status.WA: 'Wrong Answer'>, (b'0', b''), 0.001),
        (<Status.RE: 'Runtime Error'>, (None, b'Floating point exception (core dumped)\n'), 0.01)
    ],
    b''
]
>>>
>>> judge(GCC(GCC.Language.c), b'', [(b'', b'')])  # CE
[
    [
        (<Status.CE: 'Compilation Error'>, (None, None), 0.0)
    ],
    b"/usr/bin/ld: /usr/lib/x86_64-linux-gnu/crt1.o: in function `_start':\n(.text+0x20): undefined reference to `main'\ncollect2: error: ld returned 1 exit status\n"
]
>>>
>>> judge(
...     GCC(GCC.Language.cpp),  # or `GCC('cpp')` / `GCC('C++')`, which means compile the source code in the C++ programming language with `g++` command
...     b'''
...         #include <cstdio>
...         int main() {
...             printf("Hello, world!");
...             while (true)
...                 ;
...         }
...     ''',
...     [
...         (b'', b'Hello, world!')  # TLE
...     ],
...     {
...         'limit': {
...             'time': .1
...         }
...     }
... )
[
    [
        (<Status.TLE: 'Time Limit Exceeded'>, (None, b'bash: line 1:    35 Killed                  timeout -sKILL 0.1 sh -c ./a.out > /dockerjudge/1.out < /dockerjudge/1.in\n'), 0.100)
    ],
    b''
]
>>>
>>> judge(
...     GCC(
...         GCC.Language.c,
...         'latest',  # The GCC version number, such as `4`, `4.8`, etc.
...         {'bin': 'a'}  # The binary filename, which passes to `gcc`'s `-o` option
...     ),
...     b'''
...         #include <stdio.h>
...         int main() {
...             int a, b;
...             freopen("a.in", "r", stdin);  // Open `a.in` as stdin
...             scanf("%d %d", &a, &b);  // Scan from `a.in`
...             freopen("a.out", "w", stdout);  // Open `a.out` as stdout
...             printf("%d", a / b);  // Print to `a.out`
...             return 0;
...         }
...     ''',
...     [
...         (b'1 1', b'1'),  # AC
...         (b'1 2', b'0.5'),  # WA
...         (b'0 0', b'')  # RE
...     ],
...     {
...         'iofilename': {
...             'in': 'a.in',
...             'out': 'a.out'
...         }
...     }
... )
[
    [
        (<Status.AC: 'Accepted'>, (b'1', b''), 0.001),
        (<Status.WA: 'Wrong Answer'>, (b'0', b''), 0.001),
        (<Status.RE: 'Runtime Error'>, (None, b'Floating point exception (core dumped)\n'), 0.001)
    ],
    b''
]
>>>
>>> judge(
...     GCC(GCC.Language.c, filenames={'bin': 'a'}),
...     b'''
...         #include <stdio.h>
...         int main() {
...             int a, b;
...             scanf("%d %d", &a, &b);
...             printf("%d", a / b);
...             return 0;
...         }
...     ''',
...     [
...         (b'1 1', b'1'),
...         (b'0 0', b'')
...     ],
...     {
...         'iofilename': {
...             'out': 'a.out'  # ONF
...         }
...     }
... )
[
    [
        (<Status.ONF: 'Output Not Found'>, (None, b''), 0.001),
        (<Status.RE: 'Runtime Error'>, (None, b'Floating point exception (core dumped)\n'), 0.001)
    ],
    b''
]
>>>
>>> judge(  # BTW, GCC starting from 4.9 also supports Go, named `gccgo`
...     GCC(GCC.Language.go),
...     b'package main\n'
...     b''
...     b'import "fmt"\n'
...     b''
...     b'func main() {\n'
...     br'    fmt.Printf("hello, world\n")'b'\n'
...     b'}\n',
...     [(b'', b'hello, world')]
... )
[
    [
        (<Status.AC: 'Accepted'>, (b'hello, world\n', b''), 0.02)
    ],
    b''
]
>>>
>>> judge(
...     Clang(  # Besides GCC, LLVM Clang is also supported (The same arguments as GCC's)
...         Clang.Language.c,  # Only C and C++ supported
...         11  # The version number of LLVM CLang is **required**!
...     ),
...     b'',  # CE
...     [
...         (b'', b'')
...     ]
... )
[
    [
        (<Status.CE: 'Compilation Error'>, (None, None), 0.0)
    ],
    b"/usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crt1.o: in function `_start':\n'
    b"(.text+0x24): undefined reference to `main'\n"
    b'clang: error: linker command failed with exit code 1 (use -v to see invocation)\n'
]
>>>
>>> # Other programming languages are also supported
>>> judge(Bash(), b'echo Hello, world!', [(b'', b'Hello, world!')])  # Bash
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.001)
    ],
    b''
]
>>>
>>> judge(Python(3), b"print('Hello, world!')", [(b'', b'Hello, world!')])  # Python 3
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.05)
    ],
    b"Listing '.'...\n"
    b"Compiling './__init__.py'...\n"
]
>>> judge(PyPy(), b"print('Hello, world!')", [(b'', b'Hello, world!')])  # PyPy 3
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.075)
    ],
    b"Listing '.'...\n"
    b"Compiling './__init__.py'...\n"
]
>>>
>>> judge(Node(12), b'console.log("Hello World")', [(b'', b'Hello World')])  # Node.js
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello World\n', b''), 0.05)
    ],
    b''
]
>>>
>>> judge(  # Java / OpenJDK
...     OpenJDK(), #  The default public class name is `Main`
...     b'''
...         public class Main {
...             public static void main(String[] args) {
...                 System.out.println("Hello, world!");
...             }
...         }
...     ''',
...     [
...         (b'', b'Hello, world!')
...     ]
... )
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.1)
    ],
    b''
]
>>>
>>> judge(PHP(), b'<?php echo "Hello, world!";', [(b'', b'Hello, world!')])  # PHP
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello, world!', b''), 0.05)
    ],
    b'No syntax errors detected in index.php\n'
]
>>>
>>> judge(Ruby(), b'print "Hello, world!";', [(b'', b'Hello, world!')])  # Ruby
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello, world!', b''), 0.05)
    ],
    b'Syntax OK\n'
]
>>>
>>> judge(
...     Mono(Mono.Language.csharp),  # C# (Mono)
...     b'''
...         using System;
... 
...         public class HelloWorld
...         {
...             public static void Main(string[] args)
...             {
...                 Console.WriteLine ("Hello Mono World");
...             }
...         }
...     ''',
...     [
...         (b'', b'Hello Mono World')
...     ]
... )
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello Mono World\n', b''), 0.02)
    ],
    b'Microsoft (R) Visual C# Compiler version 3.5.0-beta1-19606-04 (d2bd58c6)\n'
    b'Copyright (C) Microsoft Corporation. All rights reserved.\n'
    b'\n'
]
>>> judge(
...     Mono(Mono.Language.vb),  # Visual Basic (Mono)
...     b'''
...         Imports System
... 
...         Module HelloWorld
...             Sub Main()
...                 Console.WriteLine("Hello World!")
...             End Sub
...         End Module
...     ''',
...     [
...         (b'', b'Hello World!')
...     ]
... )
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello World!\n', b''), 0.024)
    ],
    b'Visual Basic.Net Compiler version 0.0.0.5943 (Mono 4.7 - tarball)\n'
    b'Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.\n'
    b'\n'
    b"Assembly 'mono, Version=0.0, Culture=neutral, PublicKeyToken=null' saved successfully to '/dockerjudge/0/mono.exe'.\r\n"
    b'Compilation successful\r\n'
    b'Compilation took 00:00:00.0000000\n'
]
>>>
>>> judge(Swift(), b'print("Hello, world!")', [(b'', b'Hello, world!')])  # Swift
[
    [
        (<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.2)
    ],
    b''
]

License

Licensed under the Apache License, Version 2.0 Wide Apache Software Foundation Logo with Feather.svg

FOSSA Status

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dockerjudge-1.2.5.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dockerjudge-1.2.5-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file dockerjudge-1.2.5.tar.gz.

File metadata

  • Download URL: dockerjudge-1.2.5.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.1 CPython/3.8.5

File hashes

Hashes for dockerjudge-1.2.5.tar.gz
Algorithm Hash digest
SHA256 3427a7e9022b09507fe1c844e8c8918fcdca8ebb311322eb1aa24e0c2d0e54f5
MD5 ec41de71e144443a59a23c7094bd1548
BLAKE2b-256 be90612eb30cdac759cc93cbefb6930f02011f644518010fad33261ad43e2c60

See more details on using hashes here.

File details

Details for the file dockerjudge-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: dockerjudge-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.1 CPython/3.8.5

File hashes

Hashes for dockerjudge-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f6df55066fa2a46038c74b752d530a753c6676ae4537bc5fa27958c66b2d7bf0
MD5 b4b32e74b50aa338f4a907923143f7b2
BLAKE2b-256 5feae0c83c7a79ea54e659684f48bf8f89539cd9c6f39a755cb8507647e7cf77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page