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

[TODO] getCurrentPkgDir: Returns the path to the closest enclosing nimble package dir #10530

Closed

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Feb 2, 2019

getCurrentPkgDir(dir), getCurrentPkgDir(): Returns the path to the closest enclosing nimble package dir.

This enables referring to current nimble package without interference from potential other nimble packages already installed with same name (eg a different version).

Suppose we have a nimble package (ie containing /pathto/nim-myjester/jester.nimble)
in /pathto/nim-myjester/bar/baz.nim:

import os
proc main()=
  static: doAssert getCurrentPkgDir() == "/pathto/nim-myjester"
  static: doAssert getCurrentPkgDir("/pathto/nim-myjester/bar/baz.nim") == "/pathto/nim-myjester"
main()

example use cases

# reliable way to access a specific file inside a nimble package regardless of where calling module is located inside nimble pkg
const file = getCurrentPkgDir() / "foo.txt"
# in combination with https://github.com/nim-lang/Nim/pull/10527:
importInterp getCurrentPkgDir() / "foo/bar"

note:

added [backport] as I'd like to have this in next release (19.6) in case there's such a release

@timotheecour timotheecour changed the title Pr get current nimble pkg path getCurrentPkgDir: Returns the path to the closest enclosing nimble package dir Feb 2, 2019
@timotheecour timotheecour force-pushed the pr_getCurrentNimblePkgPath branch 2 times, most recently from 365564d to 42719b5 Compare February 3, 2019 22:53
@Araq
Copy link
Member

Araq commented Feb 6, 2019

This enables referring to current nimble package without interference from potential other nimble packages already installed with same name (eg a different version).

I don't see how this interference could happen. We have nimble develop and well, versions, a build should use the latest version. But let's assume the interference does happen. Is this a feature patching over a Nimble bug/misdesign? Do we then go on and add a tiny flag to getCurrentPkgDir() later? Or maybe getNimblePkgDir("jester")? I mean, it enables a feature, can't be bad right...

@Araq
Copy link
Member

Araq commented Feb 8, 2019

Rejected. New features should have an RFC anyway.

@Araq Araq closed this Feb 8, 2019
@timotheecour timotheecour changed the title getCurrentPkgDir: Returns the path to the closest enclosing nimble package dir [TODO] getCurrentPkgDir: Returns the path to the closest enclosing nimble package dir Feb 10, 2020
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.

2 participants