Skip to main content

A helper script to run competitive programs and diff output

Project description

CP Runner

PyPI Status

A helper "script" to quickly run your competitive programs and diff it against the expected output.

terminal_img

Quick Start

Install from PyPI.

python3 -m pip install cprunner

Then get the default config file from the repo:

  • On Linux/Mac:
wget -O ~/.cprunner.json https://raw.githubusercontent.com/RedDocMD/cprunner/main/config.json
wget -O "$HOME\.cprunner.json" https://raw.githubusercontent.com/RedDocMD/cprunner/main/config.json

Finally run it on your program as:

cpr -d A.cpp

Usage

 python src/cprunner -h                                    
usage: cprunner [-h] [-i] [-r | -d] file

positional arguments:
  file          file you want to run

optional arguments:
  -h, --help    show this help message and exit
  -i, --ignore  Ignore the cache entry for this file
  -r, --run     Just run the code (default)
  -d, --diff    Run the code and diff with expected output

Configuration

CP Runner requires a JSON config file to know what command to run for what file extension.

File locations

The config file can be at one of the following locations:

  1. $HOME/.config/cprunner/config.json
  2. $HOME/.config/cprunner.json1
  3. $HOME/.cprunner.json

If more than one these files are present, then the one first in this list is considered.

Format

The config file is of the following format (example here):

{
  "name1": {
    "ext": ["ext1", "ext2", "ext3"],
    "command": ["command1", "command2"]
  },
  "name2" : {
    "ext": ["ext4", "ext5"],
    "command": ["command3"]
  }
}
  • name - This is a name given to that particular entry and has no significance beyond that
  • ext - This is the list of extensions of files which are to be handled by this entry. No extension can appear more than once. This applies across different entries. An extension is specified without the leading dot.
  • command - This is the list of commands that are executed for the specified extensions. Note that, input is taken only for the last command. So the program must be executed in the last step. The use of multiple commands is for languages that need to be compiled first and then run. Also, do not use combinators like &&, ||, etc.

For each command in the command array, the following placeholders are defined:

  • filename: The complete filename that is passed as an arg to the script
  • filenameWithoutExt: The filename with extension removed
  • fileDir: The directory of the file which is passed as arg.

A placeholder can be used as ${placeholder}.

Cache

CP Runner caches the inputs given by the user for the last 100 unique files it was run on. On subsequent runs, it fetches the input from its cache instead of asking the user for input. This expedites the debugging process. The cache is presistent. To ignore the cache entry and provide input again, pass the -i flag.

Platforms

The script entirely uses platform-independent Python code. It should run on most platforms. I have tested it on Linux and by extension should work on Mac. I have no reason to believe that it won't work on Windows. If you find bugs, please report it here.

License

Copyright (©) 2021 Deep Majumder

This software is distributed under the GNU General Public License v3 (GPLv3).

For more information, please read LICENSE.

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

cprunner-0.1.2.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

cprunner-0.1.2-py3-none-any.whl (18.5 kB view hashes)

Uploaded Python 3

Supported by

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