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

Import glide configuration during init #500

Merged
merged 8 commits into from
Jun 2, 2017

Conversation

carolynvs
Copy link
Collaborator

@carolynvs carolynvs commented May 2, 2017

During dep init if glide.yaml and glide.lock are present, then use the glide configuration when initializing dep's manifest and lock. Importing config from other dependency manager's will be the default, specify -skip-tools to ignore existing configuration.

  • Read glide.yaml and populate initial manifest constraints.
  • Hit the dependency repo to determine if a glide project version is a branch or tag.
  • Drop a dependency from the manifest if it's in glide.yaml but isn't imported.
  • Read glide.lock and populate initial lock revisions.
  • Unmarshal unsupported glide fields, detect if present and warn that they are being ignored.

@sdboyer
Copy link
Member

sdboyer commented May 2, 2017

First, yay!! Glad you're moving forward on this - I was actually just about to post something on one of the other issues 😄

I can't remember if I said this anywhere, but repeating just in case - the ideal place to attach this behavior would be as a method on the Analyzer - one that's compatible with the arguments to DeriveManifestAndLock().

@sdboyer
Copy link
Member

sdboyer commented May 3, 2017

the ideal place to attach this behavior would be as a method on the Analyzer - one that's compatible with the arguments to DeriveManifestAndLock().

Now, looking over the PR as-is - it's fine to have the bulk of the logic in internal, but the entry points should still be attached to the analyzer.

@carolynvs
Copy link
Collaborator Author

I've rebased to take in the gps merge. Tomorrow I'll move my hook out of init and into the Analyzer.

@sdboyer
Copy link
Member

sdboyer commented May 12, 2017

yay!

@carolynvs
Copy link
Collaborator Author

carolynvs commented May 13, 2017

@sdboyer Can you point me in the right direction for looking up a version string like "master" or "v2" against a dependency's repo to determine if it's a branch/tag/version? I mostly am not sure if this lookup exists in some form or another already.

UPDATE: I found what I was looking for in the ensure command. I'll see if I can get the branch/tag/version deduction working tonight.

@carolynvs
Copy link
Collaborator Author

Hurray for progress! It now

  • checks the dependency repo to tell if a glide "version" is a branch/tag/version
  • uses the default branch when no version information is given in glide.yaml for a package.

Both of that is rolled into the same function used by ensure so that everyone (ensure, importers, etc) all benefit.

I think all that's left is:

  • housekeeping on the importer interface, going to bring it down to a single method
  • fix merge conflict with master
  • document how this works better so people know it exists. Right now just the helptext mentions -skip-tools but doesn't say what's supported or how it works.

cmd/dep/init.go Outdated
Analyzers: []rootProjectAnalyzer{
newGopathAnalyzer(ctx.Loggers, ctx, pkgT, cpr, sm),
newImportAnalyzer(ctx.Loggers, sm),
}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just trying to understand, the compositeAnalyzer would also be added to analyzer.go's DeriveManifestAndLock() so that the dependency projects are also analyzed for dep, glide, godep, etc config in them, right?

Copy link
Collaborator Author

@carolynvs carolynvs May 15, 2017

Choose a reason for hiding this comment

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

The way I have things organized as of right now:

  • dep/analyzer.go handles identifying if a project uses dep and importing its config.
  • dep/cmd/dep/importAnalyzer.go handles organizing all the importers for other tools together and importing config for them recursively for all dependencies. The first tool which identities that its config is present is used, and the remaining tools are not used.
  • dep/cmd/dep/gopathAnalyzer.go contains all the existing logic for generating an initial manifest and lock based on what is on disk under GOPATH.
  • dep/cmd/dep/compositeAnalyzer.go lets us combine multiple analyzers, where the results of each is overlaid on top of the results of the previous, combining the results of an importer with whatever is found in the GOPATH.

The init command uses either just the gopathAnalyzer when -skip-tools is present (which is the behavior in master) for the root project and dependencies, or makes a compositeAnalyzer to determine the root manifest (first inspecting the GOPATH, then overlaying the import results) and uses the importAnalyzer for any dependencies.

Things are still in-flux as I've been developing in small steps. 😀 I haven't decided yet if it makes sense to combine the gopathAnalazyer with compositeAnalyzer, because they are only used together, but I kind of prefer to not have a hodge-podge struct that does all the things.

Let me know if that makes sense or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, totally makes sense. I have started writing godep cofig over this PR. 🙂

