A CLI tool to automate competitive programming workflow - fetch, test, and submit solutions
Project description
slave-cp
A powerful CLI tool that automates your competitive programming workflow โ fetch problems, test locally, and auto-submit solutions.
โจ Features
- ๐ Quick Setup โ One command to initialize your workspace and credentials
- ๐ Multi-Platform Support โ Works with Codeforces and CodeChef
- ๐ Auto-Fetch โ Automatically scrapes problems and test cases
- ๐งช Local Testing โ Run solutions against sample inputs with rich diff tables
- ๐ค Auto-Submit โ Submit directly from terminal with real-time verdict tracking
- ๐จ Rich Terminal UI โ Beautiful colored output with status indicators
- ๐ง 23 Languages Supported โ From C++ to Rust, Python to Haskell
๐ฆ Installation
pip install slave-cp
Requirements:
- Python 3.7 or higher
- Compiler/interpreter for your chosen language (e.g.,
g++for C++,pythonfor Python)
๐ Quick Start
1. Initialize Your Workspace
slave-cp init ~/competitive
This will:
- Set your workspace directory
- Save Codeforces credentials (handle & password)
- Save CodeChef credentials (handle & password)
- Set your default programming language
2. Fetch a Contest
Codeforces:
slave-cp fetch CF1234
CodeChef:
slave-cp fetch CC-START001
This creates a folder with all problems and their test cases:
CF1234/
โโโ A/
โ โโโ input1.txt
โ โโโ output1.txt
โ โโโ input2.txt
โ โโโ output2.txt
โโโ B/
โ โโโ input1.txt
โ โโโ ...
โโโ ...
3. Write Your Solution
Create your solution file in the problem folder:
cd CF1234/A
touch solution.cpp # or .py, .java, etc.
4. Test Locally
slave-cp run A
Or with explicit contest ID:
slave-cp run A --contest CF1234
Output:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Test Case 1 โ
AC โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Input: 5 3 โ
โ Expected: 8 โ
โ Got: 8 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
All test cases passed! ๐
Submit to Codeforces? [y/N]:
5. Submit (Optional)
If all tests pass, you'll be prompted to submit. Type y to submit directly to the platform.
๐ Commands
| Command | Description |
|---|---|
slave-cp init <path> |
Initialize workspace and save credentials |
slave-cp fetch <contest-id> |
Fetch problems and test cases from a contest |
slave-cp run <problem> |
Test your solution against sample inputs |
slave-cp run <problem> --contest <id> |
Test with explicit contest ID |
slave-cp config |
Display current configuration |
slave-cp list |
List all contests in workspace |
slave-cp check |
Check installed compilers/interpreters |
slave-cp --help |
Show help message |
๐ Supported Platforms
Codeforces
- Contest format:
CF<contest-number>(e.g.,CF1234) - Scrapes problems using
requests+BeautifulSoup - Auto-login with saved credentials
- Real-time verdict polling
CodeChef
- Contest format:
CC-<contest-code>(e.g.,CC-START001) - Uses Selenium with headless Chrome
- Supports practice problems and contests
- Automated CodeMirror injection for submission
๐ป Supported Languages (23)
Auto-detected by file extension:
| Language | Extension | Compiler/Interpreter Required |
|---|---|---|
| C++ | .cpp |
g++ |
| C | .c |
gcc |
| Python | .py |
python or python3 |
| Java | .java |
javac + java |
| Kotlin | .kt |
kotlinc + kotlin |
| Go | .go |
go |
| Rust | .rs |
rustc |
| C# | .cs |
dotnet-script |
| Ruby | .rb |
ruby |
| JavaScript | .js |
node |
| TypeScript | .ts |
ts-node |
| Haskell | .hs |
ghc |
| Scala | .scala |
scalac + scala |
| D | .d |
dmd |
| Pascal | .pas |
fpc |
| Perl | .pl |
perl |
| PHP | .php |
php |
| Swift | .swift |
swift |
| Lua | .lua |
lua |
| R | .r |
Rscript |
| Dart | .dart |
dart |
| F# | .fs |
dotnet fsi |
| PyPy | .pypy |
pypy or pypy3 |
Run slave-cp check to verify which languages are available on your system.
โ๏ธ Configuration
Configuration is stored at ~/.slave-cp/config.json:
{
"workspace": "/Users/username/competitive",
"language": "cpp",
"codeforces": {
"handle": "tourist",
"password": "your-password"
},
"codechef": {
"handle": "gennady.korotkevich",
"password": "your-password"
}
}
View current config:
slave-cp config
Update workspace or credentials:
slave-cp init ~/new-workspace
๐งช Testing Workflow
Verdicts
| Verdict | Symbol | Meaning |
|---|---|---|
| AC | โ | Accepted โ correct output |
| WA | โ | Wrong Answer โ output mismatch |
| TLE | โฑ๏ธ | Time Limit Exceeded (>5s) |
| RE | ๐ฅ | Runtime Error โ program crashed |
| CE | ๐ง | Compilation Error โ code didn't compile |
Diff Table
When output doesn't match:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Test Case 2 โ WA โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Input: 10 20 30 โ
โ Expected: 60 โ
โ Got: 50 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
๐ง Troubleshooting
HTTP 403 Error on Codeforces Fetch
Problem: Codeforces blocks the scraper
Solution: This will be fixed in the next version (0.1.1). For now, try:
- Running the command again (sometimes transient)
- Using a VPN if your IP is rate-limited
Wrong/Empty Credentials Accepted
Problem: Invalid credentials saved without validation
Solution: Fixed in version 0.1.1. Meanwhile, manually edit ~/.slave-cp/config.json to ensure credentials are correct.
Selenium/Chrome Issues (CodeChef)
Problem: chromedriver not found or browser errors
Solution:
# macOS
brew install chromedriver
# Ubuntu/Debian
sudo apt-get install chromium-chromedriver
# Windows
Download from https://chromedriver.chromium.org/
Compiler Not Found
Problem: g++: command not found
Solution:
# macOS
xcode-select --install
# Ubuntu/Debian
sudo apt-get install build-essential
# Windows
Install MinGW or use WSL
Check installed compilers:
slave-cp check
๐ Advanced Usage
Custom Time Limit
By default, solutions timeout after 5 seconds. This is hardcoded but can be adjusted in future versions.
Multiple Solutions
You can have multiple solution files (e.g., solution.cpp, brute.cpp) in the same problem folder. slave-cp run will use the first one it finds matching your default language.
Manual Test Cases
Add your own test cases by creating input{n}.txt and output{n}.txt pairs in the problem folder.
๐ค Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Development setup:
git clone https://github.com/block-plant/slave-cp.git
cd slave-cp
pip install -e .[dev]
pytest
๐ License
This project is licensed under the MIT License โ see the LICENSE file for details.
๐ค Author
Ayush Kunwar Singh (@block-plant)
๐ Acknowledgments
- Built with Click for CLI
- Styled with Rich for beautiful terminal output
- Web scraping powered by BeautifulSoup and Selenium
๐ Project Status
- โ
Live on PyPI:
pip install slave-cp - โ Codeforces support
- โ CodeChef support
- โ 23 languages supported
- ๐ง Version 0.1.1 coming soon with bug fixes
๐ Links
- PyPI: https://pypi.org/project/slave-cp/
- GitHub: https://github.com/block-plant/slave-cp
- Issues: https://github.com/block-plant/slave-cp/issues
- Documentation: USER_MANUAL.md
Happy Coding! ๐
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slave_cp-0.1.7.tar.gz.
File metadata
- Download URL: slave_cp-0.1.7.tar.gz
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12f5824ccf148e45a5cdd0e60689544eb4de89ddb15b33c0be7fa35299ee1c07
|
|
| MD5 |
d46f3e9daa6cf12f127a274c81964f0a
|
|
| BLAKE2b-256 |
028523e4e614f63c343fd4e8306ce8adaabab8c3b854f2b8a9b98ee0813cce18
|
File details
Details for the file slave_cp-0.1.7-py3-none-any.whl.
File metadata
- Download URL: slave_cp-0.1.7-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1d41492666922e61683860dbaf35b2a73603f194898729867abafccd9acae04
|
|
| MD5 |
920301b2eb5da9a65b83460377e568e9
|
|
| BLAKE2b-256 |
61832dbdc4ca03df4496d882aacc6376caa76572ab0ac25809efbdf682658ebb
|