gp-97 / generative

Generative arts library in Rust
Apache License 2.0
21 stars 1 forks source link

Make examples work from any subdirectory #11

Open joseluis opened 3 years ago

joseluis commented 3 years ago

Since their output path is currently hardcoded, they fail when run outside the project's root.

I've created a proof-of-concept in PR #12 that enables them to be run from anywher inside the project.

This could also be applied to the integration tests. But in that case it may be more convenient to put the path() function in a common module instead of repeating it on each file.

gp-97 commented 3 years ago

@joseluis, thanks for the wonderful suggestion, but the main purpose of examples, according to me, is for people to look at the code usage and run it via cargo's functionality.:

cargo run --example <example name>

The examples aren't supposed to be run from outside the library, and that's why the paths are hard coded in the examples..

joseluis commented 3 years ago

yes, that doesn't change. The thing is if you run that command from the examples folder they fail because the output path can't be found.

having said that, it's ok if you prefer the way it is now, so feel free to close the issue & pr.

gp-97 commented 3 years ago

Correct me if I am wrong, but the command:

cargo run --example <example name>

is supposed to be run from the libray root and not from the examples folder, right?

Also I surely like your suggestion but implementing it is currently not high on my priority, but in the future I would like to return back to it.

joseluis commented 3 years ago

Well, cargo commands for building, running, checking, testing, etc. can be run from the root or from any subdirectory inside the project. That's also how git works.

That changes if there's an assumption of the calling path, like in this case, from inside the examples code.

there's no standard solution for this conflict of assumptions that can be confusing when looking at a project for the first time, only mitigations in the form of better error messages, specify how examples are supposed to be run in the readme, or add some boilerplate like in this PR.