But I was wondering if we should help gps analyze the dependency projects too with the new importers. From my understanding, gps calls analyzer's DeriveManifestAndLock() for every (direct & transitive) project, and tries to analyze their dependency constraints. Right now it receives nil for manifest and lock of those projects. But as projects adopt dep, and for those projects that already use some other tool, gps should be able to analyze them, right?

Please correct me if I misunderstood 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we are both trying to say the same thing. 👍 That's what I was trying to say with "using the importers for both the root project and the dependencies".

The solver takes an an initial manifest and lock for the root project, which I am generating using either just the gopathAnalyzer (for -skip-tools) or the compositeAnalayzer. But it also takes an analyzer to be applied to any dependencies it finds. When not skipping importing from other tools, I give the solver the importAnalyzer so that the same import logic we applied at the root is also applied to dependencies.

Thank you for asking about this! I forget to add an integration test for this scenario.

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.

(just some ongoing comments that i had built up)

}
}

// If not a plain SHA1 or bzr custom GUID, assume a plain version.
// TODO: if there is amgibuity here, then prompt the user?
return gps.NewVersion(s)
// return gps.NewVersion(s)
Copy link
Member

Choose a reason for hiding this comment

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

this is now cruft, let's remove

@@ -0,0 +1,148 @@
// Copyright 2016 The Go Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

snake_case for filenames, please

@carolynvs
Copy link
Collaborator Author

@sdboyer The analyzer name returned by analyzer.Info() impacts the lock memo. I am using multiple analyzers, depending on if -skip-tools was specified. Do we want them to have different names (and therefore hashes)?

For example: dep/1 and dep.importer/1. If we do that, I'm not sure if I should try to distinguish between the external tool used to import as well, like dep.importer.glide or dep.importer.govendor?

@sdboyer
Copy link
Member

sdboyer commented May 15, 2017

@carolynvs I haven't reviewed your changes yet, so I don't know how much this lines up with what you've already done - so, speaking in generalities 😄

My instinctive preference is to have one actual analyzer struct that, perhaps based on some flag property, decides whether it will look for all existing tool metadata files, or only dep's. The name should similarly vary based on the state of that flag. When passing the analyzer to gps.Prepare(), just make sure it has the flag set for the narrower behavior.

For reference, the purpose of the name and version fields is really just to provide a simple way of categorizing the compatibility of solutions. More formally, their meaning would be:

  1. If a solution differs from inputs by analyzer name, then the relationship is undefined, and no guarantee is made that the solution is valid for those inputs.
  2. If a solution and inputs have the same analyzer name, but vary by version, then there is still no guarantee that the solution is valid for those inputs, but the user can be safely advised that their analyzer is either "newer" or "older" than the version used to create that lock.
  3. If a solution and inputs have the same analyzer name and number, then it is guaranteed that the solution is valid for those inputs (with certain caveats)

My plan is to expose these fields directly in Gopkg.lock in #508, so that saner errors messages can be provided.

@carolynvs
Copy link
Collaborator Author

Thanks! That helps guide my next steps then. I was tempted to merge the two analyzers (skipping tools vs the current behavior) and that sounds like the way to go.

@darkowlzz darkowlzz mentioned this pull request May 16, 2017
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.

incremental review - holy crap, a lot of progress here 😄

if err != nil {
t.Fatal(err)
}

