-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: relative imports do not work with vendoring #15478
Comments
Your need to put your source in GOPATH. From the example you posted (sorry |
@davecheney I've been putting it in GOROOT, I updated now to use GOPATH, same issue persists.
So, sorry, no. I also tried putting everything in |
I belive GOPATH is not set in your enviroment correctly. I believe this Is it possible to isolate your issue by removing docker? |
I don't have an environment outside of docker where I can run the tests. If I get one, I'll post the results, and if you have one, please just stick the sources from the tgz into $GOPATH/src/app and run But, my sanity check here tells me that you shouldn't be so suspicious, I'll attach my results if I can get my hands on on a local install of go somewhere. |
You shouldn't need docker to compile your tests -- they may not pass, but |
I just checked out your sample. Sorry I should have done that before. The root cause is you are using go run, which does not support vendoring. I recommend you lay out your code in the prescribed package format as Then compile and run your program. |
I'm having the same result with
So if I understand you, instead of using "subpackage" I should create
Is there a way to achieve something similar for local development without a recognized VCS location? I believed until now that: import "./package" was it. |
Yes, packages are just directories on disk. They follow the url based |
I think that currently local (relative) imports do not work with vendoring. I am not sure if it is even possible to make these features work together. Local imports do not work in some other cases as well (see for example http://stackoverflow.com/questions/10687627/relative-import-from-parent-directory). |
@davecheney It is just slightly awkward if you're using @kostya-sh That's unfortunate. I guess I'd mark this issue as a feature request then, I would very much like local imports to work with vendoring. |
If anybody is coming here for a fix, this worked for me:
I will not close this issue, just because I expect that this should be fixed in a future version. I hope someone agrees and tags/assigns the issue properly. Relative imports should work with vendoring, but I understand the motivations for FQDN imports. Considering that i'm using them from the main package, which is a reasonable "root" of the project, and if I'll ever reuse it from another package i would use the FQDN import from a VCS/other. In the current state I would have to rewrite './' to |
It looks like there were several different issues at play in this thread. @titpetric, could you summarize the remaining problem that you want to be fixed, ideally as a list of commands that we can run in isolation to observe the problem? (A I suspect that this is another instance of #14566 / #18007, but since I don't really understand the problem statement it's hard to be sure. |
There's only one issue, vendoring doesn't play well with relative imports.
package main
import (
"fmt"
"./errors"
)
func main() {
fmt.Println(errors.Error404())
}
package errors
import (
e "github.com/pkg/errors"
)
func Error404() error {
return e.New("Not found")
} Expected result: stdout Actual result:
I verified the above with Go 1.6-1.11:
|
Neither of the paths listed in that comment includes a Please provide a list of specific commands that we can run to reproduce the problem, starting from an empty |
I apologize, I believed I was clear that the vendor/ folder should come from `go dep`, it seems to have gotten lost in a comment edit (I was too much in a rush).
The `github.com/pkg/errors` repo should be vendored. You can use `go get` to retrieve it and then just copy it into the vendor/ folder to provide `vendor/github.com/pkg/errors/*`.
|
Here you have it:
|
Ok, this is definitely #18007. When you use a relative path from within |
go version
)?go version go1.6.1 linux/amd64
go env
)?Linux serenity 4.3.0-1-amd64 #1 SMP Debian 4.3.5-1 (2016-02-06) x86_64 GNU/Linux
Running golang with Docker image, official golang build, latest image from docker hub.
Full reproduction script available with
./run
Source files: https://cdn.si/assets/go-gh-issue-vendoring.tgz
I created a small program, using a local subpackage.
main.go (using a subpackage + vendor) = experienced problem.
main2.go (using vendored import from main) = works as expected.
Subpackage is imported with: import "./apiservice". Import of vendored package from this subpackage results in a run/build error.
Also included is a test-runner using the official
golang
docker image. It's the same environment, that I'm running the example in. The folder vendor was created withgvt fetch github.com/namsral/flag
, full source provided.Expected output with main.go:
Problem:
Import path for local subpackage is not honored. The dot gets converted to underscore, and as a consequence, it's looking for the vendor directory in the wrong path:
Expected path:
The text was updated successfully, but these errors were encountered: