Refactor and simplify go fetcher code.
Review Request #3902 — Created May 17, 2016 and submitted
|2018, 3427, 3439|
This is not a small change... It gets rid of a lot of complex logic
that, with hindsight, doesn't appear to be necessary. It replaces
that complexity with a more simple approach.
This mirrors the direction that Go itself is moving in: Go's heuristics
for fetching remote deps (including the meta tag protocol) are becoming
increasingly standard. In fact, there are comments in Go's codebase(1)
to the effect that they encourage code-hosting sites to support the
meta tag protocol so that Go can remove its own hard-coded special cases.
Under this change there are two Fetcher types: The existing ArchiveFetcher,
and a new CloningFetcher.
ArchiveFetcher handles special cases where we know how to map an import
path to a tarball path. This is useful for sites like github.com, which
do not currently support the meta tag protocol, and also for diverting
fetches to an internal artifactory, for repos that wish to do so.
CloningFetcher implements (a useful subset of) the standard Go heuristics:
It checks meta tags, and then clones the remote repo and sets its state
to the specified rev (currently this only works for git).
All remote fetches that don't map to an ArchiveFetcher will use the
CloningFetcher. This makes it trivial to use standard git-based remote
repos without any extra config. In particular, gopkg.in, golang.org/x
and google.golang.org now support the meta tag protocol, so there is
no need to special-case them.
The Fetcher class API has also changed a bit. Now a Fetcher encapsulates
the import_path its fetching, so a new Fetcher instance is created for
each fetch operation. The Fetcher classes use Subsystems, but are no longer
For separation of concerns, this commit introduces two utility subsystems
that do what their names imply: GoImportMetaTagReader and ArchiveRetriever.
The fetchers use these. Note that they are not currently unit-tested,
because by the time you mock out the network stuff, there's not that
much left. However they are indirectly tested via several other unit and
This change gets rid of the fetcher advertisement+registration mechanism,
which with hindsight seems like overkill, given that we expect that the
current two Fetcher classes are all we're likely to need for the forseeable
future. The Fetchers class is gone. In its stead is much simpler
FetcherFactory subsystem. It now encapsulates the matcher logic, and uses
that to choose a fetcher.
This resolves https://github.com/pantsbuild/pants/issues/3439 and
https://github.com/pantsbuild/pants/issues/3427, and obsoletes
https://github.com/pantsbuild/pants/issues/2018, as we're now
going in a different, simpler, direction.
I can't add dbentley and yujie here because they aren't reviewers on RB, but
I will ask for their review feedback via email.
CI passes after all merges: http://jenkins.pantsbuild.org/job/pantsbuild/job/pants/branch/PR-3458/
Added various remote deps to one of the example targets and verified manually that it buildgens and compiles. Also added it to the integration test.
Address code review comments.
Catching up on reviews after some time away. This is my last catch-up to do, but its meaty. I'm going to push this to end of day, but a quick skim looks great to me!
LGTM - setting this up as an async shipit since all LGTM on the production path save for the `None` issue and stray file noted.
sources=globs('*.py', exclude=['go_distribution.py']),is slightly more sane until these 2 can be collapsed into 1 target.
Its titchy, but my preference here would be to add a
classmethodto act as a factory for a new
FetchErrorgiven an existing
FetchErrorand a prefix.
Callers aren't expecting or handling
Noneand the docs are silent. It seems like this should raise or else callers should be updated and either way docs should set the contract.
The https and then only fall back to http (possibly also only if flagged), as go does, would be good here. I'd be happy with a TODO + linked issue.
It would be great not to lose the meta-tag scraping tests even if it caused slightly more gymnastics in
GoImportMetaTagReader. Just testing
_find_meta_tagdirectly would be fine with me to limit gymnastics to ~0.
Revert - this looks like a buggy commit path... hopefully a test or buildgen is not creating this!
Address code review comments.
Revision 3 (+678 -981)
Revision 4 (+690 -1005)
Revision 5 (+696 -1014)
Submitted! Thanks for the reviews.