Skip to content

Changes to auto-download of tools #37

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

Merged
merged 5 commits into from
Jul 10, 2020
Merged

Changes to auto-download of tools #37

merged 5 commits into from
Jul 10, 2020

Conversation

WhoIsSethDaniel
Copy link
Contributor

  • Allow no auto-download of tools (default is to auto-download)
  • Allow to install tools in the default $GOBIN (default is to install
    tools in /tools/bin
  • Create command that forces download of all tools

@WhoIsSethDaniel
Copy link
Contributor Author

Mostly looking for comments as to whether this can ever be accepted. If it can, I will add docs and make any requested changes.

I like the choices that this vim plugin has made but I did like, in vim-go, being able to use :GoInstallBinaries when I wanted. I have found the auto-download of tools a mixed bag.

I'd like to move :GoForceSetup to plugin/go.vim so that it is global and may be used like so:
vim -c :GoForceSetup -c :q
This can be useful when setting up a new environment.

@arp242
Copy link
Owner

arp242 commented May 29, 2020

Hey, thanks for your PR :-)

What is the use case for using a different $GOBIN? The intention behind using a our own $GOBIN is that I know which versions of which tools work, and that I want those exact versions to prevent upstream updates from breaking stuff, similar to e.g. the vendor directory in Go.

This happened several times when I maintained vim-go, and then we had to scramble to fix stuff, which wasn't great.

Just want to understand the problem so we can add the best fix :-)


As a general comment, I tried to prevent having a sprawl of different :Go* commands; pressing :Go<Tab> gives a huge list in vim-go, many of them unused by most users.

So I'd prefer something like :GoSetup force or :GoSetup! over a new :GoSetupForce command. The same applies to settings, e.g. a list of flags or dict in g:gopher_setup would be preferred, unless we're sure there will never be any more options, e.g.:

let g:gopher_setup = ['local-install', 'no-download']

I wouldn't change this just yet, btw, since we may decide solving your problem in a different way and I'd hate for you to waste your time.

@WhoIsSethDaniel
Copy link
Contributor Author

I like the :GoSetup! idea. I thought of doing that, but decided against it for this PR. I'm neutral as to the use of global settings. Fewer is probably better for the reason you give.

I mentioned in my earlier comment that one thing I would really like is for :GoSetup[!] to be available immediately. This allows for automation such as:

vim -c :GoSetup\! -c :q

to f.e. be run from scripts when initializing or updating an environment. One way this can be achieved is by moving the command definition to plugin/go.vim.

I understand the motivation for downloading the tools to a separate and controlled directory. I want to be able to use the same tools I use within vim when I am outside of vim. There are ways to do this without downloading to go's default $GOBIN. I can set $PATH to include this special directory. I can create symlinks from $GOBIN to the files in the special directory. These solutions are less appealing than having all tools (both tools downloaded by gopher and other tools downloaded separately) in a single, well-known place.

@arp242
Copy link
Owner

arp242 commented May 29, 2020

Right, so it's just a personal preference. That's fair enough, and don't mind supporting that. Just wondered if there's a problem you ran in to.


As for the setup, I think you should already be able to set up the environment with:

$ vim +'setf go' +GoSetup +q

The trick is to make sure the filetype is set to go, or alternatively you can also call the function directly:

$ vim +'call gopher#system#setup()' +q

I'm not sure if there are any differences in the :GoForceSetup logic vs. the regular one? I compared the new function to the existing code, and I think it does the same, but maybe I'm missing something; I wrote all of this 2 years ago and haven't looked much at this part since 😅

" By default autodownload of tools happens. However, if
" we want a 'local' install we can no longer have
" autodownload.
let s:tool_autodownload = s:use_gotools is 1 ? 1 : 0
Copy link
Owner

@arp242 arp242 May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you run in to a problem with the autodownload and the default GOBIN/local_install logic, or is it just something you'd prefer not to happen?

