Skip to content
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

Impliment new template based generator #1730

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Conversation

meatball133
Copy link
Member

No description provided.

@meatball133 meatball133 added the x:rep/large Large amount of reputation label Nov 9, 2024
Copy link
Contributor

github-actions bot commented Nov 9, 2024

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

generatorv2/lib/generator.rb Outdated Show resolved Hide resolved
generatorv2/lib/generator.rb Outdated Show resolved Hide resolved
bin/generate.rb Outdated Show resolved Hide resolved
bin/generate Outdated Show resolved Hide resolved
@meatball133 meatball133 marked this pull request as ready for review November 11, 2024 13:09
@meatball133 meatball133 requested a review from a team November 15, 2024 18:30
@@ -0,0 +1,49 @@
require 'toml-rb'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problems or solutions are we avoiding/gaining by using TOML as opposed to YAML (or even JSON)? This is the point at which TOML as a tool and dependency is being introduced, and its associated maintenance cost, so we should evaluate that. We should have a net positive effect by bringing this in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test.toml files are written in toml, using another file format isn't really an option since rewriting it would require parsing it.

I wrote a manual parser for the Crystal generator (but it is likely not as good of an implementation) because I couldn't find any good shards (library). This library should be fine, the toml specification isn't changing, but we could have our own solution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is more or less with the toml files is that, if someone adds extra test cases or reimplements test cases for a certain exercise will that not affect the generation process until you sync the exercise. Meaning the ci won't fail in the majority of cases if not all exercises are synced.

bin/generate Outdated
f = Tempfile.create
Generator.new(exercise).generate(f.path)
generated_code = f.read
raise RuntimeError.new("The result generated for: #{exercise}, doesnt match the current file") if current_code != generated_code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise RuntimeError.new("The result generated for: #{exercise}, doesnt match the current file") if current_code != generated_code
raise RuntimeError.new("The result generated for: #{exercise}, doesn't match the current file") unless current_code == generated_code

Typographical error (missing apostrophe) and preference of "positive conditional statement".

Prefer using unless positive_conditional_statement rather than if negative, this can keep all (or at least most) of our conditional statements positive.

We should also consider if RuntimeError is the best error here. It could be VerificationError instead, which would be more specific.

We might also fail instead of raise for the communication that this is purposefully failed here, given the right conditions.

Since the generator grabs all the data from the canonical data, so does this enable new tests that won't automatically be merged in.
Instead so does new tests have to be added to the toml file before they show up in the test file.

If there is a test that isn't needed or something that doesn't fit Ruby you can remove it from the toml file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If there is a test that isn't needed or something that doesn't fit Ruby you can remove it from the toml file.
If there is a test that isn't needed or something that doesn't fit Ruby you can remove it from the configuration file.

In case we move from TOML to another type of configuration file, this reference will not need to change in the documentation.

generatorv2/README.md Outdated Show resolved Hide resolved
generatorv2/README.md Outdated Show resolved Hide resolved
bin/generate Outdated
end
rescue VerificationError => e
$stderr.puts e.message % {exercise:}
Copy link
Member

@kotp kotp Nov 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be aware that this syntax is relatively new, and so we should ensure that the minimum Ruby version is set to allow for this "valueless hash" syntax.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it is tooling and we have set the ruby version to 3.3 so I think we dont have to have backwards compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that it is backward compatible to 3.3.0, up to 3.3.6, currently. Locally I am running 3.3.6, and so the backward compatibility is there.

bin/generate Outdated Show resolved Hide resolved
Co-authored-by: Victor Goff <[email protected]>
bin/generate Outdated
parser = OptionParser.new

parser.on('-v', '--version', 'Print the version') do
puts '0.1.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting this out to a version file for the generator. This will mean that we do not have to dig into the code to update the version.

# This would break it since it is an extra space between UUID and `[`
[ 1e22cceb-c5e4-4562-9afe-aef07ad1eaf4]
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth writing a "validator" option for the genator. Perhaps even initiating the bundle install command that is needed. If we know it has to happen we can provide the mechanism, avoiding mistakes from the users, even if it is seemingly "simple".

Copy link
Member Author

@meatball133 meatball133 Jan 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that shouldn't actually be an issue, unless it breaks against toml rules which I think it doesn't. The docs very some what of a copy paste from the Crystal docs (so it shouldn't be here). And that one has that issue,


### The Test Generator

If all the earlier steps are done so can you run the generator.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If all the earlier steps are done so can you run the generator.
If all the earlier steps are done you run the generator.


The template file is written in [Embedded Ruby(ERB)][erb].
ERB enables you to write Ruby code inside of the template file.
It also means that the templates can be highly customizable since you can write any Ruby code you want.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It also means that the templates can be highly customizable since you can write any Ruby code you want.
It also means that the templates can be highly customized allowing you to write any Ruby code you want or need.

The template is located under the `.meta` for each exercise.

This template has to be manually written for each exercise.
The goal although is to make it so that you only have to write the template once and then it will be able to be used to generate new tests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The goal although is to make it so that you only have to write the template once and then it will be able to be used to generate new tests.
The goal is to make it so that you only have to write the template once and then it will be able to be used to generate new tests.

To run the generator so do you have to be in the root directory and run the following command:

```shell
bundle exec ./bin/generate -e <exercise_slug>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either the line commented prior to this comment is incorrect, or this line is incorrect.


Where `<exercise_slug>` is the same name as the slug name which is located in the `config.json` file.

For more commands so can you run the following command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more commands so can you run the following command:
For more commands and options, you can see this by running the command:


The generator will give you errors and warnings if something is wrong.
That includes if the exercise is not in the `config.json` file, if the exercise is not in the toml file, or if the template file is missing.
Also if it has a problem getting the `canonical-data.json` file so will it give you an error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Also if it has a problem getting the `canonical-data.json` file so will it give you an error.
It will also report an error if it can not read the `canonical-data.json` file.

The generator will give you errors and warnings if something is wrong.
That includes if the exercise is not in the `config.json` file, if the exercise is not in the toml file, or if the template file is missing.
Also if it has a problem getting the `canonical-data.json` file so will it give you an error.
The generator also uses a formatter which will give you errors if the generated file is not formatted correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The generator also uses a formatter which will give you errors if the generated file is not formatted correctly.
The generator will check that the generated file is formatted correctly, reporting an error if there is a problem.

That includes if the exercise is not in the `config.json` file, if the exercise is not in the toml file, or if the template file is missing.
Also if it has a problem getting the `canonical-data.json` file so will it give you an error.
The generator also uses a formatter which will give you errors if the generated file is not formatted correctly.
The file will still be generated even if formatter gives errors, therefore can you check the file and see what is wrong and fix it in the template.
Copy link
Member

@kotp kotp Jan 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The file will still be generated even if formatter gives errors, therefore can you check the file and see what is wrong and fix it in the template.
The file will still be generated even if the formatter reports errors, so that you can check the file and see what is wrong and fix it in the template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:rep/large Large amount of reputation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants