Skip to main content

Yet another Codeforces CLI tool

Project description

pyforces

Github release platform license

中文

Yet another command-line interface tool for Codeforces designed for (neo)vim competitors. Rebirth of xalanq/cf-tool.

Why another CLI tool?

Codeforces added bot detection recently, and AFAIK all the existing CLI tools are blocked. ref1 ref2

Features

  • Parse sample testcases.
  • Test your solution with parsed testcases.
  • Submit code.
  • Generate code from templates.
  • Start a contest (parse sample testcases for all problems and optionally gen template).

Feature requests and PRs are welcomed.

Since this tool is designed for speed only, some features of xalanq/cf-tool are removed. Please don't request for any features that are not speed-sensitive or already supported by Codeforces webpage itself or other GUI tools like CCH.

Platforms

Developed on Linux, tested on Linux, Mac and Windows.

If you encounter any issues on Windows or Mac, please read the error message and stacktrace first. If you believe this is a bug or unwanted feature, submit an issue with the stacktrace, or use pyforces --log-level=debug <subcommand> [sub-arguments] to get even more verbose output.

Installation

pip install pyforces-cli

See FAQ if you encounter any problems.

Usage

  • pyforces config to login and configure your tool. Firefox is needed for login.
  • pyforces race 2092 to start the contest 2092.
  • pyforces test in the problem folder, like ~/pyforces/contest/2092/a, to test your solution against parsed sample testcases. Note that you need to first compile it yourself, the executable filename is derived from the cpp filename.
  • pyforces submit in the problem folder, to submit your solution.
  • pyforces parse in the problem folder to parse sample testcases.
  • pyforces gen in the problem folder to generate a file from template.

Vim config

The intended use of this tool is to bind some keys to speed up testing and submitting. Here is an example neovim keybinding configuration (vim users need to replace term by !):

" test, and submit on success
nnoremap <F5> :w<CR>:term pyforces test -f % && pyforces submit -f %<CR>
" test
nnoremap <F6> :term pyforces test -f %<CR>
" submit
nnoremap <F7> :w<CR>:term pyforces submit -f %<CR>

Change the keys to your choices as you wish.

Also, if you don't want to mess up keybindings of other buffers or projects, consider adding a filetype check and buffer prefix:

" test, and submit on success
au FileType cpp nnoremap <buffer><F5> :w<CR>:term pyforces test -f % && pyforces submit -f %<CR>
" test
au FileType cpp nnoremap <buffer><F6> :term pyforces test<CR>
" submit
au FileType cpp nnoremap <buffer><F7> :w<CR>:term pyforces submit -f %<CR>

" python support, with program_type_id=70 (PyPy 3.10)
au FileType python nnoremap <buffer><F5> :w<CR>:term pyforces test -f % && pyforces submit --file=% --program-type-id=70<CR>
au FileType python nnoremap <buffer><F6> :w<CR>:term pyforces test -f %<CR>
au FileType python nnoremap <buffer><F7> :w<CR>:term pyforces submit -f % --program-type-id=70<CR>

How to login

First, you need to login to codeforces in Firefox. If you don't use Firefox, either use it once or find a way (like a plugin?) to configure your ~/.pyforces/headers.txt (If you don't know what is ~, try searching home directory).

Then, follow this video to configure your HTTP header:

https://github.com/user-attachments/assets/cac3b09a-1809-4de3-bc9a-53d8d9df8c05

Note: in the video the root name has been configured to cf not default pyforces.

If the method in the video fails, check FAQ first. If that doesn't help, you can manually paste your headers to ~/.pyforces/headers.txt. If you use Firefox, directly pasting the "(Copy All)" to ~/.pyforces/headers.txt is okay. If you use other browsers, check this example headers.txt.

Note: the ensure logged in option in config doesn't actually ensure you are logged in. It is recommended to paste your headers before each contest.

FAQ

pip install failed

error: externally-managed-environment

× This environment is externally managed

It is recommended to install this tool in a virtual environment managed by miniconda.

If you don't want to use a virtual environment, adding --break-system-packages at the end of pip install should work.

Command 'pyforces' not found

If pyforces command isn't available, you can use python -m pyforces to invoke pyforces.

Terminal stuck when pasting headers

Change the buffer size of your terminal, and make sure you press enter after pasting it if it seems to stuck. You can modify the buffer size in your terminal's settings.

Is it violating bot detection?

Since login requries you to actually login in Firefox first, this doesn't violate bot detection. For more details, see here.

TODO

  • Floating-point errors in tests
  • Special Judge and Interactive problems
  • (Neo)vim config example
  • Sphinx documentation
  • Support for AI automatic problem solving as a library
  • Fix "ensure logged in" (some old cookies still work on the host url)
  • Use websocket to receive status updates
  • Test on Windows & Mac
  • Provide more test outputs
  • Arguments for time and memory limit
  • Support stressing using an std and a brute force

Not Planned

  • Colorful CLI
  • Login with username and password (too complicated firewall)

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

pyforces_cli-0.3.3.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

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

pyforces_cli-0.3.3-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file pyforces_cli-0.3.3.tar.gz.

File metadata

  • Download URL: pyforces_cli-0.3.3.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyforces_cli-0.3.3.tar.gz
Algorithm Hash digest
SHA256 fb5cdf4065c45baefc729f97fc5bbb33fc91ec8610f1940ac0c988cd09e43687
MD5 4e65919315af0753ac471b871749b144
BLAKE2b-256 b62bdff135b5ba8b1b9fc660b4041656814a500e2de45055fb6994711ccbf898

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyforces_cli-0.3.3.tar.gz:

Publisher: python-publish.yml on LZDQ/pyforces

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyforces_cli-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: pyforces_cli-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyforces_cli-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fe54b2335ee680af7ca72e640bccb2be25861b35837e67d884ef5f78c04b9d08
MD5 eed4d22e8353bc2bbfa05aa5b1f60677
BLAKE2b-256 28cacb42bab0437bd022d246909bc1b8cefa65ae54acff091c6b9672c2b9aa3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyforces_cli-0.3.3-py3-none-any.whl:

Publisher: python-publish.yml on LZDQ/pyforces

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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