#cli #test #samples #kattis #submit

app kattis

Manage Kattis submissions, samples and templates from the terminal

4 releases

✓ Uses Rust 2018 edition

0.2.2 Nov 21, 2019
0.2.1 Oct 17, 2019
0.2.0 Oct 17, 2019
0.1.0 Oct 15, 2019

#269 in Command line utilities

Download history 17/week @ 2019-11-27 8/week @ 2019-12-04 17/week @ 2019-12-11 5/week @ 2019-12-25 7/week @ 2020-01-01 45/week @ 2020-01-08 5/week @ 2020-01-15 1/week @ 2020-01-29 5/week @ 2020-02-12 16/week @ 2020-02-19 9/week @ 2020-02-26 8/week @ 2020-03-04 5/week @ 2020-03-11

52 downloads per month

MIT/Apache

66KB
1.5K SLoC

Kattis Client

Warning: This is an unofficial client and may break without notice. If it does, please leave an issue.

Features

  • Minimize typing by using code templates.
  • Automatically download problem samples and test your solution against them.
  • Submit and get updates on your solutions without leaving the terminal.

Installation

Using Cargo

This tool can easily be installed using Cargo, the Rust package manager.

cargo install kattis

It is normal for installation to take a minute. Meanwhile, you can prepare your configuration.

Example Usage

To illustrate how this tool may be used, we are going to solve the problem Aaah. You can find the configuration and files used in this example in the examples directory.

If you don't already have one, you have to create a new template. A template is basically a folder containing a barebones solution with all boilerplate code already typed out. Find out more here.

Our first order of business is to find the problem's id: aaah. This will be used by the client to download all the problem's samples and setup a new test environment:

kattis new --problem aaah --template rust

By default this command creates a new directory called aaah in which we will find our template (in this case the template called rust).

At this point we would write our solution, and when we believe we have a working solution we can test our hypothesis by running:

cd aaah
kattis test

This will run the build commands specified in the kattis.yml followed by the run commands, once for every sample. If our solution was correct we should see the following output:

Running test case: aaah.1
Correct
Running test case: aaah.2
Correct

If our solution was wrong we would instead see something like (actual output is colorized for readability):

Running test case: aaah.1
Correct
Running test case: aaah.2
Wrong Answer

Input:
aaah
ah

Found:
uh oh

Expected:
go

Testing your code before submitting will not only make debugging easier, but will also reduce the possibility of you getting a test case wrong. This is especially important in a competition where a wrong answer includes a penalty.

When you are confident that your solution is correct you can easily submit your solution by running:

kattis submit

It will prompt you with a short summary of what will be submitted along with a confirmation prompt. If you answer y your submission will be sent and you should see the status of your submission get periodically updated:

Language: Rust
Files:
  - ./main.rs
Main Class:
Proceed with the submission? (y/N) y
Submission ID: 4253057
Compiling...
Running...
Test Case 1/52: Accepted
Test Case 2/52: Accepted
Test Case 3/52: Accepted
Test Case 4/52: Accepted
...
Test Case 42/52: Accepted
...
Test Case 49/52: Accepted
Test Case 50/52: Accepted
Test Case 51/52: Accepted
Test Case 52/52: Accepted

Submission Status: Accepted
Time: 17:47:24
CPU: 0.00 s

As you would expect, if something has gone terribly wrong you will find out ASAP:

Language: Rust
Files:
  - ./main.rs
Main Class:
Proceed with the submission? (y/N) y
Submission ID: 4253066
Compiling...
Compiling...
Test Case 1/52: Accepted
Test Case 2/52: Accepted
Test Case 3/52: Accepted
Test Case 4/52: Accepted
Test Case 5/52: Wrong Answer

Submission Status: Wrong Answer
Time: 17:53:36
CPU: 0.00 s

Configuration

By default kattis will search for your configuration files in your user's configuration directory:

Operating System Directory Example
Linux $XDG_CONFIG_HOME/kattis or $HOME/.config/kattis /home/alice/.config/kattis
macOS $HOME/Library/Preferences/kattis /Users/Alice/Library/Preferences/kattis
Windows {FOLDERID_RoamingAppData} C:\Users\Alice\AppData\Roaming\kattis

You can override the default configuration directory by setting the KATTIS_CONFIG_HOME environment variable.

Inside the configuration directory you can create a global configuration file kattis-global.yml. You may print the path to this file by running kattis config show

Credentials

In order to make submissions from the command line you will need to download the appropriate credentials. These can be found here. If you want to use this client on any other domain than open.kattis.com you will find credentials at https://<kattis>/download/kattisrc where <kattis> is the domain, eg. https://po.kattis.com/download/kattisrc.

Unlike the official submission CLI this client does not expect credentials to be stored in your home directory. Instead they are stored the credentials folder inside your configuration directory.

You may name the file containing the credentials whatever you want. Later, such when as when making a new submission, you can use this name to tell the client to submit to a different Kattis domain. This can, among other times, be useful during competitions.

By default the client will search for credentials with the name open.kattis.com. This behaviour can be overriden by changing the KATTIS_HOST environment variable or with a command line flag.

Templates

A template is basically a folder containing a barebones solution with all boilerplate code already typed out. They can save you a lot of time during competitions (when allowed) as you can spend more time on the problem at hand and less typing code.

Templates are stored as seperate directories in the templates folder inside the configuration directory. It is simple to create a new template:

kattis template new <name>

This will create a new template called <name> in the appropriate directory and create a default kattis.yml configuration file.

By default you will have to provide the client with the name of the template you wish to use with a flag. This behaviour can be overriden by changing the default_template property in either the global configuration file (kattis-global.yml).

The kattis.yml file

In this YAML file you may configure how the template is built, which files are submitted, and so on:

Field Description
samples The directory in which samples will be stored
files A list of files that should be submitted to the judge
language The language the solution is written in
mainclass Optional. Specify the main class
build A list of commands to execute in order to build the solution
run The command to run in order to run the solution

Note that for interpreted languages such as Python there's no need for a build step, as such you may leave the build field empty.

When a template is used to create a new solution to a problem using the kattis new command two additional fields are created:

Field Description
hostname The name of the credentials to use when submitting
problem The id of the problem the solution solves

Dependencies

~20MB
~462K SLoC