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).
  • Gym support.

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. See How to login below.
  • pyforces race 2092 to start the contest 2092. Same for gym (numbers >= 100000 are gyms).
  • pyforces test in the problem directory, like ~/cf/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.

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.

Warning: 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.

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>

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

  • Bug fix: some problems have multiple sub-problems like g1, g2
  • Bug fix: cannot track last submission
  • Floating-point errors in tests
  • (Neo)vim config example
  • Fix "ensure logged in" (some old cookies still work on the host url)
  • Use websocket to receive status updates
  • Test on Windows & Mac Write tests(?)
  • Provide more test outputs
  • Better CLI and color
  • Arguments for time and memory limit
  • Arguments for user customization (submit with custom URL and problem id)
  • Log to ~/.pyforces/logs/ to track bugs
  • Log requests and responses
  • Also store images if parse_problem_md

Not Planned

  • Login with username and password (too complicated firewall)
  • SPJ, interactive problem and communication. Most users don't write SPJ or interactor during contest, and after contest it is better to write custom test scripts for these problems.
  • Export as a python SDK for other libraries. CLI is the only way to use this tool.

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.4.0.tar.gz (27.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.4.0-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyforces_cli-0.4.0.tar.gz
  • Upload date:
  • Size: 27.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.4.0.tar.gz
Algorithm Hash digest
SHA256 d9c1801e88b48465b354597cfa12f1eb9ad30fbdc7e0dcc2272d2854fb8726e5
MD5 1f263143e44c411deb78fc18e84e9a67
BLAKE2b-256 60a101eee94f85b8f03f2383c551253b88f3748eaeb334e632501affac091ba7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyforces_cli-0.4.0.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.4.0-py3-none-any.whl.

File metadata

  • Download URL: pyforces_cli-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 26.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68e5b801a0ee0cfbb3e18a9fc33cf66325466f3b3cc471887873c9e9d06af0e9
MD5 a5d3219ecd8e4163e00fa5df42278e78
BLAKE2b-256 5e94d60aa58ba5bd795124ce5c976e5326c75f0cd9f5bebdd8d2e4cfdc15396b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyforces_cli-0.4.0-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