Skip to main content

A CLI tool to automate competitive programming workflow

Project description

⚡ slave-cp

Your competitive programming workflow, automated.

CI PyPI version Python License: MIT

slave-cp is a command-line tool that automates the repetitive parts of competitive programming — fetching problems, running test cases with rich diffs, and submitting — so you can focus entirely on solving.


✨ Features

  • 📥 Fetch problems and sample test cases from Codeforces in one command
  • 🗂️ Auto-generates a clean folder structure and solution templates
  • ▶️ Run your solution against all test cases with colored pass/fail output
  • 🔍 Diff view — see exactly where your output differs from expected
  • 🚀 Auto-submit — triggered automatically when all test cases pass
  • 🌐 23 languages supported — C++, Python, Java, Rust, Go, Kotlin, and more
  • 🔒 Credentials stored locally — no third-party servers, ever

📦 Installation

pip install slave-cp

Requires Python 3.7+.


🚀 Quick Start

# 1. Set your workspace and save credentials (one-time setup)
slave-cp init ~/competitive

# 2. Fetch a contest
slave-cp fetch CF1234

# 3. Solve problem A (edit A.cpp, A.py, A.java — whatever language you like)
vim ~/competitive/CF1234/A.cpp

# 4. Run against sample test cases
slave-cp run A

# 5. If all pass, you'll be asked to submit automatically

📁 Folder Structure

After slave-cp fetch CF1234:

~/competitive/
└── CF1234/
    ├── A.cpp              ← pre-created solution template
    ├── A/
    │   ├── input1.txt
    │   ├── output1.txt
    │   ├── input2.txt
    │   └── output2.txt
    ├── B.cpp
    ├── B/
    │   └── ...
    └── ...

🖥️ Commands

slave-cp init <path>

Set your workspace folder and save credentials for Codeforces and CodeChef. Run this once before anything else.

slave-cp init ~/competitive
# ✔ Workspace set to: ~/competitive
# Codeforces handle: tourist
# Codeforces password: ••••••••
# ✔ Codeforces credentials saved.
# Default extension: .cpp
# ✔ slave-cp is ready! Happy coding.

slave-cp fetch <contest-id>

Scrapes all problems and sample test cases for a contest. Supports Codeforces (CF<id>) and CodeChef (CC-<id>).

slave-cp fetch CF1234        # Codeforces contest 1234
slave-cp fetch CC-START001   # CodeChef contest

slave-cp run <problem>

Compiles and runs your solution against all sample test cases. If all pass, you'll be prompted to submit.

slave-cp run A
slave-cp run A --contest CF1234   # specify contest explicitly

Output:

Language detected: C++
Compiling: A.cpp ... OK
Running 3 test case(s)...

  ✔ Test 1  →  ACCEPTED
  ✘ Test 2  →  WRONG ANSWER

  ╭───┬─────────┬─────────────────┬──────────────╮
  │   │ Input   │ Expected Output │ Your Output  │
  ├───┼─────────┼─────────────────┼──────────────┤
  │ 1 │ 3 5     │ 4               │ 3            │
  ╰───┴─────────┴─────────────────┴──────────────╯

  ✔ Test 3  →  ACCEPTED

─────────────────────────────────────────────
  ✘ 2/3 passed — 1 failed
─────────────────────────────────────────────

If all test cases pass:

─────────────────────────────────────────────
  ✔ All 3/3 test cases passed!
─────────────────────────────────────────────
Do you want to submit to the judge? [y/N]:

If multiple language files exist for the same problem (e.g. A.cpp and A.py), slave-cp will ask which one to run.

When all tests pass and you confirm submit, slave-cp logs in and polls for the verdict:

✔ Logged in successfully.
Submitting problem A (.cpp) ...
✔ Solution submitted successfully!

Waiting for verdict.........

  ✔ ACCEPTED 🎉

Possible verdicts: ACCEPTED, WRONG ANSWER, TIME LIMIT EXCEEDED, MEMORY LIMIT EXCEEDED, RUNTIME ERROR, COMPILATION ERROR.

Note: CodeChef submission uses Selenium with headless Chrome, same as slave-cp fetch.


slave-cp config

Show your current configuration.

slave-cp config
# Workspace : ~/competitive
# Extension : .cpp
# CF Handle : tourist
# CC Handle : chef

slave-cp list

List all contests in your workspace.

slave-cp list

slave-cp check

Check which compilers and interpreters are installed on your system.

slave-cp check

🌐 Supported Languages

Language Extension Compiled
C++ .cpp g++ -O2 -std=c++17
C .c gcc -O2
Python 3 .py
PyPy 3 .pypy
Java .java javac
Kotlin .kt kotlinc
Go .go go build
Rust .rs rustc -O
C# .cs dotnet-script
Ruby .rb
JavaScript .js
TypeScript .ts tsc
Haskell .hs ghc -O2
Scala .scala scalac
D .d dmd -O
Pascal .pas fpc
Perl .pl
PHP .php
Swift .swift swiftc
Lua .lua
R .r
Dart .dart
F# .fs dotnet-fsi

⚙️ Configuration

Config is stored at ~/.slave-cp/config.json:

{
  "workspace": "~/competitive",
  "extension": ".cpp",
  "codeforces": { "handle": "tourist" },
  "codechef":   { "handle": "chef" }
}

To update, just re-run slave-cp init or edit the file directly.


🧪 Running Tests

# Install dev dependencies
pip install -e ".[dev]"

# Run all tests
pytest tests/ -v

Tests cover:

  • test_config.py — init, save/load, workspace, credentials
  • test_fetcher.py — write test cases, templates, CF scraping (mocked HTTP)
  • test_runner.py — load test cases, detect solution, run (AC / WA / TLE / RE), summary

🗺️ Roadmap

  • Phase 1 — Fetch + folder setup (Codeforces)
  • Phase 2 — Run & test locally with diff output
  • Phase 3 — Auto-submit to Codeforces
  • Phase 4 — CodeChef support
  • Phase 5 — Published on PyPI

🤝 Contributing

Pull requests are welcome! For major changes, open an issue first.

git clone https://github.com/block-plant/slave-cp
cd slave-cp
pip install -e ".[dev]"
pytest tests/

Please make sure tests pass and code is formatted with black before submitting a PR.


📄 License

MIT © block-plant

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

slave_cp-0.1.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

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

slave_cp-0.1.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file slave_cp-0.1.0.tar.gz.

File metadata

  • Download URL: slave_cp-0.1.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for slave_cp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6062737014e6e27744568281a6d7855a798c1a8b03ea9953c9a4452ad8939592
MD5 19f2f8b4f393dda4106d7bd6be370748
BLAKE2b-256 187572e36ac4b0cadaa282253f0391d1bc4e6a1847487528174a92e093506cd0

See more details on using hashes here.

File details

Details for the file slave_cp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: slave_cp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for slave_cp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a29532a6765998b78a4c2f7b5349346ee7e533e8448c93a29b9f9ac6ded9c266
MD5 f6aebf2c6ea079a21065b517a09adcc2
BLAKE2b-256 11302ffe35349e3451eb86951b1df832762a32a53d1f9d7e98b365a2f0780329

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