-
Notifications
You must be signed in to change notification settings - Fork 1k
replace versionInworkspace() stub #27
replace versionInworkspace() stub #27
Conversation
aaawesome, glad to see this move. a few things to consider here:
maybe we just ignore these entirely. maybe we put in a general disclaimer note to the user that such things will trip up the init importer. |
added some initial tests |
so this is big because i added tests |
|
||
func newContext() *ctx { | ||
// this way we get the default GOPATH that was added in 1.8 | ||
buildContext := build.Default |
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.
Why the additional assignment?
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.
build.Default is calling a function https://github.com/golang/go/blob/master/src/go/build/build.go#L257
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.
OK, but build.Default
is the value returned from that function call, not itself a function, so this seems unnecessary?
Or is this a way of guarding against an out-of-order initialization problem, since both of these assignments end up being made as a result of function calls on package var init?
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 was more trying to protect us, if we wanted other things from buildContext, from re-calling that function
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.
OK, nbd anyway, it's really just a nit. The thing actually worth discussing is the gopath/splitlist stuff, i think
case "github.com/termie/go-shutil": | ||
return gps.NewBranch("master").Is("4239b77079c7b5d1243b7b4736304ce8ddb6f0f2"), nil | ||
func (c *ctx) versionInWorkspace(root gps.ProjectRoot) (gps.Version, error) { | ||
pr, err := c.absoluteProjectRoot(string(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.
So, I realize you're just doing a a 1:1 change from before, but by moving these methods onto the ctx object, it seems like we need to do away with the loop over all the possible GOPATH workspaces. Instead, we should do it in newContext()
, and pick exactly one GOPATH to use then and there, based on the current working directory.
That way these method calls will always and only search the one workspace, which I think is our desired behavior for all the methods on there.
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.
That'd also let us do away with the second return param from determineProjectRoot
, as that state would be carried in the ctx object itself.
return nil, errors.Wrapf(err, "determine project root for %s", root) | ||
} | ||
|
||
repo, err := vcs.NewRepo("", string(pr)) |
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.
Hah...I'm glad an empty first param works. I don't think they'd ever anticipated it, but if it does...awesome.
|
||
func TestIsStdLib(t *testing.T) { | ||
tests := map[string]bool{ | ||
"github.com/sirupsen/logrus": false, |
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.
supernit: s/sirupsen/Sirupsen/
(i think he actually switched his own nick to be uncapitalized recently, but we should be consistent in how we refer to it in the tests)
gopath := os.Getenv("GOPATH") | ||
for _, gp := range filepath.SplitList(gopath) { | ||
posspath := filepath.Join(gp, "src", path) | ||
f, err := os.Stat(posspath) |
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'd make an isDir function for this
return nil, errors.Wrapf(err, "finding current branch/version for root: %s", pr) | ||
} | ||
|
||
sha, err := repo.Version() |
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.
maybe 'rev' ?
|
||
func TestInit(t *testing.T) { | ||
// test must also have external network | ||
if _, err := exec.LookPath("git"); err != nil { |
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.
maybe we need a needsGit method at some point
// | ||
// The second returned string indicates which GOPATH value was used. | ||
// TODO: rename this appropriately | ||
func (c *ctx) determineProjectRoot(path string) (string, string, error) { |
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.
These should be colocated with the ctx type declaration.
func getSourceManager() (*gps.SourceMgr, error) { | ||
gopath := os.Getenv("GOPATH") | ||
if gopath == "" { | ||
func (c *ctx) getSourceManager() (*gps.SourceMgr, error) { |
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.
rename 'sourceManager'
tg.setenv("GOPATH", tg.path(".")) | ||
depCtx := &ctx{GOPATH: tg.path(".")} | ||
|
||
importPaths := map[string]bool{ |
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 also have a case for a file where a dir is expected, or something. if that's possible
@@ -70,6 +72,39 @@ func TestIsStdLib(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestVersionInWorkspace(t *testing.T) { | |||
// test must also have external network | |||
if _, err := exec.LookPath("git"); err != nil { |
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.
another usage for that helper
Signed-off-by: Jess Frazelle <[email protected]>
Signed-off-by: Jess Frazelle <[email protected]>
Signed-off-by: Jess Frazelle <[email protected]>
Signed-off-by: Jess Frazelle <[email protected]>
Signed-off-by: Jess Frazelle <[email protected]>
Signed-off-by: Jess Frazelle <[email protected]>
Signed-off-by: Jess Frazelle <[email protected]>
Moved all functions that use ctx to context.go Created a test helper for `needsGit` and `needsExternalNetwork` Added a test case for `absoluteProjectPath` to make sure a file will error out Renamed `getSourceManager` to `sourceManager` Signed-off-by: Jess Frazelle <[email protected]>
Addressed all comments except this one: #27 (comment) which I'm hoping in pairing with Sam tomorrow I can get an idea of what he's thinking :) |
IMO we can merge and fix in pairing tomorrow - no need to bloat this PR more :) |
sweet yeah thats what I was hoping for figured we could just do it together real fast |
fix #21