How to run file watcher in virtual environment in GoLand?

huangapple go评论86阅读模式
英文:

How to run file watcher in virtual environment in GoLand?

问题

我在GoLand中启用了golangci-lint文件监视器,但是当我保存文件时,会出现以下错误:

msg="Running error: context loading failed: no go files to analyze"

经过一些调试,我发现当我在没有激活虚拟环境的情况下运行golangci-lint时会出现这个错误。
所以我的问题是,我如何告诉文件监视器在激活虚拟环境后运行golangci-lint?

所以,总结一下,我想要的是:
在运行任何文件监视器命令之前,运行以下命令:

source .my_virtual_env_folder/bin/activate

这个命令基本上是激活虚拟环境。

我是GoLand的新手。我尝试进行了谷歌搜索,但没有找到解决办法。

英文:

I have enabled golangci-lint file watcher in GoLand but when I save file I got error like below one:

> msg="Running error: context loading failed: no go files to analyze"

After some debugging I found that this error comes when I run golangci-lint without activating my virtual env.
So my question is how do I tell file watcher to run golangci-lint after activating virtual environment?

So, In summary I want this:
Before running any file watcher command, Run this command

> source .my_virtual_env_folder/bin/activate

This command is basically activates virtual environment.

I am new to GoLand. I tried to do google search but no luck.

答案1

得分: 1

我找到了一个解决方法。

创建一个可执行文件,在其中编写所有的命令。我们可以完全控制要运行的命令以及它们的顺序。然后在文件监视器的"Program"中,粘贴该文件的绝对路径。

我只是在文件的顶部写了source <name_of_the_env>/bin/activate,然后写下了我的主要命令。

这样可以激活虚拟环境,然后调用命令。

英文:

I found a workaround.

Make a executable file, write all the commands there. We have full control on which commands do we want to run and in which order. Then in file watcher "Program", paste the absolute path of this file.

I just wrote source &lt;name_of_the_env&gt;/bin/activate at the top of file and then wrote my main command.

This way it activated the virtual environment and then call the command.

huangapple
  • 本文由 发表于 2022年6月4日 15:28:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/72497898.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定