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

Make examples work from any subdirectory #11

Open
joseluis opened this issue Apr 30, 2021 · 4 comments
Open

Make examples work from any subdirectory #11

joseluis opened this issue Apr 30, 2021 · 4 comments
Labels
low priority This issue or pull request is low on priority

Comments

@joseluis
Copy link

joseluis commented Apr 30, 2021

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
Copy link
Owner

gp-97 commented Apr 30, 2021

@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
Copy link
Author

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
Copy link
Owner

gp-97 commented Apr 30, 2021

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
Copy link
Author

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.

@gp-97 gp-97 added the low priority This issue or pull request is low on priority label May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority This issue or pull request is low on priority
Projects
None yet
Development

No branches or pull requests

2 participants