-
Notifications
You must be signed in to change notification settings - Fork 1k
Use gps.SourceManager instead of *gps.SourceMgr in cmd/dep #353
Conversation
cmd/dep/signals.go
Outdated
@@ -0,0 +1,23 @@ | |||
package main |
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 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.
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, 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.
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 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.
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.
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 |
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 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.
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.
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.
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.
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.
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.
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 { |
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 like the principle here, but IMO DepContext
is preferable to BuildContext
, as we're not really building anything here.
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.
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.
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, 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... 😄
cmd/dep/signals.go
Outdated
@@ -0,0 +1,23 @@ | |||
package main |
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, 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 |
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.
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.
I think I can get away with writing those tests even with a concrete |
I do think they're a valuable direction to explore, but if they're yaks vis-a-vis your current goals, then sure 😄 |
@spenczar did you want to keep trying to move this forward? |
Oops, thanks for the reminder. Let's drop this and do it after gps is
merged into dep, it'll be much easier then.
…On Sun, Apr 16, 2017 at 9:58 PM sam boyer ***@***.***> wrote:
@spenczar <https://github.com/spenczar> did you want to keep trying to
move this forward?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#353 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA1vHcN1-hEzKEBo5745462fC9RFa2oAks5rwsdjgaJpZM4MrsNo>
.
|
SGTM |
Is it time to pick this back up? |
Yes! I'll dig in. |
7bb4c77
to
25a5016
Compare
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. |
Yeah OK, this is a good division of work, I think. Feel free with that follow-up at your leisure 😄 |
Use gps.SourceManager instead of *gps.SourceMgr in cmd/dep
This is a refactor that shouldn't change behavior. It just gets
package main
to use interfaces instead of concrete implementations forSourceManager
.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.