constraints := map[string]gps.Constraint{
"v1.2.3": sv,
"v0.8.1": sv,
"master": gps.NewDefaultBranch("master"),
Copy link
Member

Choose a reason for hiding this comment

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

Not necessarily opposed to this, but...

Is making it a default branch actually material to the test here? Branch default-ness is something that's supposed to only really matter in internal sorting; that's why the func for it isn't currently exported from gps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Derp! I don't know why I didn't try using c.String() != expected.String() to workaround default causing the equality check to fail. That fixes the test without having to expose NewDefaultBranch, I'll revert that change.


// Unsupported fields that we will warn if used
Subpackages []string `yaml:"subpackages"`
OS string `yaml:"os"`
Copy link
Member

Choose a reason for hiding this comment

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

Just noting here that we may be able to deal with these eventually - #291 - and if we warn on seeing these, we should probably include a link to that issue.

func (g *glideFiles) load(projectDir string) error {
y := filepath.Join(projectDir, glideYamlName)
if g.loggers.Verbose {
g.loggers.Err.Printf("glide: Loading %s", y)
Copy link
Member

Choose a reason for hiding this comment

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

We want the output here to follow the pattern generally described in the spec, initial implementation in #512. Maybe this becomes the "section header" message? (If so, though, that header is printed regardless of verbose flag)


func (g *glideFiles) buildProjectConstraint(pkg glidePackage, sm gps.SourceManager) (pc gps.ProjectConstraint, err error) {
if pkg.Name == "" {
err = errors.New("glide: Invalid glide configuration, package name is required")
Copy link
Member

Choose a reason for hiding this comment

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

ehhh, i'm on the fence about this. does glide care that much about having this value present? i can't actually recall.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to detect thje invalid configuration below, where an import section failed to set the package name. I don't require the root package name to be set. Granted it's unlikely to ever happen... Let me know if you still want the check removed.

import:
- package: ""
  version: 1.0.0

Copy link
Member

Choose a reason for hiding this comment

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

ohhhhh totally misread, ok 👍

g.loggers.Err.Printf("glide: The %s package specified an arch, but that isn't supported by dep, and will be ignored.\n", pkg.Name)
}
if len(pkg.Subpackages) > 0 {
g.loggers.Err.Printf("glide: The %s package specified subpackages, but that is calcuated by dep, and will be ignored.\n", pkg.Name)
Copy link
Member

Choose a reason for hiding this comment

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

subpackages are basically dead information in glide right now, anyway. I think it's fine to just ignore them entirely; no need to warn.

if newProject {
// Check if it's in notondisk project map. These are direct deps, should
// be added to manifest.
if _, ok := a.pd.notondisk[pr]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

The notondisk map isn't what we want to check here - rather, we need to be looking at the set of external roots. For that, we need something like what I've added over in my WIP ensure PR - https://github.com/sdboyer/dep/blob/1a546666f038281855255a52a3ff8532ff758b1b/cmd/dep/ensure.go#L356-L375

Copy link
Collaborator Author

@carolynvs carolynvs May 17, 2017

Choose a reason for hiding this comment

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

I think a couple of your comments may not be applicable due to the confusion over what gopath_analyzer does? It's just me extracting functions out of the init command into it's own struct and isn't for import at all.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, this probably doesn't apply anymore

func (a *gopathAnalyzer) DeriveRootManifestAndLock(path string, n gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) {
var err error

a.pd, err = getProjectData(a.ctx, a.pkgT, a.cpr, a.sm)
Copy link
Member

Choose a reason for hiding this comment

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

getProjectData is really only for the GOPATH detection route, not when we're importing from another tool. (we should probably rename it...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is for the gopath detection route (see file name: gopath_analyzer.go). I had extracted the logic for init into multiple analyzers (because as I was working on it, made it easier for me to think about). Based on your stated preference for one analyzer, I am now working to combine them back into a single struct.

Copy link
Member

Choose a reason for hiding this comment

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

ah! ok, i clearly didn't grok that reorganization from context here 😄

// be added to manifest.
if _, ok := a.pd.notondisk[pr]; ok {
m.Dependencies[pr] = getProjectPropertiesFromVersion(x.Version())
feedback(x.Version(), pr, fb.DepTypeDirect, a.ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Also, though we had some confusion in #512 (I wasn't clear about this initially), the goal of the feedback is to report what we learned by importing from the other tool before we go into the solve, not what the ultimate results are. We want to tell the user what we extracted from glide - what we ultimately end up with is a different question.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll keep an eye out for the follow-up PR for #512 to make sure that any code I moved is merged appropriately.

return depAnalyzer.DeriveManifestAndLock(dir, pr)
}

// The assignment back to an interface prevents interface-based nil checks from failing later
Copy link
Member

Choose a reason for hiding this comment

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

👍
ugh typed nils

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I struggled to figure out how to reuse that logic without causing typed nil troubles. Let me know if it's preferable to copy/paste code vs. calling the function and coercing the nils.

Copy link
Member

Choose a reason for hiding this comment

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

I think we may end up wanting to change the return pattern, anyway, per the discussion over in #594, which may help with this.

@carolynvs carolynvs changed the title WIP - Import glide configuration during init Import glide configuration during init May 17, 2017
@carolynvs
Copy link
Collaborator Author

@sdboyer Okay I just finished consolidating the little analyzer structs I had made into a single analyzer in cmd/dep/root_analyzer.go. Hopefully that makes things less confusing to review. If I need to doc more, just poke me with a sharp stick. 😀

I stopped short of combining that with analyzer.go because I wanted to get feedback and ... because moving the analyzer out of cmd/dep into dep forces me to make more decisions about exported/unexported/internal which is a can of worms.

Working on your other feedback right now.


rev := lpv.Underlying()
if rev != "6a741be0cc55ecbe4f45690ebfd606a956d5f14a" {
t.Fatalf("Expected locked revision to be '6a741be0cc55ecbe4f45690ebfd606a956d5f14a', got %s", lv)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change lv to rev? lv results in the version string, in this case v1.0.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the second set of 👀 !


ver := lpv.String()
if ver != "v1.0.0" {
t.Fatalf("Expected locked version to be 'v1.0.0', got %s", lv)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe change lv to ver? This would still be fine because lv and ver have same string values.

],
"error-expected": "",
"gopath-initial": {
"github.com/sdboyer/deptestdos": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f",
Copy link
Collaborator

Choose a reason for hiding this comment

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

"github.com/sdboyer/deptest" 👀

Copy link
Member

Choose a reason for hiding this comment

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

bump

@carolynvs
Copy link
Collaborator Author

@sdboyer When glide.yaml has a constraint for a transitive dependency, we want to create an override for that in the manifest, right? I wasn't sure if we wanted to force people to notice a warning in the output, and then make the override manually so that it's such a PITA that no one bothers. 😉

@carolynvs
Copy link
Collaborator Author

@sdboyer Another question. 😊 Now that we have the nifty feedback in place, the text displayed is misleading because the importer doesn't currently have all the facts up-front.

I am relying on the solver doing what it does best and then making sure the manifest is cleaned up to match before writing to disk. I populate the initial root manifest with everything I find in glide.yaml. If after solving it turns out that the package was transitive or not imported, then I remove it from the manifest.

Now with instant-feedback, I either need to pass more info to the importer to correctly display feedback, or tweak the feedback text to make it more clear that it's not final.

Here's an example:

  • deptest is a transitive dependency
  • deptestdos is a direct dependency
  • lint is not imported

Current (Misleading) Output

Converting from glide.yaml and glide.lock...
  Using ^1.0.0 as constraint for direct dep github.com/sdboyer/deptest
  Locking in v1.0.0 (ff2948a) for direct dep github.com/sdboyer/deptest
  Using ^2.0.0 as constraint for direct dep github.com/sdboyer/deptestdos
  Locking in v2.0.0 (5c60720) for direct dep github.com/sdboyer/deptestdos
  Using master as constraint for direct dep github.com/golang/lint
  Locking in master (cb00e56) for direct dep github.com/golang/lint

Option A: More vague output which is refined later during solve

Converting from glide.yaml and glide.lock...
  Using ^1.0.0 as constraint for imported dep github.com/sdboyer/deptest
  Locking in v1.0.0 (ff2948a) for imported dep github.com/sdboyer/deptest
  Using ^2.0.0 as constraint for imported dep github.com/sdboyer/deptestdos
  Locking in v2.0.0 (5c60720) for imported dep github.com/sdboyer/deptestdos
  Using master as constraint for imported dep github.com/golang/lint
  Locking in master (cb00e56) for imported dep github.com/golang/lint

Option B: Importers use the packageTree(?) to get it right the first time

Converting from glide.yaml and glide.lock...
  Ignoring transitive dep github.com/sdboyer/deptest
  Using ^2.0.0 as constraint for direct dep github.com/sdboyer/deptestdos
  Locking in v2.0.0 (5c60720) for direct dep github.com/sdboyer/deptestdos
  Ignoring unimported dep github.com/golang/lint

I'm leaning towards option b. What do you think?

@carolynvs
Copy link
Collaborator Author

@sdboyer This is ready for review.

  • This only covers init. The ensure and status commands are still using dep.Analyzer when solving which doesn't look at external tools. We'll need another pass to address that after this PR.
  • Since I wasn't sure what to do about imported constraints for transitive deps, I decided to ignore them for now.
  • I'm not sure how to deal with code climate. Some stuff, like doc on exported functions seems to be ignored for existing code but enforced for new code. Should I add an ignore in CC, doc the new function, doc all the exported functions?
  • I'm not sure why appveyor is failing. I assume I borked up test cleanup(?) but nothing is jumping out at me.

Overview of changes

  • cmd/dep/root_analyzer handles calling dep.Analyzer and the importers correctly based on -skip-tools. The analyzer name changes depending on this flag (dep vs dep+import).
  • cmd/dep/gopath_scanner is just the gopath scanning logic extracted out of the init command. It overlays whatever it finds on the results from the rootAnalyzer, filling in any gaps, but not changing values found by the importers.
  • cmd/dep/glide_importer implements the importer interface for glide.
  • Updated test harness tests to use -skip-import unless they are actually testing import.

@sdboyer
Copy link
Member

sdboyer commented May 30, 2017

Reviewing now 😄

As a starter, looking at the appveyor failures, it looks like a couple tests might've forgotten a call to SourceManager.Release().

@carolynvs
Copy link
Collaborator Author

Doh! Thanks that was it.

@sdboyer
Copy link
Member

sdboyer commented May 31, 2017

I'm not sure how to deal with code climate. Some stuff, like doc on exported functions seems to be ignored for existing code but enforced for new code. Should I add an ignore in CC, doc the new function, doc all the exported functions?

Yeah, I just flipped the switch on the CC analyzer for FIXMEs, TODOs, etc. It only applies to changed lines, not existing ones.

We need to buckle down and be diligent about following these rules, at least with the new stuff we introduce. So yes, let's make sure we're correctly documenting new exported identifiers.

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.

OK! i think we're really pretty close at this point - i'm happy with the fundamental architecture. one more pass and i think we can merge 🎉 🎉

analyzer.go Outdated
func (a Analyzer) DeriveManifestAndLock(path string, n gps.ProjectRoot) (gps.Manifest, gps.Lock, error) {
// TODO: If we decide to support other tools manifest, this is where we would need
// to add that support.
func (a Analyzer) HasConfig(path string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Let's call this HasDepMetadata() instead; HasConfig() is a bit generic.

if !found {
return constraint, errors.Errorf("%s is not a valid version for the package %s", versionStr, arg)
for _, v := range versions {
if v.Type() == gps.IsBranch {
Copy link
Member

Choose a reason for hiding this comment

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

We're not guaranteed sorted output from ListVersions() - the first branch we encounter might not be the default. Need to gps.SortPairedForUpgrade() on the slice to get the outcome we want.

// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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.

fyi, i'm not gonna review the actual glide conversion logic in detail. if there are problems, i'd likely miss them; we'd end up needing to rely on user testing and incremental improvement anyway. so 😄

}
}

// Perform analysis of the filesystem tree rooted at path, with the
Copy link
Member

Choose a reason for hiding this comment

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

Doc text should start with "InitializeRootManifestAndLock"

cmd/dep/init.go Outdated
If configuration files for other dependency management tools are found, they
are used to pre-populate the manifest and lock. Specify -skip-tools to disable
this behavior.

A Gopkg.toml file will be written with inferred version constraints for all
Copy link
Member

Choose a reason for hiding this comment

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

This text needs to be updated, as well. (Can be a little sloppy about it, given that it's going to change again once we add the -gopath flag.)

"github.com/golang/dep/internal/gps"
)

// importer handles importing configuration from other dependency managers into our format
Copy link
Member

Choose a reason for hiding this comment

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

Just a note - I think I'd eventually like to see this exported.

// importer handles importing configuration from other dependency managers into our format
type importer interface {
Name() string
Import(path string, pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error)
Copy link
Member

Choose a reason for hiding this comment

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

Seems like importer should just compose gps.ProjectAnalyzer, rather than having a new method called Import with the same (well, an equivalent) signature, and the same basic purpose, as DeriveManifestAndLock. Is there a reason not to do that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did it this way for a couple reasons:

  1. I needed the importers to return a dep manifest and lock, not the gps interfaces. Otherwise I would have to cast it immediately back.
  2. I didn't want the importers to implement functions that would go unused, Analyzer.Info.

So while they are similar, but I didn't see anything to be gained by reusing that interface.

HasConfig(dir string) bool
}

// rootAnalyzer supplies manifest/lock data both from dep and external tool's config files
Copy link
Member

Choose a reason for hiding this comment

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

add periods; complete sentences is generally 👍

@@ -0,0 +1,10 @@
ignored = ["github.com/sdboyer/dep-test","github.com/golang/notexist/samples"]
Copy link
Member

Choose a reason for hiding this comment

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

you do not, sorry, shouldn't have mentioned it 😄


package samples

import dt "github.com/carolynvs/go-dep-test"
Copy link
Member

Choose a reason for hiding this comment

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

ok, as long as you solemnly swear on your maintainer badge that this repo is frozen and will never change or go away once we merge this ❄️ 😺

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haha, I can swear to that. Or you can clone/fork it and put it with sdboyer/deptest for consistency?

@sdboyer
Copy link
Member

sdboyer commented May 31, 2017

hmm - looking at dep init -v output run against Masterminds/glide:

Importing configuration from glide. These are only initial constraints, and are further refined during the solve process.
Detected glide configuration files...
  Loading /Users/sdboyer/ws/go/src/github.com/Masterminds/glide/glide.yaml
  Loading /Users/sdboyer/ws/go/src/github.com/Masterminds/glide/glide.lock
Converting from glide.yaml and glide.lock...
  Using 0bdedde as initial hint for imported dep github.com/codegangsta/cli
  Using abff190 as initial hint for imported dep github.com/Masterminds/semver
  Using 3084677 as initial hint for imported dep github.com/Masterminds/vcs
  Using b8bc1bf as initial hint for imported dep github.com/mitchellh/go-homedir
  Using a3f3340 as initial hint for imported dep gopkg.in/yaml.v2
Searching GOPATH for projects...
Root project is "github.com/Masterminds/glide"
 17 transitively valid internal packages
 5 external packages imported from 5 projects
(0)   ✓ select (root)
(1)	? attempt github.com/Masterminds/semver with 1 pkgs; at least 1 versions to try
(1)	    try github.com/Masterminds/semver@v1.3.0
(1)	✓ select github.com/Masterminds/semver@v1.3.0 w/1 pkgs
(2)	? attempt github.com/Masterminds/vcs with 1 pkgs; at least 1 versions to try
(2)	    try github.com/Masterminds/vcs@v1.11.1
Importing configuration from glide. These are only initial constraints, and are further refined during the solve process.
Detected glide configuration files...
  Loading /Users/sdboyer/ws/go/pkg/dep/sources/https---github.com-Masterminds-vcs/glide.yaml
Converting from glide.yaml...
(2)	✓ select github.com/Masterminds/vcs@v1.11.1 w/1 pkgs
(3)	? attempt github.com/mitchellh/go-homedir with 1 pkgs; at least 1 versions to try
(3)	    try github.com/mitchellh/go-homedir@master
(3)	✓ select github.com/mitchellh/go-homedir@master w/1 pkgs
(4)	? attempt gopkg.in/yaml.v2 with 1 pkgs; 1 versions to try
(4)	    try gopkg.in/yaml.v2@v2
(4)	✓ select gopkg.in/yaml.v2@v2 w/1 pkgs
(5)	? attempt github.com/codegangsta/cli with 1 pkgs; at least 1 versions to try
(5)	    try github.com/codegangsta/cli@v1.19.1
(5)	✓ select github.com/codegangsta/cli@v1.19.1 w/1 pkgs
  ✓ found solution with 5 packages from 5 projects

Solver wall times by segment:
           b-gmal: 1.686396366s
      b-list-pkgs: 1.181170341s
      select-root:   1.577029ms
      select-atom:    355.459µs
          satisfy:    266.412µs
         new-atom:    129.091µs
  b-list-versions:    102.977µs
            other:      25.49µs
       b-pair-rev:     15.052µs
  b-source-exists:      8.269µs

  TOTAL: 2.870046486s

  Using master as constraint for direct dep github.com/mitchellh/go-homedir
  Locking in master (b8bc1bf) for direct dep github.com/mitchellh/go-homedir
  Using v2 as constraint for direct dep gopkg.in/yaml.v2
  Locking in v2 (cd8b52f) for direct dep gopkg.in/yaml.v2
  Using ^1.19.1 as constraint for direct dep github.com/codegangsta/cli
  Locking in v1.19.1 (0bdedde) for direct dep github.com/codegangsta/cli

we still have this thing where we produce feedback after the solve. either i'm forgetting something about the spec i wrote, or there's something fishy there. why are we not even applying constraints at all until after solving?

This makes it easier for the importers to reuse its logic
I tweaked ensure so that the existing behavior of ensure X applies
the any (*) constraint.
@carolynvs
Copy link
Collaborator Author

@sdboyer There are a couple problems with the output. 😊

  1. It was a bug that it wasn't properly printing the imported constraints. After fixing the truncated output from the importer looks like this:

    Converting from glide.yaml and glide.lock...
    Using ^1.16.0 as initial constraint for imported dep github.com/codegangsta/cli
    Trying ^1.16.0 (0bdedde) as initial lock for imported dep github.com/codegangsta/cli
    
  2. The last line should print the version that goes with the revision. @darkowlzz wrote that logic and was asking about where it should live, or if it exists already in gps. I'm going to steal his code and put it in a function next to deduceConstraint for now.

  3. The feedback shown after the solve is from a bad merge. I think we used to log feedback after solving, and must have dropped it since I started on this feature. I missed that when I copied that code from init to the gopath_scanner. Fixing!

* init imports by default unless -skip-tools is specified
* glide config in dependencies is taken into account during solve
@carolynvs
Copy link
Collaborator Author

I've addressed all your feedback, rebased and squashed. Here's the latest output of running dep init -v on glide.

$ dep init -v
Importing configuration from glide. These are only initial constraints, and are further refined during the solve process.
Detected glide configuration files...
  Loading /Users/carolynvs/go/src/github.com/Masterminds/glide/glide.yaml
  Loading /Users/carolynvs/go/src/github.com/Masterminds/glide/glide.lock
Converting from glide.yaml and glide.lock...
  Using ^1.19.1 as initial constraint for imported dep github.com/codegangsta/cli
  Trying v1.19.1 (0bdedde) as initial lock for imported dep github.com/codegangsta/cli
  Using ^1.3.0 as initial constraint for imported dep github.com/Masterminds/semver
  Trying v1.3.0 (abff190) as initial lock for imported dep github.com/Masterminds/semver
  Using ^1.11.1 as initial constraint for imported dep github.com/Masterminds/vcs
  Trying v1.11.1 (3084677) as initial lock for imported dep github.com/Masterminds/vcs
  Using master as initial constraint for imported dep github.com/mitchellh/go-homedir
  Trying master (b8bc1bf) as initial lock for imported dep github.com/mitchellh/go-homedir
  Using a3f3340 as initial hint for imported dep gopkg.in/yaml.v2
Searching GOPATH for projects...
Root project is "github.com/Masterminds/glide"
 53 transitively valid internal packages
 5 external packages imported from 5 projects
(0)   ✓ select (root)
(1)	? attempt github.com/Masterminds/semver with 1 pkgs; at least 1 versions to try
(1)	    try github.com/Masterminds/semver@v1.3.0
(1)	✓ select github.com/Masterminds/semver@v1.3.0 w/1 pkgs
(2)	? attempt github.com/Masterminds/vcs with 1 pkgs; at least 1 versions to try
(2)	    try github.com/Masterminds/vcs@v1.11.1
Importing configuration from glide. These are only initial constraints, and are further refined during the solve process.
Detected glide configuration files...
  Loading /Users/carolynvs/go/pkg/dep/sources/https---github.com-Masterminds-vcs/glide.yaml
Converting from glide.yaml...
(2)	✓ select github.com/Masterminds/vcs@v1.11.1 w/1 pkgs
(3)	? attempt github.com/mitchellh/go-homedir with 1 pkgs; at least 1 versions to try
(3)	    try github.com/mitchellh/go-homedir@master
(3)	✓ select github.com/mitchellh/go-homedir@master w/1 pkgs
(4)	? attempt gopkg.in/yaml.v2 with 1 pkgs; 1 versions to try
(4)	    try gopkg.in/yaml.v2@v2
(4)	✓ select gopkg.in/yaml.v2@v2 w/1 pkgs
(5)	? attempt github.com/codegangsta/cli with 1 pkgs; at least 1 versions to try
(5)	    try github.com/codegangsta/cli@v1.19.1
(5)	✓ select github.com/codegangsta/cli@v1.19.1 w/1 pkgs
  ✓ found solution with 5 packages from 5 projects

Solver wall times by segment:
      b-list-pkgs: 1.730042899s
           b-gmal: 1.573923904s
      select-root:   3.099974ms
      select-atom:    349.794µs
          satisfy:    340.791µs
         new-atom:    189.522µs
            other:     20.486µs
  b-source-exists:     16.998µs
  b-list-versions:      9.218µs
       b-pair-rev:      1.732µs

  TOTAL: 3.307995318s

@sdboyer
Copy link
Member

sdboyer commented Jun 2, 2017

(2)	    try github.com/Masterminds/vcs@v1.11.1
Importing configuration from glide. These are only initial constraints, and are further refined during the solve process.
Detected glide configuration files...
  Loading /Users/carolynvs/go/pkg/dep/sources/https---github.com-Masterminds-vcs/glide.yaml
Converting from glide.yaml...
(2)	✓ select github.com/Masterminds/vcs@v1.11.1 w/1 pkgs

The question of whether we read e.g. glide files in deps is a separate one from whether we read them from the current project during dep init. Can we make it controllable via a single boolean flag - e.g. if true, it'll try all the types of files we support; if false, it'll only look for Gopkg.toml and Gopkg.lock.

Also, either way, I don't think we want to print there, as it interrupts the trace output.

@carolynvs
Copy link
Collaborator Author

carolynvs commented Jun 2, 2017

I've disabled importing during solve. This means that if a dependency has glide config, it is not used at all. Previously -skip-tools controlled import both for the root project and dependencies, now it only controls at the root, and we never import for dependencies.

I've also tweaked the importer so that nothing is logged during solve. So if we eventually use the importer during solve, it won't interrupt the output. Here's the new output:

$ dep init -v
Importing configuration from glide. These are only initial constraints, and are further refined during the solve process.
Detected glide configuration files...
  Loading /Users/carolynvs/go/src/github.com/Masterminds/glide/glide.yaml
  Loading /Users/carolynvs/go/src/github.com/Masterminds/glide/glide.lock
Converting from glide.yaml and glide.lock...
  Using ^1.19.1 as initial constraint for imported dep github.com/codegangsta/cli
  Trying v1.19.1 (0bdedde) as initial lock for imported dep github.com/codegangsta/cli
  Using ^1.3.0 as initial constraint for imported dep github.com/Masterminds/semver
  Trying v1.3.0 (abff190) as initial lock for imported dep github.com/Masterminds/semver
  Using ^1.11.1 as initial constraint for imported dep github.com/Masterminds/vcs
  Trying v1.11.1 (3084677) as initial lock for imported dep github.com/Masterminds/vcs
  Using master as initial constraint for imported dep github.com/mitchellh/go-homedir
  Trying master (b8bc1bf) as initial lock for imported dep github.com/mitchellh/go-homedir
  Using a3f3340 as initial hint for imported dep gopkg.in/yaml.v2
Searching GOPATH for projects...
Root project is "github.com/Masterminds/glide"
 65 transitively valid internal packages
 5 external packages imported from 5 projects
(0)   ✓ select (root)
(1)	? attempt github.com/Masterminds/semver with 1 pkgs; at least 1 versions to try
(1)	    try github.com/Masterminds/semver@v1.3.0
(1)	✓ select github.com/Masterminds/semver@v1.3.0 w/1 pkgs
(2)	? attempt github.com/Masterminds/vcs with 1 pkgs; at least 1 versions to try
(2)	    try github.com/Masterminds/vcs@v1.11.1
(2)	✓ select github.com/Masterminds/vcs@v1.11.1 w/1 pkgs
(3)	? attempt github.com/mitchellh/go-homedir with 1 pkgs; at least 1 versions to try
(3)	    try github.com/mitchellh/go-homedir@master
(3)	✓ select github.com/mitchellh/go-homedir@master w/1 pkgs
(4)	? attempt gopkg.in/yaml.v2 with 1 pkgs; 1 versions to try
(4)	    try gopkg.in/yaml.v2@v2
(4)	✓ select gopkg.in/yaml.v2@v2 w/1 pkgs
(5)	? attempt github.com/codegangsta/cli with 1 pkgs; at least 1 versions to try
(5)	    try github.com/codegangsta/cli@v1.19.1
(5)	✓ select github.com/codegangsta/cli@v1.19.1 w/1 pkgs
  ✓ found solution with 5 packages from 5 projects

Solver wall times by segment:
           b-gmal: 1.832750336s
      b-list-pkgs: 1.383528239s
      select-root:   3.428211ms
          satisfy:    330.136µs
      select-atom:    318.279µs
         new-atom:    140.255µs
            other:     44.367µs
  b-source-exists:     11.541µs
  b-list-versions:      6.211µs
       b-pair-rev:        794ns

  TOTAL: 3.220558369s

@sdboyer
Copy link
Member

sdboyer commented Jun 2, 2017

OK so there is just NO apparent reason for that test windows test failure. Github is up...I don't know.

Either way, this is close enough, and has gone on way too long. It's time to merge. We can work out the rest incrementally 😄

@sdboyer sdboyer merged commit 01294a8 into golang:master Jun 2, 2017
@carolynvs carolynvs deleted the import-glide branch June 11, 2017 15:27
@carolynvs carolynvs mentioned this pull request Oct 31, 2017
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.

5 participants