Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Use gps.SourceManager instead of *gps.SourceMgr in cmd/dep #353

Merged
merged 1 commit into from
May 9, 2017

Conversation

spenczar
Copy link
Contributor

@spenczar spenczar commented Mar 28, 2017

This is a refactor that shouldn't change behavior. It just gets package main to use interfaces instead of concrete implementations for SourceManager.

The idea here is to make it easier to write tests that mock the source manager's behavior. I have some tests of the status command I'd like to write to get it to support the required field.

@@ -0,0 +1,23 @@
package main
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not very certain about this file. HandleSignals and Release are methods on *SourceMgr that aren't defined in the SourceManager interface, but which are used by commands. They seem pretty concrete, so I figured these interface assertions might be an okay way forward. I'm interested in feedback.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I was sloppy with these bits. OK, so...

Release() is something that should be promoted into the SourceManager interface. I'm fine with the idea that any SourceManager should necessarily have a lifecycle. There's no way they can do the job promised by the interface without doing state management (unless they're just mocks), so there's no sense in omitting lifecycle methods from the interface.

HandleSignals is something I'm still shifting on, though. Per #160, having the library set up and do the signal handling itself isn't exactly ideal, even if it is triggered by the caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd move Release() into the interface, but the interface lives in gps. Maybe this should just wait for #300 to get resolved? I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

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

Nah, we can just do it as a separate PR against gps right now. No problem there.

context.go Outdated
VersionInWorkspace(root gps.ProjectRoot) (gps.Version, error)

// Returns the root directory where packages can be found.
Root() string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm extreeeeeemely uncertain about this method. cmd/dep/init.go wanted to use ctx.GOPATH directly, but I'm not really certain why. It seemed like it was trying to find the local filepath to a project in GOPATH. Maybe there's a new method we could add to BuildContext that better encapsulates that use case.

Copy link
Member

Choose a reason for hiding this comment

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

Eh...I could be convinced of one for facilitating searching for directories, but I don't think having this Root() method adds much value. We don't want to rename this away from GOPATH, because that's what people already think of wrt "a space on disk where your source packages are kept"; a new name would just add confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I agree. I was trying to do the minimal change for the first set to submit for PR.

I think some sort of search-gopath-for-a-project method seems right.

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

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

In general, I think this is a worthwhile abstraction. But there's a lot of details here to work out, first.

Rather than going forward iteratively in a PR, could you open an issue to make a proposal about what the scope of responsibilities should be here?

context.go Outdated
@@ -16,14 +16,41 @@ import (
"github.com/sdboyer/gps"
)

type BuildContext interface {
Copy link
Member

Choose a reason for hiding this comment

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

I like the principle here, but IMO DepContext is preferable to BuildContext, as we're not really building anything here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, BuildContext doesn't seem right. I don't love how DepContext stutters the package name (dep.DepContext). Is just Context okay? That's also pretty vague.

Most of the operations here are filesystem operations, apart from SourceManager(). Is there something we could call it related to that? I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm not a fan of that aspect, either. I considered plain Context; while it is what go/build does, that was also before the context package became a thing. Seems like it dominates that naming now, and I didn't have an alternative, sooo... 😄

@@ -0,0 +1,23 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I was sloppy with these bits. OK, so...

Release() is something that should be promoted into the SourceManager interface. I'm fine with the idea that any SourceManager should necessarily have a lifecycle. There's no way they can do the job promised by the interface without doing state management (unless they're just mocks), so there's no sense in omitting lifecycle methods from the interface.

HandleSignals is something I'm still shifting on, though. Per #160, having the library set up and do the signal handling itself isn't exactly ideal, even if it is triggered by the caller.

context.go Outdated
VersionInWorkspace(root gps.ProjectRoot) (gps.Version, error)

// Returns the root directory where packages can be found.
Root() string
Copy link
Member

Choose a reason for hiding this comment

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

Eh...I could be convinced of one for facilitating searching for directories, but I don't think having this Root() method adds much value. We don't want to rename this away from GOPATH, because that's what people already think of wrt "a space on disk where your source packages are kept"; a new name would just add confusion.

@spenczar
Copy link
Contributor Author

spenczar commented Apr 1, 2017

In general, I think this is a worthwhile abstraction. But there's a lot of details here to work out, first.

Rather than going forward iteratively in a PR, could you open an issue to make a proposal about what the scope of responsibilities should be here?

BuildContext wasn't really what I hoped to focus on. My hope was to eventually write tests of the Status command, which would be easier if I could mock interfaces, so I wanted to use gps.SourceManager instead of *gps.SourceMgr. I happened to change *Ctx to a new interface too just because the *Ctx was the thing that made the Source Manager.

I think I can get away with writing those tests even with a concrete *Ctx though. I'll revert the changes to context and focus on just the SourceManager aspect. Does that sound OK?

@sdboyer
Copy link
Member

sdboyer commented Apr 1, 2017

I think I can get away with writing those tests even with a concrete *Ctx though. I'll revert the changes to context and focus on just the SourceManager aspect. Does that sound OK?

I do think they're a valuable direction to explore, but if they're yaks vis-a-vis your current goals, then sure 😄

@sdboyer
Copy link
Member

sdboyer commented Apr 17, 2017

@spenczar did you want to keep trying to move this forward?

@spenczar
Copy link
Contributor Author

spenczar commented Apr 17, 2017 via email

@sdboyer
Copy link
Member

sdboyer commented Apr 17, 2017

SGTM

@sdboyer
Copy link
Member

sdboyer commented May 5, 2017

Is it time to pick this back up?

@spenczar
Copy link
Contributor Author

spenczar commented May 6, 2017

Yes! I'll dig in.

@spenczar spenczar changed the title Use interfaces between main and dep packages Use gps.SourceManager instead of *gps.SourceMgr in cmd/dep May 6, 2017
@spenczar
Copy link
Contributor Author

spenczar commented May 6, 2017

I've pushed a new version which only changes *SourceMgr references to SourceManager. The build context stuff takes a little more design, so it can be done separately with some more discussion.

@sdboyer
Copy link
Member

sdboyer commented May 9, 2017

Yeah OK, this is a good division of work, I think.

Feel free with that follow-up at your leisure 😄

@sdboyer sdboyer merged commit 4c5e459 into golang:master May 9, 2017
ibrasho pushed a commit to ibrasho-forks/dep that referenced this pull request May 10, 2017
Use gps.SourceManager instead of *gps.SourceMgr in cmd/dep
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants