A helper script to run competitive programs and diff output
Project description
CP Runner
A helper "script" to quickly run your competitive programs and diff it against the expected output.
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
- On Windows, on the Windows Terminal or on Powershell (get wget here):
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:
$HOME/.config/cprunner/config.json
$HOME/.config/cprunner.json1
$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 scriptfilenameWithoutExt
: The filename with extension removedfileDir
: 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
Built Distribution
File details
Details for the file cprunner-0.1.3.tar.gz
.
File metadata
- Download URL: cprunner-0.1.3.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6fd9243348d9daf25b587ccc7260fb3c319e922d4e68a3056b44d7910f50a1d |
|
MD5 | 7aaa435b0af10c12a49f1ae9e1245de3 |
|
BLAKE2b-256 | be46a69e23be6202d3f8bdba545f2594f6b6f08cd4bdffaf86c38c0f1028b10e |
File details
Details for the file cprunner-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: cprunner-0.1.3-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 196b1c38a53a9ed8ff2eb7ebe15e533572714550bc1fd88b3f9edd50eade0f80 |
|
MD5 | 089acfd5f8a38fbdb79c6bab16c80c67 |
|
BLAKE2b-256 | 8b9f22de05bf6fd49540dcc2c1b1ca735318e8188eb9fd06d56be260f3246ed3 |