Skip to content

Add haskell exercises' dependency control. #159

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

Merged
merged 2 commits into from
Jun 27, 2016
Merged

Add haskell exercises' dependency control. #159

merged 2 commits into from
Jun 27, 2016

Conversation

rbasso
Copy link
Contributor

@rbasso rbasso commented Jun 22, 2016

Install three files:

  • dependencies.txt - List of dependencies for all Haskell sources.
  • dependencies - Shell script to query dependencies.
  • stackalize - Shell script to convert an exercise in a stack project.

Sample usage:

$ dependencies go-counting
array
base
containers
HUnit

$ dependencies `ls exercises`
array
attoparsec
...
time
vector

$ dependencies --only-in-examples `ls exercises`
attoparsec
lens
..
split
stm

$ cd exercises/leap
$ stackalize --resolver lts-6.4
...
$ stack test
$ stackalize --undo

Closes #151

@rbasso
Copy link
Contributor Author

rbasso commented Jun 22, 2016

This may not be the best dependency control system designed by humankind, but I expect it to work well enough, and it's better to have something than nothing. 😄

stackalize is in the pack because it depends on dependencies, and it is the simplest way I found to get a running environment to run the tests and check if the dependencies are correctly specified. It also makes very easy to test locally against multiple GHC versions before committing.

@rbasso
Copy link
Contributor Author

rbasso commented Jun 23, 2016

The dependency-list for each of the exercises was successfully tested in individual stack projects with Travis, using lts-2.22 (ghc-7.8.4), lts-6.4 (ghc-7.10.3) and nightly-2016-06-21 (ghc-8.0.1). The dependencies of tests and examples were specified and tested independently, so they can be regarded as correct.

@petertseng
Copy link
Member

Perhap I'll have to grab Stack and play around with it this weekend to try out the effects of this for myself. I can reason about bash well enough to understand what's here though.

One interesting question I had is - we would want to note somewhere that adding a new exercise to this track will also want the dependencies added to dependencies.txt, right? Unless I missed a way to automatically populate that file

exit 1
else
mkdir .extraFiles &&
mv * .extraFiles &&
Copy link
Member

Choose a reason for hiding this comment

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

hmm, would you explain to me what happens if not moving files to here? What would break? Maybe worth a comment here, unless you think it's obvious to anyone who knows what they doing (I certainly don't with Stack, I know)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, you need to know that this is not the best example of bash scripting in the world. It's just something that I improvised to solve this problem. 😄

What the script does is:

  • move everything to .extraFiles, so we get a known directory struture.
  • move from there the example and test files to their correct locations.
  • generate a stack.yaml with the provided resolver.
  • generate a package.yaml (simpler than a .cabal file) with the correct dependencies.

It can centainly be improved, but It's been 17 years since the last time I played with bash as a sysadmin. Let's say it works under normal conditions. 😁

About your question, if there are additional source files in the directory, as in forth and zipper, they could be included accidentally in the project and break the build. Also, I wanted to be able to unstackalize the project, moving everything back to their places.

Copy link
Contributor Author

@rbasso rbasso Jun 23, 2016

Choose a reason for hiding this comment

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

If you think these scripts deserve a complete rewrite, fell free to change anything. I just need a way to assemble the project.

I did this in bash so it could run without additional dependencies. That's convenient for Travis.

Copy link
Contributor Author

@rbasso rbasso Jun 24, 2016

Choose a reason for hiding this comment

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

Added the comments explaining the move to .extraFiles. Thanks again! 😄
Now working on the README.md.

@rbasso
Copy link
Contributor Author

rbasso commented Jun 23, 2016

You are correct, @petertseng.

It is, in fact, impossible to automatically populate the dependencies, so that would demand an update to the README.md explaining to the contributors that the file must reflect the dependencies.

It's a way to enforce good discipline and minimize maintenance. It would also allow reproducible build environments for contributors.

If in the future we move to stack based tests, Travis will check for correctly specified dependencies automatically.

Install three files:

- dependencies.txt  List of dependencies for all Haskell sources.
- dependencies      Shell script to query dependencies.
- stackalize        Shell script to convert an exercise in a stack project.

Sample usage:

$ dependencies go-counting
array
base
containers
HUnit

$ dependencies `ls exercises`
array
attoparsec
...
time
vector

$ dependencies --only-in-examples `ls exercises`
attoparsec
lens
..
split
stm

$ cd exercises/leap
$ stackalize --resolver lts-6.4
...
$ stackalize --undo
@rbasso
Copy link
Contributor Author

rbasso commented Jun 24, 2016

Added a new README.md with some instructions for contributors on how to use stack.

Also updated the list of packages and included a small section mentioning dependency control.

Major rewrite:
- Update list of used packages.
- Add instructions on how to use Stack.
- Add instructions on dependency control.
@rbasso
Copy link
Contributor Author

rbasso commented Jun 27, 2016

Considering that this PR only adds functionalities and updates an outdated documentation file, there is no risk in merging it now, even if there are some problem with the scripts we are not catching until now.

This way we can at least keep the dependency list updated and start testing #162.

@rbasso rbasso closed this Jun 27, 2016
@rbasso rbasso reopened this Jun 27, 2016
@rbasso rbasso merged commit f8d43d6 into exercism:master Jun 27, 2016
@petertseng
Copy link
Member

I'm late to the show but you correctly determined you didn't need to wait for me. And I would have said 👍 anyway.

@rbasso rbasso deleted the add-dependency-control branch July 1, 2016 00:26
rbasso pushed a commit that referenced this pull request Jul 3, 2016
* bootstrap: Use dependencies.txt to list packages

Thanks to #159, we have a list of dependencies of each exercise. We
should replace the current hard-coded list in `bootstrap.sh` with one
inferred from `dependencies.txt`.

Closes #175
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

discussion: Tracking dependencies (update README.md to include package "lens").
2 participants