-
Notifications
You must be signed in to change notification settings - Fork 16
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 filewalks #32
base: master
Are you sure you want to change the base?
add filewalks #32
Conversation
But you already have Code looks Ok but still... |
@juancarlospaco no, you missed the discussion, addition of globs to the stdlib was rejected because for this module it makes more sense to put it into Fusion. See nim-lang/Nim#15598 |
@Yardanico https://nim-lang.github.io/Nim/globs.html |
@juancarlospaco seems like a bug though, it wasn't merged. You can see that it's not in https://github.com/nim-lang/Nim/tree/devel/lib/std |
this is from lib/std/private/globs.nim which I had added in nim-lang/Nim#14501 for kochdocs, it's in private hence not intended for public use, just like
since it's not public and I started relying on it from outside (in fusion in #24 do add doc generation to fusion) as well as for future intended use, it was time to make it a proper module, hence my original attempt to add it to stdlib here nim-lang/Nim#15598. Note that making it a separate nimble project (or using pkg/globs) would not allow using it in either kochdocs nor from within fusion. I wrote this because the existing See also design discussion and comparison against pkg/globs in nim-lang/Nim#15598, it was designed with pkg/globs in hindsight. walkFiles is designed to be both simple to use yet general and flexible enough to fit most use cases thanks to optional callbacks. |
ping @Araq ; generally useful and would help with things like nimgrep (eg nim-lang/Nim#15962 (comment)) which now has to change to slightly slower closure iterators to avoid code bloat from multiple yields as well as in other places, eg would avoid the ugly |
LGTM 👍 |
fcc3e1c
to
b129155
Compare
PTAL, rebased for conflict bitrot |
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.
PTAL
replying to @Araq nim-lang/Nim#16709 (comment)
there is precedent in stdlib, eg sequtils.filter:
that's not what for e in walkPaths(src):
if e.path.lastPathPart != ".git": doSomeWork(e) this would be very inefficient as it'd recurse down ".git" only to be filtered out later by the iterator body.
I intentionally did not include a
that would give a crippled, foreign-looking API, that doesn't interoperate with stdlib, eg: import std/[sequtils,sugar]
let s1 = toSeq(walkPaths(dir))
let s2 = collect: (for e in walkPaths(dir): e.path) with a proc, this wouldn't work. Likewise, iterator allows the usual break/continue/return/yield control flow, a proc doesn't (nim-lang/Nim#15655 is a separate topic).
that's already the case in this PR (and was also the case in the stdlib version of this PR nim-lang/Nim#15598) |
So... how this is going ?. |
@Araq this should be moved back to a PR against stdlib (as was intially the case refs nim-lang/Nim#15598). This is 100% stdlib territory, general purpose enough, and would benefit existing code in tools/ and elsewhere that reimplement this (poorly, with duplicate yield and worse API) The main thing missing in this API is resumable error handling (via a callback to handle IO errors), but this can be done in followup work. |
The API is alien, we use named parameters instead of the "object builder" pattern. It's also not clear to me why "sorting" is important, looking at https://docs.python.org/3/library/glob.html for a comparison I see none of these shenanigans. Also, ideally new APIs embrace the
For me it's the one problem of the old API that is worth solving. |
just replying on this point for now, will followup with other points later:
because it's easy to support efficiently in the iterator (as i did) with O(N) space where N=max entries per dir, impossible to support efficiently in the callee (it'd require O(P) where P = total number of files/dirs listed recursively), and most of all because it's useful; a quick google search reveals people keep searching for this (with bad solutions, involving having to first get all results and then sort) here's a post from today:
(although that person talks about walkDir, where caller can easily solve this with a toSeq.sorted, the main problem is recursive listing) |
That's convincing, thanks. However, we could simply always enable it and document that it does sort. |
migrated from nim-lang/Nim#15598 (refs nim-lang/Nim#15598 (comment))
(and yes, people care about walking at CT, eg see recent https://forum.nim-lang.org/t/6984)
links