Skip to content
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

go 1.11 mod support #296

Open
llonchj opened this issue Oct 23, 2018 · 12 comments
Open

go 1.11 mod support #296

llonchj opened this issue Oct 23, 2018 · 12 comments

Comments

@llonchj
Copy link

llonchj commented Oct 23, 2018

kallax gen does not work when in a module outside GOPATH.

@gvs42
Copy link

gvs42 commented Dec 22, 2018

for me it does not work inside any gomod enabled src directory.
When GO111MODULE=off is set, then "kallax gen" generates code correctly. Otherwise the generated kallax.go is only an empty template.
With modules enabled, it does not list any Models found.

Output with modules enabled (GO111MODULE=on and go.mod in the src path):

Package: models

Output with modules disabled (GO111MODULE=off):

Package: models
Model: "ProductFeature" [59 Field(s)] [Events: [BeforeSave]]

@ibrt
Copy link

ibrt commented Mar 18, 2019

Sad workaround:

  1. Create a gen.sh file in your models package dir:
#!/usr/bin/env bash

set -e

rm -f "gen.go"

for PKG in $(go list -f '{{ join .Imports "\n" }}' | grep '\.'); do
    (cd "$HOME/go"; GOPATH="$(pwd)" go get -u "$PKG")
done

GO111MODULE=off kallax gen -e "gen.go" --output "gen.go"
  1. Use this go:generate comment:
//go:generate ./gen.sh

May or may not work with your setup, but you get the idea. Tested with Go 1.12.1 on macOS. The go get stuff is needed so that the code is compilable even if module support is off, by searching for deps in the default GOPATH.

@gvs42
Copy link

gvs42 commented Mar 21, 2019

Thanks for the workaround. Had basically the same thing in place, but I did not know about the Imports / go get part.

Any plans about supporting modules?

dpordomingo added a commit to dpordomingo/lookout that referenced this issue Apr 16, 2019
kallax models should be generated with 'make generate-go',
kallax migrations should be generated with
'MIGRTION_NAME=<name> make generate-migrations' and packed
with 'make pack-migrations'

All the code generation: kallax and vendor can be done
at once with 'make generate'

kallax does not work with go Modules, so it'll be disabled
issue: src-d/go-kallax#296

Signed-off-by: David Pordomingo <David.Pordomingo.F@gmail.com>
@efarrer
Copy link

efarrer commented Jun 11, 2019

It looks like kallax uses https://github.com/src-d/go-parse-utils for parsing go files. The go-parse-utils library exposes GOPATH as a first class concept parsutils.GoPath, parseutils.DefaultGoPath so I think a required step for making kallax support go modules is to create a version of go-parse-utils that abstracts away the concept of GOPATH and go modules. This work would likely break compatibility with the current library.

@felipemfp
Copy link

There has been any progress on this?

@iorlas
Copy link

iorlas commented Jul 2, 2019

Was so eager to try it out, but faces this problem. Would be awesome if we could support go mod.

@felipemfp
Copy link

felipemfp commented Jul 2, 2019

Was so eager to try it out, but faces this problem. Would be awesome if we could support go mod.

I've been using a variation of @ibrt script:

#!/usr/bin/env bash

set -e

export GO111MODULE=off
export GOPATH=/tmp/kallax

FILE=kallax.go

mkdir -p $GOPATH

if [ -f "$FILE" ]; then
    mv $FILE $FILE.old
fi

for PKG in $(go list -f '{{ join .Imports "\n" }}' | grep '\.'); do
    (cd "$GOPATH"; go get "$PKG")
done

if [ -f "$FILE.old" ]; then
    mv $FILE.old $FILE
fi

kallax $@

And it works pretty well and don't pollute my default GOPATH.

@iorlas
Copy link

iorlas commented Jul 2, 2019

And it works pretty well and don't pollute my default GOPATH.

It gives
go: cannot find main module; see 'go help modules' models/kallax_init.go:3: running "./kallax.sh": exit status 1

I'm not sure what's wrong, will take a look later today

@felipemfp
Copy link

felipemfp commented Jul 2, 2019

Do you have kallax installed and available on your PATH?

go get -u gopkg.in/src-d/go-kallax.v1/...

You may also want to omit the mv kallax.go kallax.go.old (and vice versa), if it's the first time.

The go:generate instruction would look like:

//go:generate $PATH_TO_SCRIPT/kallax.sh gen

s-kostyaev pushed a commit to s-kostyaev/go-kallax that referenced this issue Jul 5, 2019
s-kostyaev pushed a commit to s-kostyaev/go-kallax that referenced this issue Jul 5, 2019
Signed-off-by: Sergey Kostyaev <feo.me@ya.ru>
s-kostyaev pushed a commit to s-kostyaev/go-kallax that referenced this issue Jul 5, 2019
Signed-off-by: Sergey Kostyaev <sergey.kostyaev@bitfury.com>
erka added a commit to erka/go-kallax that referenced this issue Aug 28, 2019
zbyte added a commit to zbyte/go-kallax that referenced this issue Oct 1, 2019
@hlubek
Copy link

hlubek commented Jun 26, 2020

See https://github.com/networkteam/go-kallax for an updated fork (of a fork) that supports Go modules and also makes the tests with Go modules green again.

@llonchj
Copy link
Author

llonchj commented Jun 27, 2020

@hlubek, it appears that some import references should be fixed

$ go get -u github.com/networkteam/go-kallax/...
go: downloading github.com/networkteam/go-kallax v1.3.9
go: found github.com/networkteam/go-kallax/... in github.com/networkteam/go-kallax v1.3.9
go get: github.com/networkteam/go-kallax@v1.3.9: parsing go.mod:
        module declares its path as: github.com/zbyte/go-kallax
                but was required as: github.com/networkteam/go-kallax

@hlubek
Copy link

hlubek commented Jun 30, 2020

@hlubek, it appears that some import references should be fixed

$ go get -u github.com/networkteam/go-kallax/...
go: downloading github.com/networkteam/go-kallax v1.3.9
go: found github.com/networkteam/go-kallax/... in github.com/networkteam/go-kallax v1.3.9
go get: github.com/networkteam/go-kallax@v1.3.9: parsing go.mod:
        module declares its path as: github.com/zbyte/go-kallax
                but was required as: github.com/networkteam/go-kallax

Hi @llonchj,

maybe the pre-release tag wasn't fetched. For me it worked when I used go get github.com/networkteam/go-kallax in a project using Go modules. I just created a v1.4.0 tag to hopefully fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants