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

add os.absolutePath; fixes #8174 #8213

Merged
merged 4 commits into from
Jul 10, 2018
Merged

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Jul 5, 2018

fixes #8174

NOTE: see #8174 and https://forum.nim-lang.org/t/4004 for prior discussion.
absolutePath would be best put in ospaths but nim doesn't support circular dependencies (yet...).

An alternative would've been to split in 2:

# in ospaths:
proc absolutePath*(path: string, base: string)
# in os:
proc absolutePath*(path: string)

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 call getCurrentDirbut just calls absolutePath in his code (something nim could improve on IMO )

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=
Copy link
Member

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

Copy link
Member

@Araq Araq Jul 6, 2018

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".

Copy link
Member Author

@timotheecour timotheecour Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@timotheecour
Copy link
Member Author

PTAL

lib/pure/os.nim Outdated
try:
let a = absolutePath("a", "b")
doAssert false, "should've thrown"
except:
Copy link
Contributor

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.

Copy link
Member Author

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!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dom96 just wrote #8237 in response to your comment

Copy link
Member Author

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

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@timotheecour
Copy link
Member Author

@dom96 PTAL

lib/pure/os.nim Outdated
else:
if not root.isAbsolute:
# CHECKME: is that the correct exception type?
raise newException(ValueError, root)
Copy link
Contributor

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: "

Copy link
Contributor

@dom96 dom96 left a 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.

@dom96
Copy link
Contributor

dom96 commented Jul 10, 2018

I'm guessing that the test failure is unrelated.

@dom96 dom96 merged commit 25bf0d1 into nim-lang:devel Jul 10, 2018
@timotheecour timotheecour deleted the pr_abspath branch July 10, 2018 20:18
@timotheecour
Copy link
Member Author

I'm guessing that the test failure is unrelated.

=> filed #8267

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.

missing ospaths.absolutePath function to get absolute path from a path
3 participants