-
-
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
fix issue #8268 (joinPaths); add lots of tests and make use of use runnableExamples #8351
Conversation
cbc9e4d
to
fc1ffb0
Compare
Why is normalizePathEnd public? Even if required by other procedures in the os module, it seems somewhat niche. |
faf723e
to
ec3ea7b
Compare
lib/pure/ospaths.nim
Outdated
doAssert joinPath("usr///", "//lib") == "usr/lib" ## `//` gets compressed | ||
doAssert joinPath("//", "lib") == "/lib" ## ditto | ||
when defined(Windows): | ||
doAssert joinPath("""C:\foo""", """D:\bar""") == """C:\foo\bar""" |
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.
Should be able to swap the triple quotes out for raw strings:
doAssert joinPath(r"C:\foo", r"D:\bar") == r"C:\foo\bar"
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, thx for the tip!
lib/pure/ospaths.nim
Outdated
## assert joinPath("usr/", "/lib") == "usr/lib" | ||
## If ``tail`` is absolute or ``head`` is empty, returns ``tail``. If | ||
## ``tail`` is empty returns ``head``. Else, returns the concatenation with | ||
## normalized spearator between ``head`` and ``tail``. |
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.
typo: spearator
-> separator
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
27aca68
to
16eebf9
Compare
I think it's useful, I would want to use it in my code |
16eebf9
to
f79a016
Compare
PTAL, now green |
@dom96 What are your thoughts? Aside from my thoughts on |
lib/pure/ospaths.nim
Outdated
@@ -157,64 +158,173 @@ const | |||
## The character which separates the base filename from the extension; | |||
## for example, the '.' in ``os.nim``. | |||
|
|||
# TODO: MOVE to strutils, sequtils, or algorithms | |||
proc countWhile*(str: string, pred : proc(a:char):bool, prefix = true): int = |
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 can use parseutils.parseWhile
for this, or just str.len-str.replace("/", "").len
If you want more complicated counting then just use a for loop...
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.
parseWhile
is not as flexible (eg I need arbitrary lambda; and I need to go from both ends).
str.len-str.replace("/", "").len
won't work with my other usages of countWhile
.
If you want more complicated counting then just use a for loop...
countWhile
leads to simpler code
lib/pure/ospaths.nim
Outdated
return lenS | ||
|
||
# TODO: once slices are supported, define instead `rootPrefix` | ||
proc rootPrefixLength*(path: string) : int = |
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.
Once slices are supported? Just return the prefix and call len
on it.
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.
rootPrefixLength
avoids allocating. If/when we have slices, this wouldn't be a problem; until then it is.
doAssert r"C:".rootPrefixLength == 2 | ||
doAssert r"C:\foo".rootPrefixLength == 3 | ||
doAssert r"//foo".rootPrefixLength == 2 | ||
doAssert r"C:\\foo".rootPrefixLength == 4 |
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.
As far as I'm concerned this is abusing runnableExamples
as exhaustive testing again. Examples should be one or two (one per platform). Not a long list of edge cases.
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.
fixed; moved out from runnableExamples
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.
fixed; moved out of runnableExamples
lib/pure/ospaths.nim
Outdated
if path[0] == ':': | ||
result = 0 | ||
else: | ||
result = countWhile(path, a => a != ':') |
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.
Is macos
pre-mac-os-x only? If it covers latest macOS then this looks wrong to me.
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.
IIRC macos
is the legacy classic Mac, macosx
is, well, Mac OS X. This is kind of confusing though because since 10.12 Sierra they rebranded it as macOS.
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.
yeah, this is far too confusing.
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.
what is too confusing? the code in PR or macos
? I already suggested removing support for macos
https://forum.nim-lang.org/t/4039 "should we keep supporting macos? (as opposed to macosx)"
lib/pure/ospaths.nim
Outdated
doAssert "/".isAbsolute | ||
doAssert(not "a/".isAbsolute) | ||
when defined(Windows): | ||
doAssert "C:\\foo".isAbsolute |
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.
Too many examples here too.
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.
fixed
## assert joinPath("", "lib") == "lib" | ||
## assert joinPath("", "/lib") == "/lib" | ||
## assert joinPath("usr/", "/lib") == "usr/lib" | ||
## If ``tail`` is absolute and ``absOverrides`` is true, or ``head`` is empty, |
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.
I'm not really sure about the use case for this.
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.
rationale is given in #8268 : most languages use the behavior absOverrides=true whereas before this PR nim was using the equivalent of absOverrides=false; so with this PR, 0 code is broken but user has option of using absOverrides=true
I also think that |
All in all there is too much going on here. I would prefer if you just created a simple PR that fixes the underlying issue instead of introducing two new procedures into the mix, which as far as I'm concerned are not needed. I'm pretty sure for most purposes |
doesn't work with
I have other upcoming PR's that fix pre-existing bugs with ospaths that rely on I'm willing to address the comments that make sense to me:
but I'm not ok with removing these helpers. Let me know if you want me to go ahead with this plan otherwise I'll just apply these fixes in a private library and someone else can fix these issues in ospaths (there are many, see a list #8177 + others I haven't reported). |
I'm not ok that you have to rewrite large parts of mostly working code with your own ideas of how things should be done in Nim/D and leaving a track record of well meaning, but time-consuming RFCs/proposals as a side effect that take away from our manpower. I really appreciate your help, but if in the end your help makes us all more unproductive than we were before, I have to decline it. Let's assume Your way of working: Write 20 RFCs instead, half of them about perceived more general language deficiencies. And here is the bad part of it: More/different language features just move problems around most of the time. For example, I don't want to use D's superior const system, I know from experience it's not worth it, given its complexity, it doesn't find enough real bugs. (Same holds for Nim's |
c07b318
to
6e3be1e
Compare
6e3be1e
to
924c963
Compare
138c550
to
73c2851
Compare
73c2851
to
ddc6850
Compare
/cc @Araq PTAL
PS: I'm not gonna attempt defending my POV and instead will focus here on moving forward with this PR |
Needs to be redone, |
/cc @dom96
absOverrides
tojoinPath
(by default, same behavior as before so no breaking change)normalizePathEnd
(also useful in other places, can be refactored later)countWhile
androotPrefixLength
(simplifies and fixes a lot of code)eg motivation
joinPath(foo, bar)
is often a bug whenbar
is absolute, for eg:nimterop/nimterop@a8bb2dc#r31391178