Masterminds / glide

Package Management for Golang
https://glide.sh
Other
8.15k stars 540 forks source link

sort package list in yaml #139

Closed kyteague closed 8 years ago

kyteague commented 8 years ago

If you "glide get" a package it will reorder the package list in the yaml config causing your diff to look very messy.

technosophos commented 8 years ago

Here's an example I just saw:

$ cat glide.yaml
parent: null
package: github.com/deis/helm
import:
- package: github.com/codegangsta/cli
  version: f445c894402839580d30de47551cedc152dad814
- package: github.com/deis/pkg
  subpackages:
  - /prettyprint
- package: github.com/Masterminds/vcs
- package: github.com/Masterminds/semver
- package: speter.net/go/exp/math/dec/inf
- package: golang.org/x/crypto
- package: github.com/aokoli/goutils
- package: github.com/pborman/uuid
- package: github.com/google/go-querystring
- package: github.com/google/go-github
$  glide get gopkg.in/yaml.v2
[INFO] Preparing to install 1 package.
[INFO] Package gopkg.in/yaml.v2 manages its own dependencies
[INFO] Setting version for github.com/codegangsta/cli to f445c894402839580d30de47551cedc152dad814.
[INFO] Project relies on 11 dependencies.
$  cat glide.yaml
package: github.com/deis/helm
import:
- package: github.com/Masterminds/vcs
- package: speter.net/go/exp/math/dec/inf
- package: golang.org/x/crypto
- package: github.com/pborman/uuid
- package: gopkg.in/yaml.v2
- package: github.com/codegangsta/cli
  version: f445c894402839580d30de47551cedc152dad814
- package: github.com/deis/pkg
  subpackages:
  - /prettyprint
- package: github.com/Masterminds/semver
- package: github.com/aokoli/goutils
- package: github.com/google/go-querystring
- package: github.com/google/go-github
$ glide --version
glide version 0.7.1
mattfarina commented 8 years ago

Good catch. Found the issue (I think). Will fix this next.

mattfarina commented 8 years ago

I think this is happening as part of the flattening process. The dependency list is turned into a map and then back into a slice here.

mattfarina commented 8 years ago

@kyteague can you test the latest on master. I believe this is fixed. Want to make sure you're not still seeing the issue. If everything is good I'll release 0.7.2 on Monday.

kyteague commented 8 years ago

Trying to test but running into this issue now:

https://github.com/Masterminds/glide/issues/141

kyteague commented 8 years ago

Confirmed that the main issue is fixed. Now the dependency is added to the end of the file.

However, this is not how bundler or pip handle this. They both resort the package list based on the package name. This makes it easy to look up versions of packages when looking at the file. This would also grouped related dependencies together.

mattfarina commented 8 years ago

@kyteague we talked about sorting them in alpha order or some other useful manner. We have a problem in Go right not that makes that difficult. Let me explain because you may see something we don't.

Most Go packages don't provide a useful version, such as SemVer. Instead they just use commit ids. This is a big difference between the Go community right now and every other language community.

So, if you have multiple declarations of the same dependency to different commit ids who wins? For example, I was looking at kubernetes the other day. It's dependencies and it's dependencies dependencies will pull in the same package at different commit id versions. One of them wins but which one?

Right now we take the stance that the first one wins and we tell you about any conflicts that arise. You normally only see this on complicated projects (like deis/helm). If you want a different one to win you move it to a higher point in the glide.yaml file and it will win.

So, order can matter on a complicated project. Especially with nested dependency declarations and it's not pretty because of all the commit ids being used.

I've got some ideas to solve the problem and then you can order by alpha. But, we need to solve that first. Any ideas?