I think this could perhaps be two different settings: "use default GOBIN" and "don't download tools automatically"? I could imagine some people might prefer to use the default GOBIN but still keep the auto-download stuff (or use gopher.vim's GOBIN but never automatically download stuff).

Copy link
Contributor Author

@WhoIsSethDaniel WhoIsSethDaniel May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all true. The amount of refactoring that would be required to do that seemed greater than I was willing to devote when I was working on this PR. This PR was primarily a "here is an idea I have, will you accept it?" If you are okay with the concept behind the PR I can work on it. Or you or anyone else can. I think allowing auto-download while also placing tools in default $GOBIN sounds fine. The problem you run in to is when $GOBIN is unset. I think go uses $GOPATH and looks for a bin directory. But $GOPATH can be more than one path. So determining where exactly go would download tools to can be complicated. Unless there is a way to programatically determine this. I tried

go env GOBIN

but this doesn't return the default value if $GOBIN is unset. It just returns nothing.

Perhaps the solution is more obvious than I think it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about the $GOPATH issue sent me down a rabbit hole. This seems to be the best answer:
golang/go#23439
Hopefully go 1.15 will make it easier to determine where tools are installed when $GOBIN is unset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I mentioned all of the above because s:tool() performs an existence check on the tool using filereadable(). It requires the full path to the tool. This can be re-written using something like exepath() and there is no longer a need for the path at all.

@WhoIsSethDaniel
Copy link
Contributor Author

I think there is an advantage to calling :GoSetup over calling gopher#system#setup() directly. It is not guaranteed that gopher#system#setup() will always be the only thing called by :GoSetup. Or maybe the setup() function moves to a new name. These are minor concerns but :GoSetup is the umbrella over the setup process. For "future proofing" it seems better to call :GoSetup.

Setting the filetype is actually what I am doing now in my automation scripts. It's one of those things that can be done, but, perhaps, should not need to be done.

gopher#system#forcedownload is similar to s:tool. s:tool only downloads a single tool, only downloads to the tools/bin dir and will short-circuit for various reasons. forcedownload does no short-circuiting, will download either to tools/bin or default $GOBIN, and downloads all tools listed in the go.mod.

There may be a way to refactor such that there is less duplication of the call to 'go install'. I briefly spent some time looking at how to change s:tool to do this, but it wasn't immediately clear that this would be all that straightforward. This is something to look at if this PR is to move forward.

Thanks for looking at this PR. I appreciate it.

@arp242
Copy link
Owner

arp242 commented May 30, 2020

Okay, I added a new commit with documentation on the new behaviour (but didn't really implement anything yet); I think this would work for you?

I added a way to print some more info as well, because to be honest I was rather confused on what it is and isn't doing myself as there's quite a lot of logic in there now.

This also includes a basic prototype fix for the filereadable()/exepath() thing mention in the other thread.

I'll look some more at the entire thing next week or so.

Setting the filetype is actually what I am doing now in my automation scripts. It's one of those things that can be done, but, perhaps, should not need to be done.

That's fair enough, but on the other hand, making :GoSetup available everywhere means you'll have a "useless" command when editing non-Go files which I also don't really like. As far as I know, there is no real downside to setting the filetype so that seems like the better option since it's much rarer to have to do that than it is to edit non-Go files.

Aside: the API is quite stable (and documented) and should be guaranteed to be stable once 1.0 is released so gopher#system#setup() should be safe. I've just been working towards the 1.0 release very slowly as I want it to be slightly perfect 😅

WhoIsSethDaniel and others added 5 commits July 7, 2020 10:08
* Allow *no* auto-download of tools (default is to auto-download)
* Allow to install tools in the default $GOBIN (default is to install
  tools in <plugin>/tools/bin
* Create command that forces download of all tools
Also remove the verbose flag from :GoSetup as I don't feel like
implementing that correctly now (and it's not really related to this PR
anyway).
@arp242
Copy link
Owner

arp242 commented Jul 7, 2020

Okay, I did some more work on this and I think it should be done now; the new behaviour is documented at: https://github.com/arp242/gopher.vim/pull/37/files#diff-ddb7fdffdda30755d89d0c488e77e51dR255

I think this should work for you? Let me know and I'll merge it.

@WhoIsSethDaniel
Copy link
Contributor Author

Looks good to me. Thank you.

@arp242 arp242 merged commit 0f74a11 into arp242:master Jul 10, 2020
@arp242
Copy link
Owner

arp242 commented Jul 10, 2020

Coolio, let me know if you run in to any issues 👍

Sorry it took a while; I'm going to try and spend at least half a day a week on this so I can finally get the v1.0 out that I've been planning for almost 2 years now 😅 So hopefully things should move in a faster pace for the next while.

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

Successfully merging this pull request may close these issues.

2 participants