getstream / vg Goto Github PK
View Code? Open in Web Editor NEWVirtualgo: Easy and powerful workspace based development for go
License: MIT License
Virtualgo: Easy and powerful workspace based development for go
License: MIT License
This should not happen, we should probably use process groups. Or custom signal handling.
Here's a simplified example:
(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ tree
.
├── hello
├── hello.go
└── internal
└── hello2
└── hello2.go
(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ cat internal/hello2/hello2.go
package hello2
import (
"fmt"
)
func Do() {
fmt.Println("hello2")
}
(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ vim hello.go
(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ cat hello.go
package main
import (
"hello/internal/hello2"
)
func main() {
hello2.Do()
}
Without vg:
callpraths@remote-workstation:/mnt/work/go/src/hello$ go run hello.go
hello2
With vg (but fallback to GOPATH):
callpraths@remote-workstation:/mnt/work/go/src/hello$ vg init
Creating workspace "hello" with global fallback import mode
Activating hello
Linking /mnt/work/go/src/hello to workspace 'hello'
(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ go run hello.go
hello2
With vg (full isolation):
(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ vg destroy
Destroying workspace "hello"
Deactivating hello
callpraths@remote-workstation:/mnt/work/go/src/hello$ vg init --full-isolation
Creating workspace "hello" with full isolation import mode
Installing local sources at "/mnt/work/go/src/hello" in workspace as "hello" using bindfs
Persisting the local install for "hello"
Activating hello
Uninstalling "hello" from workspace
Unmounting bindfs mount at "/home/callpraths/.virtualgo/hello/src/hello"
Removing sources at "/home/callpraths/.virtualgo/hello/src/hello"
Installing local sources at "/mnt/work/go/src/hello" in workspace as "hello" using bindfs
Persisting the local install for "hello"
Linking /mnt/work/go/src/hello to workspace 'hello'
(hello) callpraths@remote-workstation:/mnt/work/go/src/hello$ go run hello.go
hello.go:4:2: use of internal package not allowed
Case 1: Destroyed environments are re-created again with cd
[host]xyz_proj$ vg init
...
(xyz_proj) [host]xyz_proj$ vg destroy
[host]xyz_proj$ cd any_other_folder
[host]any_other_folder$ cd xyz_proj
Creating workspace "xyz_proj" with global fallback import mode
Activating "xyz_proj"
(xyz_proj) [host]xyz_proj$
I've managed to fix the problem with new condition to activate function:
__vg_auto_activate() {
activation_root=$PWD
while [ "$activation_root" != "" ]; do
if [ -f "$activation_root/.virtualgo" ]; then
new_virtualgo_name=$(cat "$activation_root/.virtualgo")
if [ "" = "$VIRTUALGO" ] || [ "$new_virtualgo_name" != "$VIRTUALGO" ]; then
# that's what I added
if [[ -d "$HOME/.virtualgo/$new_virtualgo_name" ]];then # <=========
vg activate "$new_virtualgo_name"
fi
fi
return
Also, I think that vg destroy
should do vg unlink
automatically
Case 2: Activate in child folder of folder that is linked to some vg environment will create new environment instead of activating parent.
src is a child folder of goenv:
(goenv) [host]src$ vg deactivate
Deactivating goenv
[host]src$ vg activate
Creating workspace "src" with global fallback import mode
Activating src
We have a project that uses a variety of home-grown shell scripts to provide a similar experience to vg. I'd like to replace it with vg.
One nice feature of our project is that you can check it out anywhere and it will work immediately (as long as you run our shell wrapper, which works well with direnv). We store the equivalent to the ~/.virtualgo/V
directory inside a gitignored directory in the repo itself. That way you can have multiple checkouts and they just work.
So to port to vg our scripts (we'd still have direnv scripts because we set up non-Go environments as well) would like to be able to just use a fixed environment name and a virtualgoroot that's not global, rather than a global virtualgoroot and a variable environment name.
It looks like we should be able to just define, say, $VIRTUALGOROOT
, and use it instead of ~/.virtualgo in the shell scripts and utils.Virtualgoroot. Is that a PR you'd take?
I'm currently using Gogland for go development. Switching over to vg definitely helps with reducing CPU load and in general making gogland snappier.
Running tests still works as expected. When setting breakpoints and running tests in debug mode, it seems like the breakpoints are not registering at all. My current fallback solution is to set GOPATH back to my default global path, effectively disabling vg
, but that defeats the purpose of using it in the first place :)
This may be an OS X thing and how it deals with symlinks, but I thought I'd see if anyone else has a good way of dealing with this.
I'm using Atom
and go-plus
plugin. After I installed grpc
package, the go-plus
showed the following error:
main.go:8:2: cannot find package "google.golang.org/grpc" in any of:
/usr/local/opt/go/libexec/src/google.golang.org/grpc (from $GOROOT)
/[mypath]/src/google.golang.org/grpc (from $GOPATH)
but I can run it in the terminal without any error:
go run main.go
Discovering this automatically is hard. We should at least allow a --executable
/--bin
flag to vg uninstall
to indicate that an executable should be removed as well.
using 0.6.5 the output of go list ./...
is incorrect
eg.
github.com/goadapp/goad
is listed as _/Users/tommaso/src/go_development/src/github.com/goadapp/goad
Command vg ensure
run within the project directory and activated workspace returns:
(project) [user@machine project][✔]$ vg ensure
Running "dep ensure"
Error: Couldn't move the vendor directory to the active workspace: rename vendor /home/user/.virtualgo/project/src: invalid cross-device link
Usage:
vg ensure [-- [arguments to dep ensure]] [flags]
Flags:
-h, --help help for ensure
Couldn't move the vendor directory to the active workspace: rename vendor /home/uservirtualgo/project/src: invalid cross-device link
This is caused by the fact that my home directory is located on one device (/dev/sdb3
) and my project directory on another (/dev/sda1
). Call to os.Rename
(https://github.com/GetStream/vg/blob/master/cmd/ensure.go#L143) will return a LinkError
.
Hi,
I'm using POWERLEVEL9K
theme on zsh. When I activate a virtual environment, the theme doesn't change to show the name of the current environment. I sometimes forgot to deactivate it. How to set up zsh for showing the name of activated environment?
thanks
P.S: I'm using OSX and my zsh is the latest version.
Too many errors saying /root/go/src/github.com/spf13/cobra/bash_completions.go:566:28: undefined: io.StringWriter
dep
publish binary executable on GitHub for each version. It would be great if vg
can do the same too. This allows installation specific version of vg
in CI or via homebrew.
dep
build the executables using travis. There travis script is here: https://github.com/golang/dep/blob/master/.travis.yml
There seems to be no writeup on this matter in the documentations (aka README). I'm using vg with dep and my current way of installing executables is putting them in required
field inside Gopkg.toml
When changing from one workspace to another in fish, the prompt updating fails. It's worth noting that I've have a function in my fish config also called fish_prompt
:
https://github.com/karlek/dotfiles/blob/master/.config/fish/conf.d/08-prompt.fish
(gateway) (^._.^)ノ elysium @ /home/_/.local/share/go/src/github.com/karlek/tf/gateway $ ../keysmith/
Deactivating gateway
functions: Function “fish_prompt” already exists. Cannot create copy “_old_fish_prompt”
- (line 109):
functions -c _old_fish_prompt fish_prompt
^
in function “_vg_deactivate”
called on line 46 of file -
in function “_vg_activate”
called on line 13 of file -
with parameter list “activate keysmith”
in function “vg”
called on line 189 of file -
with parameter list “activate keysmith”
in function “__vg_auto_activate”
called on line 5 of file /usr/share/fish/functions/cd.fish
with parameter list “VARIABLE SET PWD”
in event handler: handler for variable “PWD”
functionsfunctions - print or erase functions
-
Synopsis
functions [ -a | --all ] [ -n | --names ]
functions [ -D | --details ] [ -v ] FUNCTION
functions -c OLDNAME NEWNAME
functions -d DESCRIPTION FUNCTION
functions [ -e | -q ] FUNCTIONS...
functions: Type “help functions” for related documentation
Activating keysmith
(keysmith) _@elysium ~/.l/s/g/s/g/k/t/keysmith>
The VG version of pip install -e . isn't clearly explained. Say that I'm working on a package and want to clone and edit one of the dependencies, how do i do that with VG?
Tommaso showed me one solution, we should document it.
Document which variables vg
exposes and also document the last-ensure
file.
Below github.com/qubit-sh/go-crypto
is a persisted package (symlinked from /Users/mmuthanna/.virtualgo/qubit/src/github.com/qubit-sh/go-crypto
.)
$ vg ensure -- -v -update
Running "dep ensure -v -update"
Root project is "github.com/qubit-sh/xpoller"
1 transitively valid internal packages
2 external packages imported from 2 projects
(0) ✓ select (root)
(1) ? attempt github.com/qubit-sh/go-crypto with 1 pkgs; 1 versions to try
(1) try github.com/qubit-sh/go-crypto@master
<SNIP>
Uninstalling "github.com/qubit-sh/go-crypto" from workspace
Removing sources at "/Users/mmuthanna/.virtualgo/qubit/src/github.com/qubit-sh/go-crypto"
Error: Couldn't move the vendor directory to the active workspace: rename vendor /Users/mmuthanna/.virtualgo/qubit/src: no such file or directory
Usage:
vg ensure [-- [arguments to dep ensure]] [flags]
Flags:
-h, --help help for ensure
Couldn't move the vendor directory to the active workspace: rename vendor /Users/mmuthanna/.virtualgo/qubit/src: no such file or directory
The workaround is to call vg ensure
immediately after to relink the persistent package.
When I activate a workspace using vg
while my GOPATH
is empty, the new GOPATH
ends in a colon, followed by the original empty GOPATH
, which confuses go:
matthijs@grubby:/$ cd /path/to/bar/
Activating bar
Uninstalling "github.com/foo/bar" from workspace
Unmounting bindfs mount at "/home/matthijs/.virtualgo/bar/src/github.com/foo/bar"
Removing sources at "/home/matthijs/.virtualgo/bar/src/github.com/foo/bar"
Removing "github.com/foo/bar" from locally installed packages
Installing local sources at "." in workspace as "github.com/foo/bar" using bindfs
(bar) matthijs@grubby:/path/to/bar$ echo $GOPATH
/home/matthijs/.virtualgo/bar:
(bar) matthijs@grubby:/path/to/bar$ go build
go: GOPATH entry is relative; must be absolute path: "".
For more details see: 'go help gopath'
I realize that using a fully-isolated workspace would work here, but would it perhaps make sense to just ignore the previous GOPATH if it is empty?
combines activate and connect
With dep -dry-run
no vendor
directory is created which vg ensure
expects. A clearer error for this would be good, but actual behaviour should stay basically the same.
The first lines of vg help
look suspiciously like a placeholder text :)
$ vg help
A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.
(...)
(vg 0.6.0)
.bashrc
/.bash_profile
/.profile
should be changeddep init
does not work when vg is activated (path is not in GOPATH)
workaround:
vg globalExec -- dep init
I'm a bit stubborn when it comes to go and directory organisation, so I tried to use vg
to create a git clone of my project in whatever directory I wanted (without having to have it in src/github.com/foo/bar
). I was hoping that that would take care of creating a virtual GOPATH somewhere, and automatically link my project directory into there in an appropriate place. Unfortunately that did not happen, so I needed a manual vg localInstall
to get my project directory linked (which makes sense, since vg
does not know the full package name of my project).
So, I tried:
/path/to/bar$ vg localInstall github.com/foo/bar .
/path/to/bar$ mount|grep bar
/path/to/bar on /home/matthijs/.virtualgo/bar/src/github.com/foo/bar type fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000,default_permissions)
Which indeed correctly puts /path/to/bar
in the virtual $GOPATH/src/github.com/foo/bar
. However, in virtualgo.toml
it stores the original relative path .
, and it seems this path is interpreted relative to the current directory, not the project root. E.g. if I deactivate the workspace and then jump into a subdirectory of my project, things get broken:
/$ cd /path/to/bar/sub/
Activating bar
Uninstalling "github.com/foo/bar" from workspace
Unmounting bindfs mount at "/home/matthijs/.virtualgo/bar/src/github.com/foo/bar"
Removing sources at "/home/matthijs/.virtualgo/bar/src/github.com/foo/bar"
Removing "github.com/foo/bar" from locally installed packages
Installing local sources at "." in workspace as "github.com/foo/bar" using bindfs
(bar) matthijs@grubby:/path/to/bar/sub$ mount|grep bar
/path/to/bar/sub on /home/matthijs/.virtualgo/bar/src/github.com/foo/bar type fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000,default_permissions)
Should the path passed to localInstall
be made absolute before storing it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.