-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite bin/init_exercise.py in Rust #660
Conversation
…he process is finished running
Questions regarding the As I understand it, the desirable algorithm is to get the latest
|
I think this tool should never delete a test case. It can't easily know if
a case not represented in the canonical data was deleted from the canonical
data, or was a custom case implemented for the Rust track which has never
appeared in the canonical data.
For updating existing test cases, I'd favor a very simple--even
stupid--strategy:
1. capture the bytes of the existing test case in a buffer: the literal
text of the test
2. compare them to the bytes of the generated test case
3. if the generated test case differs from the existing test case, update
the name of the generated case with some suffix and then emit them both.
Users of this script will then have the implicit option: keep all the
cases, and accept some repetition, or manually remove duplicate cases.
That's on them.
Both of these preferences are consistent with the general philosophy that
test suites should be write-only.
…On Tue, Sep 18, 2018 at 11:50 AM Zapolsky Anton ***@***.***> wrote:
Questions regarding the update subcommand:
As I understand it, the desirable algorithm is to get the latest
canonical-data.json for the exercise and to apply any diffs to the
existing test suite:
- If a new case/property is added to the canonical-data, add the
appropriate functions to the existing test suite - no problems here
- If the existing case is updated, add a new function to the test
suite and do not touch the existing function. Question: How to track the
updates to the cases? We cannot use the existing test suite, as the
person who implements the exercise is not bound to follow the format of the
generated test suite and may use the format of their own. Should we track
the changes via git?
- If the existing case is deleted from the canonical-data.json, what
should be done with the existing test functions?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#660 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHdeTsAWClySLXJELFCgWW1-fqefRRAvks5ucMHxgaJpZM4WtiY4>
.
|
bin/build_exercise_crate.sh
Outdated
|
||
echo "Copying exercise crate from $EXERCISE_CRATE_PATH/target/release/exercise into $BIN_DIR_PATH" | ||
|
||
cp "$EXERCISE_CRATE_PATH/target/release/exercise" "$BIN_DIR_PATH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail on a Windows machine if the user is running this through cygwin: the binary in that case would be exercise.exe
.
Some questions regarding usage notes:
I have included the line as per your comment:
The line will change to
By 'before any tests' do you mean the tests generated with the
Since we will be implementing the
|
Additional note about the test suite format: In the |
The Travis script has been added and it seems like it works, but it takes about 5 minutes to complete, which is quite a lot. |
|
What I wanted to say is that from the start the |
I see. No, I think it's probably best to manually update the crate's version. I'd be very reluctant to give Travis push access to this repo. |
Then, right before the merge, I will give the crate the |
…th the 'cargo check' command
Works for me.
…On Fri, Oct 19, 2018 at 8:29 PM Zapolsky Anton ***@***.***> wrote:
Then, right before the merge, I will give the crate the 1.0.0 version, to
emphasize it's relative completness
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#660 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHdeTngkewL5StDj3V_E_t9uCU2ajUFLks5umhgkgaJpZM4WtiY4>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ZapAnton, for this utility! This may be the biggest PR yet merged to this repo in one go.
There are still quite a few areas which could be improved, but this already more feature-complete than the init_exercise.py
script which it replaces.
I confirm that the three critical points I listed above have all been fixed. I've listed some minor changes and fixes below. When the time comes to merge this, I will also go through and add a bunch of issues, itemizing the remaining improvement points that I've found here.
This PR has been open for long enough that I do not intend to wait for other maintainer feedback. I will merge it as soon as you say it's ready, @ZapAnton.
Optionally, you may also delete bin/init_exercise.py
as part of this PR.
exercise/Cargo.toml
Outdated
[package] | ||
name = "exercise" | ||
version = "0.1.0" | ||
authors = ["ZapAnton <[email protected]>"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line, as noted in the notes from usage.
authors = ["ZapAnton <[email protected]>"] |
exercise/src/utils.rs
Outdated
|
||
let exercises_path = Path::new(&track_root).join("exercises"); | ||
|
||
for entry in exercises_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we check whether the exercises path exists directly, instead of needing to iterate over the entire path?
exercise/src/cmd/update.rs
Outdated
pub fn update_exercise(exercise_name: &str, use_maplit: bool) { | ||
if !utils::exercise_exists(exercise_name) { | ||
println!( | ||
"Exercise with the name '{}' does not exists. Aborting", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: exists
-> exist
.
"Exercise with the name '{}' does not exists. Aborting", | |
"Exercise with the name '{}' does not exist. Aborting.", |
exercise/src/cmd/configure.rs
Outdated
let insert_index = exercises_with_similar_difficulty[insert_index].0; | ||
|
||
let prompt = if insert_index == 0 { | ||
format!("{} is the easiest exercise on the track.", exercise_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only true if *difficulty == 1
.
format!("{} is the easiest exercise on the track.", exercise_name) | |
format!("{} is the easiest exercise of difficulty {}.", exercise_name, *difficulty) |
exercise/src/cmd/configure.rs
Outdated
let prompt = if insert_index == 0 { | ||
format!("{} is the easiest exercise on the track.", exercise_name) | ||
} else if insert_index == exercises.len() - 1 { | ||
format!("{} is the hardest exercise on the track.", exercise_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only true if difficulty == 10
.
format!("{} is the hardest exercise on the track.", exercise_name) | |
format!("{} is the hardest exercise of difficulty {}.", exercise_name, *difficulty) |
util/exercise/src/cmd/generate.rs
Outdated
}; | ||
use utils; | ||
|
||
static GITIGNORE_CONTENT: &'static str = "# Generated by Cargo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking this file will not be generated by Cargo
static GITIGNORE_CONTENT: &'static str = "# Generated by Cargo | |
static GITIGNORE_CONTENT: &'static str = "# Generated by exercism rust track exercise tool |
util/exercise/src/utils.rs
Outdated
false | ||
} | ||
|
||
// Update the version of the specified exersice in the Cargo.toml file according to the passed canonical data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
// Update the version of the specified exersice in the Cargo.toml file according to the passed canonical data | |
// Update the version of the specified exercise in the Cargo.toml file according to the passed canonical data |
util/exercise/src/utils.rs
Outdated
}; | ||
use toml::Value as TomlValue; | ||
|
||
pub fn get_track_root() -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a good place to use lazy_static!
to initialize this value exactly once, and then keep it. By my count this command gets called in eight different places in this code; since the result will never change, we don't need to rerun the subcommand every time.
util/exercise/src/cmd/generate.rs
Outdated
{} \n\ | ||
", | ||
exercise_name, | ||
"https://github.com/exercism/rust/tree/master/util/exercise", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be inlined.
util/exercise/src/cmd/generate.rs
Outdated
", | ||
exercise_name, | ||
"https://github.com/exercism/rust/tree/master/util/exercise", | ||
format!("https://raw.githubusercontent.com/exercism/problem-specifications/master/exercises/{}/canonical-data.json", exercise_name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be inlined; it's a little silly to embed a format!()
string in the args of another format!()
string.
…command with PATH variable parsing
The removal of the |
Ignoring the conflict with the Python script, I think I have addressed all the recent points. @coriolinus if the last batch of commits does not contain any shorcomings and you are fine with moving the remaining usage and formatting notes into separate issues, I think this PR is ready to be merged. |
This reverts commit d8d464b. That commit caused a merge conflict.
* extract conceps from leap * Update languages/reference/exercise-concepts/leap.md Co-Authored-By: Peter Goodspeed-Niklaus <[email protected]> Co-authored-by: Peter Goodspeed-Niklaus <[email protected]>
* extract conceps from leap * Update languages/reference/exercise-concepts/leap.md Co-Authored-By: Peter Goodspeed-Niklaus <[email protected]> Co-authored-by: Peter Goodspeed-Niklaus <[email protected]>
The purpose of this PR is to replace the functionality of the existing
bin/init_exersice.py
script with the Rust crateexercise
and to add additional functionality as per #641.It is opened as
In Progress
in order for maintainers to track any undesirable decisions/functionality in the new crate, since it is a medium-complexity project, so disagreements may arise.In addition to the future suggestions the current work plan looks like this:
Major Tasks
configure
subcommandupdate
subcommandMinor Tasks
canonical-data.json
to the generated test suitemaplit
crate is used. Currently it is an unreadable mess andrustfmt
does not helpNote that as per #641 (comment) the crate name is changed from
init_exercise
toexercise
, so the prefix in the commit messages is changed frominit_exercise:
toexercise:
accordinglyIf this PR is merged, closes #641