-
-
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
add os.absolutePath; fixes #8174 #8213
Conversation
lib/pure/os.nim
Outdated
@@ -296,6 +296,18 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} = | |||
else: | |||
if chdir(newDir) != 0'i32: raiseOSError(osLastError()) | |||
|
|||
proc absolutePath*(path: string, root = getCurrentDir()):string= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: use a space after the colon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should have documentation and "runnable examples".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
PTAL |
lib/pure/os.nim
Outdated
try: | ||
let a = absolutePath("a", "b") | ||
doAssert false, "should've thrown" | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, assertion failures are not catchable. You should raise an exception instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually that try/catch was buggy independently of the fact that assertion failures are not catchable; will fix; thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should raise an exception instead
done
lib/system.nim
Outdated
runnableExamples: | ||
doAssertRaises(ValueError): | ||
raise newException(ValueError, "Hello World") | ||
## specified exception. Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: once #8245 is merged, this diff will disappear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@dom96 PTAL |
lib/pure/os.nim
Outdated
else: | ||
if not root.isAbsolute: | ||
# CHECKME: is that the correct exception type? | ||
raise newException(ValueError, root) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exception type seems fine, but the error message is poor. You need something like "The specified root
is not absolute: "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mergeable once tests pass.
I'm guessing that the test failure is unrelated. |
=> filed #8267 |
fixes #8174
NOTE: see #8174 and https://forum.nim-lang.org/t/4004 for prior discussion.
absolutePath
would be best put inospaths
but nim doesn't support circular dependencies (yet...).An alternative would've been to split in 2:
but that's uglier (and less DRY).
Another alternative would've been to add fwd reference of
getCurrentDir
in ospaths but that causes link errors in case user doesn't explicitly callgetCurrentDir
but just callsabsolutePath
in his code (something nim could improve on IMO )