-
Notifications
You must be signed in to change notification settings - Fork 1k
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
e4bce9d
to
80f5fad
Compare
I signed it! |
CLAs look good, thanks! |
80f5fad
to
bdd2f6b
Compare
hmm, so, re: the |
So I don't know enough about either project to say for sure, and it shouldn't impact this PR. Just thinking about whether or not we can close the gb PR when this merges. |
RE: the source field, this is why the original gb PR got hung up. @michael-go Let us know if you need have questions or help implementing what Sam is suggesting. |
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.
This is really good! 💖
I am so very sorry that my upcoming PR is going to require more changes to your PR. That's on me, but hopefully it's not too much work to rebase!
cmd/dep/gvt_importer.go
Outdated
} | ||
|
||
var contstraintHint = "" | ||
if pkg.Branch != "master" { |
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.
You don't need to validate this, and can set ConstraintHint
to pkg.Branch
directly. The base importer handles detecting if it's a branch, and ignore garbage like "HEAD" or constraints that don't match the revision.
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 added this line because it actually affected the behavior.
for example, I ran it on a gvt
project with this in the manifest
:
{
"importpath": "github.com/blang/semver",
"repository": "https://github.com/blang/semver",
"vcs": "",
"revision": "aea32c919a18e5ef4537bbd283ff29594b1b0165",
"branch": "master"
},
by passing the "master"
as a ConstraintHint
, dep init
chose a newer version:
[[projects]]
name = "github.com/blang/semver"
packages = ["."]
revision = "2ee87856327ba09384cabd113bc6b5d174e9ec0f"
version = "v3.5.1"
but by not passing "master"
as a hint with the check above, dep init
chose the correct version:
[[projects]]
name = "github.com/blang/semver"
packages = ["."]
revision = "aea32c919a18e5ef4537bbd283ff29594b1b0165"
version = "v3.1.0"
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 that may be a bug in the base importer then? I'll use that a testcase and see if I can figure out what's going on. 😀
cmd/dep/gvt_importer.go
Outdated
|
||
const gvtPath = "vendor" + string(os.PathSeparator) + "manifest" | ||
|
||
type gvtImporter struct { |
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.
Heads up: there's one more PR pending that will impact yours. I am so sorry about the churn! 😥
When #1145 is merged (hopefully tomorrow morning), here's what will need to change:
- Make a directory for gvt under
internal/importers
. - Move
gvt_importer.go
into that directory and rename it toimporter.go
. Same for it's test file. - Add an import for
github.com/golang/dep/internal/importers/base
. - The
*baseImporter
field should be renamed to*base.Importer
. - Any fields you were using from the base importer are now exported and need to be upper-cased (e.g.
g.logger -> g.Logger
,g.manifest -> g.Manifest
). - Rename
gvtImporter
toImporter
. - Rename
newGvtImporter()
toNewImporter()
. This function is now called ininternal/importers/importers.go -> BuildAll()
. - Move your testdata to
internal/importers/gvt/testdata
.
cmd/dep/gvt_importer_test.go
Outdated
}{ | ||
"package without comment": { | ||
convertTestCase{ | ||
wantConstraint: importerTestV1Constraint, |
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.
After that PR is merged, you will need to import github.com/golang/dep/internal/importers/importertest
, and then the testcases will look like this:
importertest.TestCase{
WantConstraint: importertest.V1Constraint,
WantRevision: importertest.V1Rev,
WantVersion: importertest.V1Tag,
},
cmd/dep/gvt_importer_test.go
Outdated
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
err := testCase.Exec(t, func(logger *log.Logger, sm gps.SourceManager) (*dep.Manifest, *dep.Lock, 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.
After the PR this function has been renamed to Execute
.
cmd/dep/gvt_importer_test.go
Outdated
name := name | ||
testCase := testCase | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() |
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.
We've had trouble with running the importer tests in parallel (see #1143). So please remove this line.
@sdboyer, regarding the and @carolynvs, thanks! I'll rebase my branch with the changes above after #1145 is merged |
yep! that sounds ideal.
…On September 12, 2017 3:49:27 AM EDT, michael-go ***@***.***> wrote:
@sdboyer, regarding the `Source`. So if I understand correctly, you
suggest a new method in `SourceManger`, something like
`IsDefaultSource(ProjectIdentifier) bool`, and this method will be
called from `baseImporter.importPackages()`, and if returns true, the
`.Source` will be cleared from the `gps.ProjectIdentifier` prior the
first call to `InferConstraint()`?
If so, you would like this to be part of this PR?
Thanks!
and @carolynvs, thanks! I'll rebase my branch with the changes above
when #1145 is merged
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1149 (comment)
|
bdd2f6b
to
a7103ca
Compare
@carolynvs I rebased the branch following the merge of #1445. I still check that the
Regarding the Thanks! |
I was able to reproduce the issue of the master constraint. The problem is that imported revision is tagged with v3.1.0, and the base importer is using that version in the lock, while still using a branch constraint in the manifest, which is invalid dep configuration. Solve will detect that v3.1.0 doesn't satisfy the branch constraint, and pick a different revision that satisfies the constraint. I am still thinking about how to resolve this:
Either of those solutions would preserve the correct locked revision. The first is "truer" to the original imported config, preserving the master branch constraint. However, dep would much prefer to move people onto using semver constraints. Plus I'm not sure that gvt really meant "stay on master" instead of "this revision happened to be the tip of master when gvt was run". 🤔 |
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.
The rebase looks great! 👍
Please update the help text and doc to mention that gvt and gb(right?) are supported:
Lines 31 to 32 in d62440d
disable this behavior. The following external tools are supported: | |
glide, godep, vndr, govend. |
https://github.com/golang/dep/blob/master/docs/FAQ.md#what-external-tools-are-supported
Thanks @carolynvs. regarding |
b9d8969
to
a7eff3c
Compare
OK, so after looking at #818, I added a special handling to a case where "branch" is set "HEAD", and updated the docs (and console output) to include |
internal/importers/gvt/importer.go
Outdated
|
||
ip := base.ImportedPackage{ | ||
Name: pkg.ImportPath, | ||
//TODO: temporarly ignore .Repository. see https://github.com/golang/dep/pull/1166 |
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 once you get a chance to incorporate your PR back into this, we can merge.
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.
thanks @carolynvs ! will try to add a commit tomorrow
a7eff3c
to
1cfc27f
Compare
@carolynvs I rebased over the new master following the merge of #1166 and handled the
|
internal/importers/base/importer.go
Outdated
source := prj.Source | ||
if len(source) > 0 { | ||
isDefault, err := i.isDefaultSource(prj.Root, source) | ||
if err == nil && isDefault { |
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 print a warning, and ignore the imported source. Then they can review the warning and tweak if necessary.
Also add a testcase in TestBaseImporter_ImportProjects
to verify that WantWarning
contains a substring from our warning message and that the source was set to ""
.
e.g.
Ignoring imported source https://github.com/example/foo.blorp for github.com/example/foo: <error 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.
Do you mean it for every time we set Source
to ""
, or just when isDefaultSource()
returns an error? (and it should actually never return an error, as DeduceRootProject()
that is called earlier in loadPackages
calls the same underlying deduceRootPath()
)
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.
Sorry that wasn't clear! Yes, I was referring to when isDefaultSource
returns an error. Even though it may never happen, I'd prefer to handle it regardless.
internal/importers/base/importer.go
Outdated
@@ -291,3 +299,20 @@ func (i *Importer) convertToConstraint(v gps.Version) gps.Constraint { | |||
} | |||
return v | |||
} | |||
|
|||
func (i *Importer) isDefaultSource(projectRoot gps.ProjectRoot, sourceURL string) (bool, error) { | |||
if sourceURL == "https://"+string(projectRoot) { |
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.
Can you help me understand why this is necessary? I would have thought that SourceURLsForPath
would cover this as well.
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.
mainly for gopkg.in
imports, as for example importing gopkg.in/yaml.v2
via gvt
will appear in the manifest as:
{
"importpath": "gopkg.in/yaml.v2",
"repository": "https://gopkg.in/yaml.v2",
"vcs": "",
"revision": "f7716cbe52baa25d2e9b0d0da546fcf909fc16b4",
"branch": "v2"
}
but SourceURLsForPath()
will return [https://github.com/airbrake/gobrake http://github.com/airbrake/gobrake]
In addition, this small condition will usually return true and will save save some CPU cycles 😄
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.
Would you please add a comment explaining that we are essentially checking for gopkg.in URLs?
return false, err | ||
} | ||
// The first url in the slice will be the default one (usually https://...) | ||
if len(sourceURLs) > 0 && sourceURL == sourceURLs[0].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.
If the first entry in sourceURLs
doesn't exist, does dep try the other ones? e.g. If the imported source matched the second entry, but we don't import it and left the source blank, would dep automatically try the first, realize it doesn't exist and fall back to that second entry?
I am a bit confused as to why only the first entry is the only "default". I thought they all were defaults that dep would try?
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.
regarding you first question, yes, I believe dep will try the next URL in order, if one doesn't exist.
I compare only to the first one following the guidance of @sdboyer - good chance I misunderstood something though. My guess for this, is that if a tool choose not the https:
URL, but the ssh
one for example, we better respect that and not try fetching via https
even if it works.
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 to me, thanks!
internal/importers/gvt/importer.go
Outdated
gvtConfig gvtManifest | ||
} | ||
|
||
// NewImporter for gvt. |
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 we don't forget, let's include in this comment that it also automatically handles gb as well.
}, | ||
}, | ||
}, | ||
"package with alternate repository": { |
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 believe this is really testing the logic that you added to the base importer, right? Let's move this testcase into the base importer's tests, as it's not specific to gvt.
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.
hm... this tests also tests that I use the Source
field in gvt
importer, i.e. it tests this line: https://github.com/michael-go/dep/blob/1cfc27fb29c6369b42d99a51e06e680f1539e819/internal/importers/gvt/importer.go#L116
maybe we just need to added another test in the base importer in addition?
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 that sounds good, would you please add a test to the base importer as well?
Thanks @carolynvs, I handled all your comments, except I didn't know how to write the test for |
Yes, that's enough, thanks! |
What does this do / why do we need it?
It imports the config (
vendor/manifest
) of https://github.com/FiloSottile/gvtWhat should your reviewer look out for in this PR?
gvt
andgb-vendor
use the same filename for their manifests, and have a pretty similar structure, asgvt
is based ongb-vendor
.There already is a PR open for
gb
: #818, however it's based on the code prior to the recently merged "Standardize the importers" #1100, and @carolynvs suggested I opened a new PR anyway.Do you need help or clarification on anything?
Every import in the
gvt
manifest has arepository
field, which has the URL of the repository. On one project I tested the importer with, it had therepository
field of allgolang.org/x/crypto
packages point tohttps://go.googlesource.com/crypto
. To make the import more accurate, I tried to init theimportedPackage
struct viaSource: pkg.Repository
, however it fails with:unable to list versions for golang.org/x/crypto(https://go.googlesource.com/crypto): unable to deduce repository and source type for "https://go.googlesource.com/crypto": unable to read metadata: go-import metadata not found
Thanks!
Which issue(s) does this PR fix?
fixes #679