Skip to content

Commit

Permalink
Rewrite bin/init_exercise.py in Rust (#660)
Browse files Browse the repository at this point in the history
* init_exercise: Generated the crate with 'cargo new'

* init_exercise: Added command-line arguments via clap

* init_exercise: Added configure command

* init_exercise: Replaced the dont-update-config flag with the no-configure flag

* init_exercise: Added init_app and process_matches functions

* init_exercise: Added cmd module

* init_exercise: Added process_matches to the generate module

* init_exercise: Added exercise template generation

* init_exercise: Added test suite and example.rs generation

* init_exercise: Added get_canonical_data function

* init_exercise: Added generate_standard_exercise_template function

* init_exercise: Renamed generate_standard_exercise_template to generate_default_meta

* init_exercise: Added update_cargo_toml function

* init_exercise: Added prepend text to the test suite

* init_exercise: Added generation of the property functions to the test suite

* init_exercise: Applied suggestions from clippy

* init_exercise: Added test suite functions generation

* init_exercise: Added generate_readme function

* init_exercise: Configured std::process::Command calls to wait until the process is finished running

* init_exercise: Renamed 'init_exercise' crate to 'exercise' crate

* exercise: Added shell script for building exercise crate

* exercise: Updated build_exercise_crate.sh script to look for Windows builds

* exercise: Removed redundant echos from build_exercise_crate.sh script

* exercise: Removed run_configure argument from the generate_exercise function

* exercise: Added configure_exercise call to the generate subcommand

* exercise: Added utils module

* exercise: Implemented the user configuration reading for the configure subcommand

* exercise: Implemented the writing of the updated configuration to the config.json

* exercise: Added run_configlate_command to the utils module

* exercise: Replaced the configlet call code with the run_configlet_command function call

* exercise: Added configlet fmt call to the configure_exercise funtion

* exercise: Replace 'null' with 'hello-world' as default unlocked_by field value

* exercise: Added configure_exercise call for the configure subcommand

* exercise: Fixed typo: 'run_configlate_command' -> 'run_configlet_command'

* exercise: configure subcommand now updates existing exercise config

* exercise: configure subcommand now allows to move the existing exercise config depending on the chosen difficulty

* exercise: Replaced the 'None' with 'hello-world' in the unlocked_by field input message

* exercise: Moved the processing of ArgMatches to the main module for the generate subcommand

* exercise: Replaced &Vec<Value> argument type with &[Value]

* exercise: Replaced the 'no-configure' flag with the 'configure' flag for the generate and update subcommands

* exercise: Added update_exercise call to the main module

* exercise: Added check if exercise exists for the update subcommand

* exercise: Moved get_canonical_data function to the utils module

* exercise: Added get_tests_content function to the utils module

* exercise: Added formatting functions for the 'property' and 'description' fields of the exercise

* exercise: Implemented apply_diffs function for the update subcommand

* exercise: Replaced apply_diffs function get_diffs function

* exercise: Implemented the update of the tests file

* exercise: Added use_maplit flag for the update subcommand

* README: Replaced the 'init_exercise.py' script description with the 'exercise' crate description

* README: Fixed typo - realease -> release

* build_exercise_crate: Fixed the Windows release path check

* exercise: Removed the authors field from the Cargo.toml and the '--help' output

* exercise: Added space to the user difficulty input prompt

* exercise: Added the newline at the end of the default generated '.meta/description.md'

* exercise: Moved exercise_exists function to the utils module

* exercise: Replaced the panic in the exercise exists checks with println and return

* exercise: Made the [utility] link to point at the exercise crate url on the Github in the test suite template

* exercise: Removed the blank line in the generated test case if no comments are present

* exercise: 'update' subcommand now updates the version of the exercise in the Cargo.toml file

* exercise: Moved the update_cargo_toml_version function to the utils module

* exercise: Made 'configure' subcommand to retain the existing values as default values, if an exercise exists in config.json

* exercise: Made 'configure' subcommand accept difficulties equal to or greater than the exercise which unlocks the configured exercise

* exercise: Added an option to restart the positioning binary search

* exercise: Moved the crate into the 'util' directory

* travis: Added a script to check if the 'exercise' crate compiles if it was modified

* check-exercise-crate: Replaced the 'cargo build --release' command with the 'cargo check' command

* exercise: Replaced the locating of the 'rustfmt' utility via 'which' command with PATH variable parsing

* exercise: Simplified the exercise_exists function

* exercise: Fixed typo in the 'exercise does not exist' message

* exercise: Specified the exercise difficulty prompt

* exercise: Specified that the new exercise is generated via 'exercise' utility

* exercise: Fixed comment typo

* exercise: Inlined the urls in the generated tests suite template

* exercise: Replaced the get_track_root function with lazy_static TRACK_ROOT value

* README: Updated the 'exercise' crate section to mention the openssl dependency

* exercise: Updated the crate's version to '1.0.0'

* init_exercise.py: Removed the script from the track

* Revert "init_exercise.py: Removed the script from the track"

This reverts commit d8d464b.

That commit caused a merge conflict.

* fix readme possessive typo
  • Loading branch information
ZapAnton authored and coriolinus committed Oct 20, 2018
1 parent b829ce2 commit 45599b8
Show file tree
Hide file tree
Showing 13 changed files with 2,443 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
tmp
bin/configlet
bin/configlet.exe
exercises/*/Cargo.lock
bin/exercise
bin/exercise.exe
exercises/*/Cargo.lock
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ script:
- "./bin/configlet lint ."
- "./_test/verify-exercise-difficulties.sh"
- "./_test/check-exercises-for-authors.sh"
- "sh ./_test/check-exercise-crate.sh"
sudo: false
rust:
- stable
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Please see the documentation about [adding new exercises](https://github.com/exe

Note that:

- The simplest way to generate a project template is to run `bin/init_exercise.py`. You'll need a Python installation >= 3.5 in order to run this script, but it will automate most of the following points for you.
- The simplest way to generate, update or configure an exercise is to use the [exercise](https://github.com/exercism/rust/tree/master/util/exercise) utility provided in this repository. To compile the utility you can use the [bin/build_exercise_crate.sh](https://github.com/exercism/rust/tree/master/bin/build_exercise_crate.sh) script or, if the script does not work for you, use the `cargo build --release` command in the `util/exercise/` directory and then copy the `exercise` binary from the `util/exercise/target/release/` directory into the `bin/` directory. Use `bin/exercise --help` to learn about the existing commands and their possible usage. Please note that this utility depends on the `reqwest` crate and therefore you may need to install its [required libraries](https://github.com/seanmonstar/reqwest#requirements) (namely `openssl`) in your system.

- Each exercise must stand on its own. Do not reference files outside the exercise directory. They will not be included when the user fetches the exercise.

Expand Down
34 changes: 34 additions & 0 deletions _test/check-exercise-crate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env sh

# A script to ensure that the util/exercise crate builds after it was modified.

EXERCISE_CRATE_PATH="util/exercise"

CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

if [ "$CURRENT_BRANCH_NAME" != "master" ]; then
# Check the changes on the current branch against master branch
git diff --name-only master | grep "$EXERCISE_CRATE_PATH"
else
# Check the commits on the master branch made during the week
# This is because Travis cron is set to test the master branch weekly.
git diff --name-only "@{7 days ago}" | grep "$EXERCISE_CRATE_PATH"
fi

if [ $? != 0 ]; then
echo "exercise crate was not modified. The script is aborted."

exit 0
fi

TRACK_ROOT="$(git rev-parse --show-toplevel)"

if !(cd "$TRACK_ROOT/$EXERCISE_CRATE_PATH" && cargo check); then
echo "\nAn error has occurred while building the exercise crate.\nPlease make it compile."

exit 1
else
echo "\nexercise crate has been successfully built."

exit 0
fi
26 changes: 26 additions & 0 deletions bin/build_exercise_crate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Compile the 'exercise' crate and put it in the 'bin/' folder

TRACK_ROOT="$(git rev-parse --show-toplevel)"

EXERCISE_CRATE_PATH="$TRACK_ROOT/util/exercise"

BIN_DIR_PATH="$TRACK_ROOT/bin"

(
cd "$EXERCISE_CRATE_PATH"

echo "Building exercise crate"

cargo build --release

RELEASE_PATH="$EXERCISE_CRATE_PATH/target/release/exercise"

if [ -f "$RELEASE_PATH.exe" ]; then
RELEASE_PATH="$RELEASE_PATH.exe"
fi

echo "Copying exercise crate from $RELEASE_PATH into $BIN_DIR_PATH"

cp "$RELEASE_PATH" "$BIN_DIR_PATH"
)
Loading

0 comments on commit 45599b8

Please sign in to comment.