List external dependencies of package

10,197 views
Skip to first unread message

Johann Höchtl

unread,
Nov 10, 2013, 2:12:21 AM11/10/13
to golan...@googlegroups.com
Is there a way to list the external dependencies of a go package?. Every package a package imports not coming from std?

I used the search functionality of this list and tried stackexchange but wasn't able to identify an answer. Sorry if it's a know use case and already documented.

Johann
Message has been deleted

Johann Höchtl

unread,
Nov 10, 2013, 3:05:49 AM11/10/13
to Islan Dberry, golan...@googlegroups.com
On 10.11.2013 08:53, Islan Dberry wrote:
The command

go list -f {{.Deps}}

list all dependencies. It should be easy to pipe the output through a filter to remove standard packages.

What makes a standard package distinguishable from an external package? The lack of "github", "Bitbucket" etc. in its specifier?
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/611QEJqkDKw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dave Cheney

unread,
Nov 10, 2013, 3:15:12 AM11/10/13
to Johann Höchtl, Islan Dberry, golang-nuts
go list std

will give you the list of standard packaqes, with a bit of work you
can subtract that set from the set of dependencies.
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Keith Rarick

unread,
Nov 10, 2013, 3:15:21 AM11/10/13
to Johann Höchtl, Islan Dberry, golang-nuts
On Sun, Nov 10, 2013 at 12:05 AM, Johann Höchtl
<johann....@gmail.com> wrote:
> What makes a standard package distinguishable from an external package?

For each package P (in your case, for each dependency),
'go list -f {{.Standard}} P' will tell you.

Dave Cheney

unread,
Nov 10, 2013, 3:18:25 AM11/10/13
to Keith Rarick, Johann Höchtl, Islan Dberry, golang-nuts
Nice tip!
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Sebastien Binet

unread,
Nov 10, 2013, 4:05:31 AM11/10/13
to Keith Rarick, Johann Höchtl, Islan Dberry, golang-nuts
nice!
$ go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -f
'{{if not .Standard}}{{.ImportPath}}{{end}}'

-s

luz...@gmail.com

unread,
Nov 10, 2013, 4:21:51 AM11/10/13
to golan...@googlegroups.com, Keith Rarick, Johann Höchtl, Islan Dberry
On Sunday, November 10, 2013 10:05:31 AM UTC+1, Sebastien Binet wrote:
nice!
$ go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -f
'{{if not .Standard}}{{.ImportPath}}{{end}}'

Without the tr calls:
$ go list -f '{{join .Deps "\n"}}' |  xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}} 

Caleb Spare

unread,
Nov 10, 2013, 3:07:42 PM11/10/13
to golan...@googlegroups.com
A few months back I made a tiny tool to do exactly this.


You can just 'go get github.com/cespare/deplist' and then 'deplist github.com/your/package' or whatever.

-Caleb


On Saturday, November 9, 2013 11:12:21 PM UTC-8, Johann Höchtl wrote:

Johann Höchtl

unread,
Nov 10, 2013, 3:50:22 PM11/10/13
to golan...@googlegroups.com, Keith Rarick, Johann Höchtl, Islan Dberry, luz...@gmail.com
$ go list -f '{{join .Deps "\n"}}' |  xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'

Hm, but that gives me - strangely - only my packages, not the ones I import.

Johann Höchtl

unread,
Nov 10, 2013, 4:16:27 PM11/10/13
to golan...@googlegroups.com


Am Sonntag, 10. November 2013 21:07:42 UTC+1 schrieb Caleb Spare:
A few months back I made a tiny tool to do exactly this.


You can just 'go get github.com/cespare/deplist' and then 'deplist github.com/your/package' or whatever.

deplist works great. However, it only accepts a single package and I got so much used to the /... - syntax of the go tool. This monster gives me what I want:

go list -f '{{.ImportPath}}' P/... | xargs -n 1 deplist | grep -v P | sort -u

with P being the partial package path.

Johann

Keith Rarick

unread,
Nov 10, 2013, 8:10:38 PM11/10/13
to Johann Höchtl, golang-nuts
On Sun, Nov 10, 2013 at 1:16 PM, Johann Höchtl <johann....@gmail.com> wrote:
> go list -f '{{.ImportPath}}' P/...

You can replace that with

go list P/...

since {{.ImportPath}} is the default format for go list.
Reply all
Reply to author
Forward
0 new messages