-
Notifications
You must be signed in to change notification settings - Fork 50
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
Import aliases break the so-called “minimal module support” in GOPATH mode #203
Comments
In case you're interested with removing import aliases: #204 |
Does |
As @vdemeester says, I think the right thing to do is But maybe it is appropriate to remove the import aliases now that the module indicates the correct path. I think your theory is likely correct, but I don't see anything about import aliases in that diff. Do you know if there is anything else written about this problem?
They used to be necessary, before modules, to get the custom import path |
@vdemeester So actually, neither
|
By "that diff", you mean the diff I propose at https://github.com/gotestyourself/gotest.tools/pull/204/files ? It's about removing all the In any case, removing those solves the problem for me:
|
Thanks for confirming that #204 does look right, and you are correct they are called import aliases. The diff I was talking about was the Go PR you linked (golang/go@28ae826). Edit; I was wrong, they are called "vanity import paths" not import aliases. I think most likely your PR is the correct solution, but I'd like to make sure I understand what the recommended approach is before making that change, just in case there is something we have missed. I'll see if I can find any information about import aliases compatibility with modules. |
For those of us still using GOPATH mode, it's still possible (or at least it should be) to use modern go packages with a
go.mod
seamlessly.For a working example : https://github.com/godbus/dbus
However it doesn't work with gotest.tools:
Question one: why does it work with
godbus
?Answer: Thanks to the so-called “minimal module support” that was introduced in golang/go@28ae826. Basically and as I understand it, Go rewrites the import path on the fly, so we can have godbus installed in the directory
$GOPATH/src/github.com/godbus/dbus
, despite the fact that ALL the import directives in the code refer github.com/godbus/dbus/v5
. The directoryv5
does not need to exist.Question two: why it doesn't work with
gotest.tools
then?Answer: Because of the import aliases. In gotest.tools, all the package lines are of the form
package assert // import "gotest.tools/v3/assert"
. It seems that the// import ...
prevents Go from rewriting the import path and dropping thev3
suffix.Suggestion: drop the import aliases?
I don't know the reason for these import aliases honestly. I tried to remove them all, and it works for me, but I don't know if it might break other configs.
The text was updated successfully, but these errors were encountered: