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

Commit fd6c461

Browse files
committed
docs: Fix up README, polish deduction and intro
1 parent 25133db commit fd6c461

File tree

4 files changed

+46
-271
lines changed

4 files changed

+46
-271
lines changed

README.md

Lines changed: 4 additions & 232 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,15 @@
88

99
## Dep
1010

11-
`dep` is a prototype dependency management tool for Go. It requires Go 1.8 or newer to compile.
11+
`dep` is a prototype dependency management tool for Go. It requires Go 1.8 or newer to compile. **`dep` is safe for production use.**
1212

1313
`dep` is the official _experiment_, but not yet the official tool. Check out the [Roadmap](https://github.com/golang/dep/wiki/Roadmap) for more on what this means!
1414

15-
## Current status
15+
For guides and reference materials about `dep`, see [the documentation](https://golang.github.io/dep).
1616

17-
`dep` is safe for production use. That means two things:
17+
## Installation
1818

19-
* Any valid metadata file (`Gopkg.toml` and `Gopkg.lock`) will be readable and considered valid by any future version of `dep`.
20-
* The CLI UI is mostly stable. `dep init` and `dep ensure` are mostly set; `dep status` is likely to change a fair bit, and `dep prune` is [going to be absorbed into `dep ensure`](https://github.com/golang/dep/issues/944).
21-
22-
That said, keep in mind the following:
23-
24-
* `dep init` on an existing project can be a rocky experience - we try to automatically convert from other tools' metadata files, and that process is often complex and murky. Once your project is converted and you're using `dep ensure`, its behavior is quite stable.
25-
* `dep` still has nasty bugs, but in general these are comparable to or fewer than other tools out there.
26-
* `dep` is [pretty slow right now](https://github.com/golang/dep/blob/master/docs/FAQ.md#why-is-dep-slow), especially on the first couple times you run it. Just know that there is a _lot_ of headroom for improvement, and work is actively underway.
27-
* `dep` is still changing rapidly. If you need stability (e.g. for CI), it's best to rely on a released version, not tip.
28-
* `dep`'s exported API interface will continue to change in unpredictable, backwards-incompatible ways until we tag a v1.0.0 release.
29-
30-
## Context
31-
32-
- [The Saga of Go Dependency Management](https://blog.gopheracademy.com/advent-2016/saga-go-dependency-management/)
33-
- Official Google Docs
34-
- [Go Packaging Proposal Process](https://docs.google.com/document/d/18tNd8r5DV0yluCR7tPvkMTsWD_lYcRO7NhpNSDymRr8/edit)
35-
- [User Stories](https://docs.google.com/document/d/1wT8e8wBHMrSRHY4UF_60GCgyWGqvYye4THvaDARPySs/edit)
36-
- [Features](https://docs.google.com/document/d/1JNP6DgSK-c6KqveIhQk-n_HAw3hsZkL-okoleM43NgA/edit)
37-
- [Design Space](https://docs.google.com/document/d/1TpQlQYovCoX9FkpgsoxzdvZplghudHAiQOame30A-v8/edit)
38-
- [Frequently Asked Questions](docs/FAQ.md)
39-
40-
## Setup
41-
42-
Grab the latest binary from the [releases](https://github.com/golang/dep/releases) page.
19+
Unless you are hacking on dep, it is strongly recommended that you use a released version. You can grab the latest binary from the [releases](https://github.com/golang/dep/releases) page.
4320

4421
On macOS you can install or upgrade to the latest released version with Homebrew:
4522

@@ -54,217 +31,12 @@ If you're interested in hacking on `dep`, you can install via `go get`:
5431
go get -u github.com/golang/dep/cmd/dep
5532
```
5633

57-
To start managing dependencies using dep, run the following from your project's root directory:
58-
59-
```sh
60-
$ dep init
61-
```
62-
63-
This does the following:
64-
65-
1. Look for [existing dependency management files](docs/FAQ.md#what-external-tools-are-supported) to convert
66-
1. Check if your dependencies use dep
67-
1. Identify your dependencies
68-
1. Back up your existing `vendor/` directory (if you have one) to
69-
`_vendor-TIMESTAMP/`
70-
1. Pick the highest compatible version for each dependency
71-
1. Generate [`Gopkg.toml`](docs/Gopkg.toml.md) ("manifest") and `Gopkg.lock` files
72-
1. Install the dependencies in `vendor/`
73-
74-
## Usage
75-
76-
There is one main subcommand you will use: `dep ensure`. `ensure` first checks that `Gopkg.lock` is consistent with `Gopkg.toml` and the `import`s in your code. If any
77-
changes are detected, `dep`'s solver works out a new `Gopkg.lock`. Then, `dep` checks if the contents of `vendor/` are what `Gopkg.lock` (the new one if applicable, else the existing one) says it should be, and rewrites `vendor/` as needed to bring it into line.
78-
79-
In essence, `dep ensure` [works in two phases to keep four buckets of state in sync](https://youtu.be/5LtMb090AZI?t=20m4s):
80-
81-
<img width="463" alt="states-flow" src="https://user-images.githubusercontent.com/21599/29223886-22dd2578-7e96-11e7-8b51-3637b9ddc715.png">
82-
83-
84-
_Note: until we ship [vendor verification](https://github.com/golang/dep/issues/121), we can't efficiently perform the `Gopkg.lock` <-> `vendor/` comparison, so `dep ensure` unconditionally regenerates all of `vendor/` to be safe._
85-
86-
`dep ensure` is safe to run early and often. See the help text for more detailed
87-
usage instructions.
88-
89-
```sh
90-
$ dep help ensure
91-
```
92-
93-
### Installing dependencies
94-
95-
(if your `vendor/` directory isn't [checked in with your code](docs/FAQ.md#should-i-commit-my-vendor-directory))
96-
97-
<!-- may change with https://github.com/golang/dep/pull/489 -->
98-
99-
```sh
100-
$ dep ensure
101-
```
102-
103-
If a dependency already exists in your `vendor/` folder, dep will ensure it
104-
matches the constraints from the manifest. If the dependency is missing from
105-
`vendor/`, the latest version allowed by your manifest will be installed.
106-
107-
### Adding a dependency
108-
109-
```sh
110-
$ dep ensure -add github.com/foo/bar
111-
```
112-
113-
This adds a version constraint to your `Gopkg.toml`, and updates `Gopkg.lock` and `vendor/`. Now, import and use the package in your code! ✨
114-
115-
`dep ensure -add` has some subtle behavior variations depending on the project or package named, and the state of your tree. See `dep ensure -examples` for more information.
116-
117-
### Changing dependencies
118-
119-
If you want to:
120-
121-
* Change the allowed `version`/`branch`/`revision`
122-
* Switch to using a fork
123-
124-
for one or more dependencies, do the following:
125-
126-
1. Manually edit your `Gopkg.toml`.
127-
1. Run
128-
129-
```sh
130-
$ dep ensure
131-
```
132-
133-
### Checking the status of dependencies
134-
135-
Run `dep status` to see the current status of all your dependencies.
136-
137-
```sh
138-
$ dep status
139-
PROJECT CONSTRAINT VERSION REVISION LATEST
140-
github.com/Masterminds/semver branch 2.x branch 2.x 139cc09 c2e7f6c
141-
github.com/Masterminds/vcs ^1.11.0 v1.11.1 3084677 3084677
142-
github.com/armon/go-radix * branch master 4239b77 4239b77
143-
```
144-
145-
On top of that, if you have added new imports to your project or modified `Gopkg.toml` without running `dep ensure` again, `dep status` will tell you there is a mismatch between `Gopkg.lock` and the current status of the project.
146-
147-
```sh
148-
$ dep status
149-
Lock inputs-digest mismatch due to the following packages missing from the lock:
150-
151-
PROJECT MISSING PACKAGES
152-
github.com/Masterminds/goutils [github.com/Masterminds/goutils]
153-
154-
This happens when a new import is added. Run `dep ensure` to install the missing packages.
155-
```
156-
157-
As `dep status` suggests, run `dep ensure` to update your lockfile. Then run `dep status` again, and the lock mismatch should go away.
158-
159-
### Visualizing dependencies
160-
161-
Generate a visual representation of the dependency tree by piping the output of `dep status -dot` to [graphviz](http://www.graphviz.org/).
162-
#### Linux
163-
```
164-
$ sudo apt-get install graphviz
165-
$ dep status -dot | dot -T png | display
166-
```
167-
#### MacOS
168-
```
169-
$ brew install graphviz
170-
$ dep status -dot | dot -T png | open -f -a /Applications/Preview.app
171-
```
172-
#### Windows
173-
```
174-
> choco install graphviz.portable
175-
> dep status -dot | dot -T png -o status.png; start status.png
176-
```
177-
<p align="center"><img src="docs/img/StatusGraph.png"></p>
178-
179-
### Updating dependencies
180-
181-
Updating brings the version of a dependency in `Gopkg.lock` and `vendor/` to the latest version allowed by the constraints in `Gopkg.toml`.
182-
183-
You can update just a targeted subset of dependencies (recommended):
184-
185-
```sh
186-
$ dep ensure -update github.com/some/project github.com/other/project
187-
$ dep ensure -update github.com/another/project
188-
```
189-
190-
Or you can update all your dependencies at once:
191-
192-
```sh
193-
$ dep ensure -update
194-
```
195-
196-
"Latest" means different things depending on the type of constraint in use. If you're depending on a `branch`, `dep` will update to the latest tip of that branch. If you're depending on a `version` using [a semver range](#semantic-versioning), it will update to the latest version in that range.
197-
198-
### Removing dependencies
199-
200-
1. Remove the `import`s and all usage from your code.
201-
1. Remove `[[constraint]]` rules from `Gopkg.toml` (if any).
202-
1. Run
203-
204-
```sh
205-
$ dep ensure
206-
```
207-
208-
### Testing changes to a dependency
209-
210-
Making changes in your `vendor/` directory directly is not recommended, as dep
211-
will overwrite any changes. Instead:
212-
213-
1. Delete the dependency from the `vendor/` directory.
214-
215-
```sh
216-
rm -rf vendor/<dependency>
217-
```
218-
219-
1. Add that dependency to your `GOPATH`, if it isn't already.
220-
221-
```sh
222-
$ go get <dependency>
223-
```
224-
225-
1. Modify the dependency in `$GOPATH/src/<dependency>`.
226-
1. Test, build, etc.
227-
228-
Don't run `dep ensure` until you're done. `dep ensure` will reinstall the
229-
dependency into `vendor/` based on your manifest, as if you were installing from
230-
scratch.
231-
232-
This solution works for short-term use, but for something long-term, take a look
233-
at [virtualgo](https://github.com/GetStream/vg).
234-
235-
To test out code that has been pushed as a new version, or to a branch or fork,
236-
see [changing dependencies](#changing-dependencies).
237-
238-
## Semantic Versioning
239-
240-
`dep ensure` uses an external [semver library](https://github.com/Masterminds/semver) to interpret the version constraints you specify in the manifest. The comparison operators are:
241-
242-
* `=`: equal
243-
* `!=`: not equal
244-
* `>`: greater than
245-
* `<`: less than
246-
* `>=`: greater than or equal to
247-
* `<=`: less than or equal to
248-
* `-`: literal range. Eg: 1.2 - 1.4.5 is equivalent to >= 1.2, <= 1.4.5
249-
* `~`: minor range. Eg: ~1.2.3 is equivalent to >= 1.2.3, < 1.3.0
250-
* `^`: major range. Eg: ^1.2.3 is equivalent to >= 1.2.3, < 2.0.0
251-
* `[xX*]`: wildcard. Eg: 1.2.x is equivalent to >= 1.2.0, < 1.3.0
252-
253-
You might, for example, include a constraint in your manifest that specifies `version = "=2.0.0"` to pin a dependency to version 2.0.0, or constrain to minor releases with: `version = "2.*"`. Refer to the [semver library](https://github.com/Masterminds/semver) documentation for more info.
254-
255-
**Note**: When you specify a version *without an operator*, `dep` automatically uses the `^` operator by default. `dep ensure` will interpret the given version as the min-boundary of a range, for example:
256-
257-
* `1.2.3` becomes the range `>=1.2.3, <2.0.0`
258-
* `0.2.3` becomes the range `>=0.2.3, <0.3.0`
259-
* `0.0.3` becomes the range `>=0.0.3, <0.1.0`
260-
26134
## Feedback
26235

26336
Feedback is greatly appreciated.
26437
At this stage, the maintainers are most interested in feedback centered on the user experience (UX) of the tool.
26538
Do you have workflows that the tool supports well, or doesn't support at all?
26639
Do any of the commands have surprising effects, output, or results?
267-
Please check the existing issues and [FAQ](docs/FAQ.md) to see if your feedback has already been reported.
26840
If not, please file an issue, describing what you did or wanted to do, what you expected to happen, and what actually happened.
26941

27042
## Contributing

docs/Gopkg.toml.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,34 @@ system2-data = "value that is used by another system"
120120

121121

122122

123-
----
123+
## Version rules
124124

125+
Version rules can be used in either `[[constraint]]` or `[[override]]` stanzas. There are three types of version rules - `version`, `branch`, and `revision`. At most one of the three types can be specified.
125126

127+
### `version`
126128

127-
## Version rules
129+
`version` is a property of `constraint`s and `override`s. It is used to specify version constraint of a specific dependency. It can be used to target an arbitrary VCS tag, or a semantic version, or a range of semantic versions.
128130

129-
Version rules can be used in either `[[constraint]]` or `[[override]]` stanzas. There are three types of version rules - `version`, `branch`, and `revision`. At most one of the three types can be specified.
131+
Specifying semantic version ranges can be done using the following operators:
130132

131-
TODOOOOOOOOOOOOO
133+
* `=`: equal
134+
* `!=`: not equal
135+
* `>`: greater than
136+
* `<`: less than
137+
* `>=`: greater than or equal to
138+
* `<=`: less than or equal to
139+
* `-`: literal range. Eg: 1.2 - 1.4.5 is equivalent to >= 1.2, <= 1.4.5
140+
* `~`: minor range. Eg: ~1.2.3 is equivalent to >= 1.2.3, < 1.3.0
141+
* `^`: major range. Eg: ^1.2.3 is equivalent to >= 1.2.3, < 2.0.0
142+
* `[xX*]`: wildcard. Eg: 1.2.x is equivalent to >= 1.2.0, < 1.3.0
132143

133-
### `version`
144+
You might, for example, include a rule that specifies `version = "=2.0.0"` to pin a dependency to version 2.0.0, or constrain to minor releases with: `version = "~2.1.0"`. Refer to the [semver library](https://github.com/Masterminds/semver) documentation for more info.
134145

135-
`version` is a property of `constraint`s and `override`s. It is used to specify version constraint of a specific dependency.
146+
**Note**: When you specify a version *without an operator*, `dep` automatically uses the `^` operator by default. `dep ensure` will interpret the given version as the min-boundary of a range, for example:
136147

137-
Internally, dep uses [Masterminds/semver](https://github.com/Masterminds/semver) to work with semver versioning.
148+
* `1.2.3` becomes the range `>=1.2.3, <2.0.0`
149+
* `0.2.3` becomes the range `>=0.2.3, <0.3.0`
150+
* `0.0.3` becomes the range `>=0.0.3, <0.1.0`
138151

139152
`~` and `=` operators can be used with the versions. When a version is specified without any operator, `dep` automatically adds a caret operator, `^`. The caret operator pins the left-most non-zero digit in the version. For example:
140153
```
@@ -150,11 +163,21 @@ To pin a version of direct dependency in manifest, prefix the version with `=`.
150163
version = "=0.8.0"
151164
```
152165

153-
[Why is dep ignoring a version constraint in the manifest?](FAQ.md#why-is-dep-ignoring-a-version-constraint-in-the-manifest)
166+
### `branch`
167+
168+
Using a `branch` constraint will cause dep to use the named branch (e.g., `branch = "master"`) for a particular dependency. The revision at the tip of the branch will be recorded into `Gopkg.lock`, and almost always remain the same until a change is requested, via `dep ensure -update`.
169+
170+
In general, you should prefer semantic versions to branches, when a project has made them available.
171+
172+
### `revision`
173+
174+
A `revision` is the underlying immutable identifier - like a git commit SHA1. While it is allowed to constrain to a `revision`, doing so is almost always an antipattern.
175+
176+
Usually, folks are inclined to pin to a revision because they feel it will somehow improve their project's reproducibility. That is not a good reason. `Gopkg.lock` provides reproducibility. Only use `revision` if you have a good reason to believe that _no_ other version of that dependency _could_ work.
154177

155178
# Example
156179

157-
Here's an example of a sample Gopkg.toml with most of the elements
180+
A sample `Gopkg.toml` with most elements present:
158181

159182
```toml
160183
required = ["github.com/user/thing/cmd/thing"]

docs/deduction.md

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,20 @@ Deduction is dep's algorithm for looking at an import path and determining the p
77
- `github.com/golang/dep/gps` -> `github.com/golang/dep`
88
- `bitbucket.org/foo/bar/baz` -> `bitbucket.org/foo/bar`
99

10-
The set of hosts supported by static deduction are the same as [those supported by `go get`]().
10+
The set of hosts supported by static deduction are the same as [those supported by `go get`](https://golang.org/cmd/go/#hdr-Remote_import_paths):
1111

12-
If the static logic cannot identify the root for a given import path, the algorithm continues to a dynamic component, where it makes an HTTP(S) request to the import path, and a server is expected to return a response that indicates the root import path. This, again, is equivalent to the behavior of `go get`.
12+
* GitHub
13+
* Bitbucket
14+
* Launchpad
15+
* IBM DevOps Services
1316

17+
In addition, dep also handles [gopkg.in](http://gopkg.in) directly with static deduction because, owing to internal implementation details, it is the easiest way of also attaching filters to adapt the versioning semantics of gopkg.in import paths into dep's versioning model. This turns out fine, as gopkg.in's rules mapping rules are themselves entirely static.
1418

19+
If the static logic cannot identify the root for a given import path, the algorithm continues to a dynamic component: dep makes an HTTP(S) request to the import path, and a server is expected to send back the root import path embedded within the HTML response. Again, this directly emulates the behavior of `go get`.
1520

1621
Import path deduction is applied to all of the following:
1722

1823
* `import` statements found in all `.go` files
19-
* Import paths named in the [`required`](gopkg.toml.md#required) property in `Gopkg.toml`
20-
* `name` properties in both [`[[constraint]]`](Gopkg.toml.md#constraint) and [`[[override]]`](Gopkg.toml.md#override) stanzas in `Gopkg.toml`. This is solely for validation purposes, enforcing that these names correspond strictly to source roots.
24+
* Import paths in the [`required`](gopkg.toml.md#required) list in `Gopkg.toml`
25+
* `name` properties in both [`[[constraint]]`](Gopkg.toml.md#constraint) and [`[[override]]`](Gopkg.toml.md#override) stanzas in `Gopkg.toml`. This is solely for validation purposes, enforcing that these names correspond only to project/source roots.
2126

22-
23-
24-
25-
The results of import path deduction are, in practice, almost entirely fixed; it's easy to imagine why. In the public ecosystem, even dynamic deductions rarely change in practice, as it would either require:
26-
27-
- a `go-get` metadata service to intentionally change its mappings, or
28-
- a `go-get` metadata service to disappear.
29-
30-
`go get` itself is only partially resilient to these cases, but each is potentially catastrophic for a package's retrievability across the ecosystem, sooner rather than later. This steep and abrupt downside makes it nearly impossible for projects only accessible via an unreliable metadata service to ever become popular or widely used in the ecosystem. Thus, in the public ecosystem, we almost only ever see reliable, well-behaved services.
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
Because deduction has a dynamic component, the deducibility of any given path necessarily cannot be fixed. However, because the
42-
43-
## Static deduction

docs/introduction.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ Welcome! This is documentation for dep, the "official experiment" dependency man
88

99
This site has both guides and reference documents. The guides are practical explanations of how to actually do things with dep, whereas the reference material provides deeper dives on specific topics. Of particular note is the [glossary](#glossary.md) - if you're unfamiliar with terminology used in this documentation, make sure to check there!
1010

11-
12-
13-
* link to guides
14-
* installing dep
11+
If you're trying dep for the first time, check out [Creating a New Project](new-project.md), or [Migrating to dep](migrating.md) if you have an existing Go project that you want to manage with dep.

0 commit comments

Comments
 (0)