-
Notifications
You must be signed in to change notification settings - Fork 1k
Ignore dot-prefixed files and subdirs when scanning packages #551
Ignore dot-prefixed files and subdirs when scanning packages #551
Conversation
fillPackage is supposed to use the AST parser on individual files. Unforntunately, `filepath.Glob("*.go")` returns directories as well as files. Fixes golang#550
I recognize that an extra filestat is not the greatest for every file in the user's project. If there's somewhere higher level we can filter these out, I'm all ears. |
internal/gps/pkgtree/pkgtree.go
Outdated
@@ -203,6 +203,12 @@ func fillPackage(p *build.Package) error { | |||
if filepath.Base(file)[0] == '_' { | |||
continue | |||
} | |||
|
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.
Any file that starts with .
, _
or called testdata
should be ignored when scanning source directories. Rather than this check, extend the check on line 203 to check for `== '.'.
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.
Sounds good! Is this documented somewhere?
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, that still leaves us open to the case where somebody names a directory "foo.go" inside their project. Perhaps we should handle that case separately, or at least give them a more helpful error message?
@sectioneight a package declaration cannot contain
|
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.
Ah yes, this is a definite improvement - thank you! 🎉
NOTE: Current implementation is still problematic if somebody has a subdir in their project that ends in ".go"
I'm not immediately seeing the problem. That function you're modifying is only responsible for deciding which files to examine; the closure inside ListPackages()
is what determines which directories to visit. Seems to me the change you've made should exclude a dir ending in .go
from being tokenized incorrectly, but won't affect traversal into the dir.
Could you provide details on the case you see as problematic?
@@ -1280,6 +1280,11 @@ func TestListPackages(t *testing.T) { | |||
}, | |||
}, | |||
}, | |||
"skip directories starting with '.'": { | |||
fileRoot: j("dotgodir"), |
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.
Let's also add e.g. a foo.go
dir to accompany the .go
dir, so that we're testing both the dot-led and the dir-ending-in-.go case.
ah perfect, i crossposted my review with the fix you just made 😄 |
Yes, I recognize this is a bit of an edge case, but it's one I ran into internally when trying to build an internal project with |
continue | ||
} | ||
|
||
// Skip any directories that happened to get caught by glob |
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.
delete this code, its not needed now.
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 think it still is - in the event of e.g. a directory named foo.go
(as the latest commit introduces). no?
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.
It still is. My comment about "NOTE: this doesn't handle directories" no longer applies, as demonstrated by the attached test case.
foo.go is a valid directory name.
…On Thu, May 11, 2017 at 11:38 AM, sam boyer ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In internal/gps/pkgtree/pkgtree.go
<#551 (comment)>:
> continue
}
+
+ // Skip any directories that happened to get caught by glob
I think it still is - in the event of e.g. a directory named foo.go (as
the latest commit introduces). no?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#551 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAcA0fmGa2YTaSYIiM303sWjYzLxR2cks5r4mZ4gaJpZM4NXQT2>
.
|
@davecheney are you saying that you'd like to modify this PR such that if we encounter a directory ("foo.go") we recurse into it? |
@sectioneight sort of. I'm saying that the go tool does not treat directories that end in
|
To be sure, it's a dumb idea, but not forbidden by the tool. |
Ok, sounds like |
guys guys, i addressed this in my earlier review comments 😄 skipping a dir named |
Aha, excellent point :) |
Though, given the discussion here, it probably would be worth adding some real |
Any concerns about the |
@sdboyer sounds good, will do |
🎉 🎉 🎊 🕺 🎉 😄
Yes, it is a bit concerning; this is a hotpath, and we've already got #419 open to swap in a faster alternative to However, it's fine for the purposes of this PR, as I think the best fix for it here may be, in #419, to have the replacement walker be responsible for injecting the results of a platform-sensitive, possibly-faster So, I'm fine with it, as it brings us closer to existing tool behavior, and we have a concrete path to removing the performance regression. /cc @jstemmer - fyi, since you're looking at #419, here's a bit of an evolved requirement 😄 |
just a license header, now |
Ok, I think we're all good now, performance considerations aside. Let me know if that's something I can help with -- I'm interested in moving my company to |
looks good, thank you! and yayyyy first contribution! 🎉 |
@sectioneight also, with any luck, it'll be reasonable to begin exploring moving your company to dep in earnest on Monday, once we stabilize the manifest and lock. 😄 re: things you could help with; TBH, i've been kicking the performance can down the road for a while. #67 lays out my basic mental roadmap for it, and why I've been vaguely OK with doing so (basically, there's a ton of headroom and a clear path to improvement, albeit with some now-mostly-cleared blockers). #289 is the meta issue for performance, and #431 is now the big ticket item there. Not in the meta-issue, though, is establishing some broader benchmarks that might help us to identify performance regressions. If you're interested in that sort of thing, that'd be cool - open up an issue and we can brainstorm about what that might look like 😄 On a different front, I haven't forgotten about the use case you raised last year in Masterminds/glide#372. I'm still finding it to be a problem for the same basic reason - how arbitrary changes to source URLs affect generated file portability, and how we cope with that - though it's been discussed in somewhat greater detail in #174. At this point, I'm inclined to say that we might be best off having a toggle that basically causes the system to reach out to a go get metadata-like service the first time (per run) it encounters every URL in order to get a rewritten one. If you wanted to work on hammering something like that out, it'd also be super helpful 🎉 |
Ya, one of the reasons I wanted my team to get involved early is to make sure we can come up with an amenable "rewrite" / airgap solution that works for us as well as the community. I'm going to pick off a few smaller tasks and then will see if I can look into perf. |
Also big +1 on your idea, it would be trivial to stand up a metadata service internally and distribute a file to engineers computers in a well-known location that points to said server, where we can have control over rewrites rather than ending up in massive TOML files |
FYI I opened golang/go#20337 for clarity on what the correct behavior should be for scanning directories. As far as I can tell this is the first tool (that I've used, at least) that ignores imports starting with "." or "_", and the documentation is unclear since it only talks about files. Depending on the response there we may want to rejigger the code so that it doesn't ignore dot-dirs: dep/internal/gps/pkgtree/pkgtree.go Lines 81 to 86 in 5540a42
|
As with the rest of the toolchain, according to @davecheney, we should ignore
_
and.
prefixed files as well as all directories infillPackages
which assumes it's working on a single directory.Fixes #550