qryxip / cargo-compete Goto Github PK
View Code? Open in Web Editor NEWA Cargo subcommand for competitive programming
License: Apache License 2.0
A Cargo subcommand for competitive programming
License: Apache License 2.0
This problem happens ABC233 and later ABCs.
In these contest, the name of 8th problem is changed to "Ex" while the URL's letter is "h".
The "run" function of new.rs creates "file_paths", the vector of pair of src path and testcase path.
At the moment of the creation, the order of src_path is alphabetical order, while testcase is problem order.
This makes unexpected "file_paths" variable like this: [ ... (e.rs, e.yml), (ex.rs, f.yml), (f.rs, g.yml), (g.rs, ex.yml)]
このようなテンプレートにRustのユニットテストを生成するようにすればVSCodeとかのGUIデバッガで動かせて便利なのではという考え。やるとすればproc-macroも良いが完全にstd
のみで動く簡潔なテストがベストか。
use proconio::source::once::OnceSource;
use std::io::Write;
fn main() {
let mut input = ::std::string::String::new();
::std::io::Read::read_to_string(&mut std::io::stdin(), &mut input).unwrap();
let stdout = ::std::io::stdout();
let mut output = ::std::io::BufWriter::new(stdout.lock());
crate::solve(&input, &mut output);
::std::io::Write::flush(&mut output).unwrap();
}
fn solve<S: AsRef<str>, W: Write>(input: S, mut output: W) {
let input = input.as_ref();
let mut input = OnceSource::from(input);
macro_rules! input(($($tt:tt)*) => (proconio::input!(from &mut input, $($tt)*)));
macro_rules! println(($($tt:tt)*) => (writeln!(output, $($tt)*).unwrap()));
input! {
n: usize,
}
println!("{}", 2 * n);
}
It seems that the terminal is cleared after printing message when using Windows Terminal.
cargo new practice # platform=atcoder
cd practice
cargo compete open
Note:
This works flawlessly in a terminal of VS Code.
$ cargo compete open
Opening https://atcoder.jp/contests/practice/tasks/practice_1
Opening https://atcoder.jp/contests/practice/tasks/practice_2
OS: Ubuntu 20.04.3 on Windows10 21H1 (WSL2)
Windows Terminal: 1.10.2383.0
cargo-compete: 0.9.0
cargo compete test
の際に、期待出力が空文字だと、
println!("")
のような空文字(改行あり)出力はWrong Answer
になります。
print!("")
だと通るので、"" != \n
なのだと思います。
AtCoderではprintln!("")
でも空文字として通ります。
例えば、↓などです。
https://atcoder.jp/contests/dp/tasks/dp_f
よろしくお願いします🙇♂️
cargo equip を使ってatcoderに提出する際、compete.toml の submit.transpile のコメントアウトを外すだけだとエラーが起きます。
エラーメッセージで"--exclude-atcoder-crates"、を足せばいいと出るので修正自体は楽なのですが、README.md やREADME-ja.mdに記載があると親切かなと思いましたが、いかがでしょうか。
nikkei2019-2-qualやdwacon6th-prelimsなどのコンテスト名にハイフンが入る場合処理の途中でエスケープされてしまい、cargo compete new
が失敗するようです
$ cargo compete -V
cargo-compete 0.7.1
$ cargo compete new nikkei2019-2-qual
error: Invalid character `%` in crate name: `nikkei2019%2D2%2Dqual`
error: `*********/.rustup/toolchains/1.42.0-x86_64-unknown-linux-gnu/bin/cargo new -q --vcs none --name 'nikkei2019%2D2%2Dqual' '*************/./nikkei2019%2D2%2Dqual'` didn't exit successfully: exit code: 101
(一部パスを伏せました)
v0.7.0からこの問題が発生してるようです(v0.7.1, v0.7.0で発生を確認しましたが、v0.6.5では発生しませんでした)
cargo_metadata
クレートの拡張。cargo-denyの一部として作られたっぽい。 cargo metadata
コマンドの発行が改善されてるしpackage specのパースまである。
Hello from rust-analyzer
! We might still revert the change that prompted this, but this PR seems like a good idea anyway.
My suggestion here would be to set a different target directory (CARGO_TARGET_DIR
) for cargo-compete
. If you use the same one, rust-analyzer
's check on save and cargo-compete
will block each other and overwrite their build artifacts.
Originally posted by @lnicola in #172 (comment)
Run cargo compete new 340
in codeforces directory, got the error:
error: `https://codeforces.com/contest/340/problem/A` is not a URL for problem in Codeforces
Currently, cargo compete test
exits without message if all tests pass.
but, it would be great if the command prints a message like "All test passed" to tell the results clearly.
abc003のテストケースを取得しようとしたのですが下記エラーが発生しテストケースを取得できませんでした。
$ cargo compete new abc003
error: Could not extract the timelimit
macOS 10.13.6
$ cargo compete --version
cargo-compete 0.4.1
$ rustc --version
rustc 1.42.0 (b8cedc004 2020-03-09)
パッケージにbin
を追加するコマンド。
現状yukicoderが不便なので。
まさかとは思うが... (cross
、rootless Dockerで動かないみたいだしrootlessじゃない方なりPodmanなりで試さないと)
% cargo compete new abc234
warning: Could not parse the title: "Ex - Enumerate Pairs"
warning: Could not find `EX` in `tasks_print`
Created `abc234` package at /xx/atcoder/./abc234
Saved 3 test cases to /xxx/atcoder/./abc234/testcases/{a.yml, a/}
Saved 2 test cases to /xxx/atcoder/./abc234/testcases/{b.yml, b/}
Saved 3 test cases to /xxx/atcoder/./abc234/testcases/{c.yml, c/}
Saved 2 test cases to /xxx/atcoder/./abc234/testcases/{d.yml, d/}
Saved 3 test cases to /xxx/atcoder/./abc234/testcases/{e.yml, e/}
Saved 3 test cases to /xxx/atcoder/./abc234/testcases/{f.yml, f/}
Saved 3 test cases to /xxx/atcoder/./abc234/testcases/{g.yml, g/}
おそらくここを
A-Za-z0-9
にすればパースできるようになりそうです
ただ二個目の警告文から分かる通り、内部のどこかで "Ex"
が "EX"
に変換されてしまっていることに起因しているエラーもあるように思うのですが、正確な発生箇所は分かりませんでした
cargo-executable-payloadというのを作ったので。
Arch Linux on Windows 10 x86_64にて cargo compete test
or cargo compete submit
を実行すると以下のようなエラーが起きる
❯ cargo compete test c
error: /home/user/atcoder/abc238/testcases/c: IO error for operation on /home/user/atcoder/abc238/testcases/c: No such file or directory (os error 2)
このような形式を追加する。この"a"
や"b"
はbin_index
のような適当な名前で呼んでいたが、「bin.name
のalias」という形にしてしまう。
[package.metadata.cargo-compete.bin]
-a = { name = "practice-a", problem = "https://atcoder.jp/contests/practice/tasks/practice_1" }
-b = { name = "practice-b", problem = "https://atcoder.jp/contests/practice/tasks/practice_2" }
+practice-a = { alias = "a", problem = "https://atcoder.jp/contests/practice/tasks/practice_1" }
+practice-b = { alias = "b", problem = "https://atcoder.jp/contests/practice/tasks/practice_2" }
It seems that when cargo compete test
for the first time after editing the source code, it's likely to exceed the time limit due to the building duration. Can you exclude building time from judging the timelimit? Great tool for Codeforces anyway, thanks.
Currently, cargo compete open
open pages in ascending order of difficulty (A to F in AtCoder), but I think this should be done in the reverse order.
This is because the most difficult problem is shown in a browser after executing the command.
possibly related code:
Lines 17 to 21 in 8a148d9
rust-analyzerはRust 1.47+に対してはproc-macroの展開をやってくれるようなのでrust-toolchain
ファイルを1.47.0
にしてtest
は1.42.0
で、という運用を可能にするための設定。
パッケージをワークスペースで管理する意味が薄くなってきたんじゃないかと思って。
というのも数十数百のパッケージを一度に登録するとrust-analyzer等に負担がかかってくる。
そもそもワークスペースで管理し始めたのがビルドキャッシュの共有するためであるが、target dirをsymlinkしたりしたら動作は保証されないしCLIで--target-dir
を指定するにしてもエディタの設定に食い込む必要がある... と思っていたのだがcargo configurationの設定にbuild.target-dir
というやつがあった。
以下のような方針でやればよさそう。
cargo compete new
の起点をワークスペースからcompete.toml
にして、それの場所をpackage.metadata
に記載するrust-toolchain
はcompete.toml
に書いたやつをnew
時に生成bin
のリネームはそのまま (target dirを使い回す以上、バッティングはしないほうが良い)現在の懸念は以下の通り。
stderrが発生した時のログについて、デフォルト値を大きくすることはできないでしょうか?
stderrに何も表示されない場合、デバッグに苦労します。
RUST_BACKTRACE=1
をセットしていることもあり、REが発生すると、すぐにデフォルトの4096バイトを超えてしまいます。
(English)
I want to set more large size of display-limit as default value.
When "stderr" does not displays error test itself, it is difficult for me to find the cause.
This happens mainly in RE case, because I set =RUST_BACKTRACE=1` for debugging.
Cargo.toml
内のpackage.metadata.cargo-compete.bin
でproblem
に設定されているURLに英大文字が含まれているとerror: Could not extract screen name of the problem
というエラーが出てきてcargo compete submit
ができません
この事象はAtCoderのCODE FESTIVAL 2016 qual Aで発生しました
このコンテストでは、各タスクのURLに英大文字が含まれています (例: https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_a の最後のqualAの部分)
URLのqualA
の部分を手動でquala
へ置き換えたところ、問題なく提出できましたが、バグだと思われるので念のため報告しておきます
実行環境:
OS: MacOS Monterey 12.1 Beta (21C5039b)
Version:
URLだけで問題を識別するようにする。ojが長年これで上手くいってるしURL単体からでもコンテストのIDは取れるはず。
[package.metadata.cargo-compete.bin]
a = { name = "practice-a", problem = "https://atcoder.jp/contests/practice/tasks/practice_1" }
b = { name = "practice-b", problem = "https://atcoder.jp/contests/practice/tasks/practice_2" }
普通に"parent directories"から探すようにする。
[package.metadata.cargo-compete]
-config = "../compete.toml"
なんか最近コンテストの度にクレートが再コンパイルされるなと思ったらCargo.lock
が展開されてなかった...
❯ cargo compete n abc191
Created `abc191` package at /home/ryo/src/competitive/atcoder/./abc191
Saved 2 test cases to /home/ryo/src/competitive/atcoder/./abc191/testcases/a.yml
Saved 2 test cases to /home/ryo/src/competitive/atcoder/./abc191/testcases/b.yml
Saved 1 test case to /home/ryo/src/competitive/atcoder/./abc191/testcases/c.yml
Saved 3 test cases to /home/ryo/src/competitive/atcoder/./abc191/testcases/d.yml
Saved 3 test cases to /home/ryo/src/competitive/atcoder/./abc191/testcases/e.yml
Saved 3 test cases to /home/ryo/src/competitive/atcoder/./abc191/testcases/f.yml
❯ ll abc191
.rw-r--r-- 3.2k ryo ryo 2021-02-19 16:15 -N Cargo.toml
drwxr-xr-x - ryo ryo 2021-02-19 16:15 -N src
drwxr-xr-x - ryo ryo 2021-02-19 16:15 -N testcases
profile
を書くことでdebug-assertions
とoverflow-checks
を有効にしたままTLEしない程度のopt-level
を設定できる。しかし現在、設定ファイルにはこれに対応する項目が無い。
[profile.dev]
opt-level = 2
yukicoder(やLibrary Checker)用にはinit
時にこのようなパッケージを作り,コンテストに参加するときはadd
コマンドを使ってもらう.
.
├── Cargo.lock
├── compete.toml
├── rust-toolchain
└── src
└── bin
└── dummy.rs
[package.metadata.cargo-compete.bin]
dummy = { problem = "https://example.com" }
compete.toml
のnew.template
をどこかに移動compete.toml
のnew
をoptionalにerror: Package names starting with a digit cannot be used as a crate name
error: `/Users/yuta/.rustup/toolchains/1.42.0-x86_64-apple-darwin/bin/cargo new -q --vcs none --name 1397 1397` didn't exit successfully: exit code: 101
コンテスト名が数字で始まるのが原因のようです
今の仕様だと単にappendするだけなので適切な場所に挿入するか,末尾に追加したあとにソートする.
[package.metadata.cargo-compete.bin]
9001 = {problem = "https://yukicoder.me/problems/no/9001"}
1358 = {problem = "https://yukicoder.me/problems/no/1358"}
1359 = {problem = "https://yukicoder.me/problems/no/1359"}
1360 = {problem = "https://yukicoder.me/problems/no/1360"}
1361 = {problem = "https://yukicoder.me/problems/no/1361"}
1362 = {problem = "https://yukicoder.me/problems/no/1362"}
1363 = {problem = "https://yukicoder.me/problems/no/1363"}
1364 = {problem = "https://yukicoder.me/problems/no/1364"}
1365 = {problem = "https://yukicoder.me/problems/no/1365"}
stderrの内容が表示されないことが多いため、デバッグに苦労します。
これ場合にほとんど表示されないため、
このため--display-limit の指定を試しているのですが、"no multiple"というよくわからないエラーが返ってきます。(複数の値を受け付けられない?)
このオプションはどう使えばよいのでしょうか?
> cargo compete new abc240
> cd abc240
> cargo compete test --display-limit 10000 e
error: Invalid value for '--display-limit <SIZE>': no multiple
> cargo compete test e --display-limit 10000
error: Invalid value for '--display-limit <SIZE>': no multiple
Successfully submitted the code
┌───────────────────┬───────────────────────────────────────────────────────────┐
│ Language ID │ 4050 │
├───────────────────┼───────────────────────────────────────────────────────────┤
│ Size │ 228 │
├───────────────────┼───────────────────────────────────────────────────────────┤
│ URL (submissions) │ https://atcoder.jp/contests/practice/submissions/me │
├───────────────────┼───────────────────────────────────────────────────────────┤
│ URL (detail) │ https://atcoder.jp/contests/practice/submissions/18710212 │
└───────────────────┴───────────────────────────────────────────────────────────┘
error: expected [200, 302], got 404 Not Found
cargo compete w s
するとちゃんと表示される。今日はABCがあるのでその数時間前にはworkaroundを追加する。
Thank you for providing useful tools.
便利なツールを提供していただいてありがとうございます。
I execute the command as follows when submitted:
私は提出するときに次のようにコマンドを実行し、
cargo compete submit --no-test --no-watch 001
A browser is opened in a browser that is fixed after the displayed submission
表示された提出後に確定されるURLをブラウザで開いています
│ URL (detail) │ https://atcoder.jp/contests/math-and-algorithm/submissions/30714538 │
This is because the eshell environment of Emacs is not compatible with the process of updating the console in real time in the escape sequence.
というのも使っている Emacs の eshell という環境が、エスケープシーケンスでコンソールをリアルタイムに更新するような処理に対応していないためです。
Sorry to be compared to other tools, but at atcoder-cli simply, it is helped to open a browser after the submission.
他のツールと比較して申し訳ありませんが atcoder-cli では単に提出後のURLをブラウザを開いてくれるので助かっています。
cargo compete submit
is only appreciated that there is a function that opens the URL after the submission to open the browser.
cargo compete submit
のときに単に提出後のURLをブラウザで開く機能(オプション)があるとありがたいです。
Please consider.
ご検討お願いいたします。
$ cargo compete t a
のかわりに
$ cargo compete t --src ./src/bin/a.rs
のようにできるとエディタから呼ぶときに便利なのでは。
It would be great if cargo compete submit
command has option to print submission results in ascending order of date, because descending order is hard to see the latest result if terminal height is small.
current:
$ cargo compete submit practice-a
│ 2021-09-19 08:46:14 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ WJ │
│ 2021-09-19 08:21:23 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 17 ms │ 2484 KB │
│ 2021-09-18 23:20:40 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 19 ms │ 2492 KB │
│ 2021-09-18 23:14:15 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 104 ms │ 2892 KB │
│ 2021-09-18 19:07:02 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 3 ms │ 2116 KB │
preferable (I think):
$ cargo compete submit practice-a
│ 2021-09-18 19:07:02 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 3 ms │ 2116 KB │
│ 2021-09-18 23:14:15 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 104 ms │ 2892 KB │
│ 2021-09-18 23:20:40 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 19 ms │ 2492 KB │
│ 2021-09-19 08:21:23 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ AC │ 17 ms │ 2484 KB │
│ 2021-09-19 08:46:14 +09:00 │ A - Welcome to AtCoder │ Rust (1.42.0) │ WJ │
Codeforces での Rust のバージョンが 1.57.0 になったのでそれに合わせてAPIの引数などを書き換えます
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.