-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Flexible import syntax #10527
Flexible import syntax #10527
Conversation
6eb747b
to
83c092a
Compare
83c092a
to
98ca491
Compare
Can't this be done by simply adding the package root to the search path, or does that have some drawback that I'm missing? Prefixing every import from the local package with I don't think an additional syntax for imports belongs in the stdlib. This would be better as a nimble package. |
noone's forcing you to, and it's not needed for sibling files, eg: # this is fine:
import ./foo/bar
# ditto
import "." / foo/bar
# this is awkward and error prone:
import ../../../foo/bar
# this one can pickup the wrong file depending on what's in nimble path (you may not want to do global changes to nimble eg in case other uses processes rely on a given pkg configuration)
import regex/foo/bar
# this one can be used in this case instead (but noone's forcing you to)
import getCurrentPkgDir() / "foo/bar"
# note: there are other use cases, eg:
const binDir = getCurrentPkgDir() / "bin" # do something with binDir |
98ca491
to
b435cea
Compare
Yes, you have to "know" how many '..' to add and if your directory hierarchy is not a deeply nested mess, it's not hard to know. And if it is a deeply nested mess, maybe you should use fewer subdirectories. |
Opinion, not an issue. |
Flexible import syntax, allowing to import a path (or multiple paths) computed at compile time from an expression, instead of standard import which requires a litteral.
getCurrentPkgDir
from [TODO] getCurrentPkgDir: Returns the path to the closest enclosing nimble package dir #10530: