sourcegraph / srclib

srclib is a polyglot code analysis library, built for hackability. It consists of language analysis toolchains (currently for Go and Java, with Python, JavaScript, and Ruby in beta) with a common output format, and a CLI tool for running the analysis.
https://srclib.org
Other
942 stars 62 forks source link

failed to install/upgrade Python toolchain: GOPATH not set #69

Closed klonuo closed 9 years ago

klonuo commented 9 years ago

Hi,

I wanted to try Sublime Text plugin with Python source, but I keep getting no result and it's not clear if Python is supported out-of-the-box or not. So after installing golang I tried this:

$ src toolchain install-std
Installing/upgrading standard toolchains...

Go (sourcegraph.com/sourcegraph/srclib-go) ====================================
skipped sourcegraph.com/sourcegraph/srclib-go: no GOPATH set (assuming Go is not installed and you don't want the Go toolchain)

Python (sourcegraph.com/sourcegraph/srclib-python) ============================
Downloading or updating Python toolchain in /home/klo/.srclib/sourcegraph.com/sourcegraph/srclib-python
Running  [src toolchain get -u sourcegraph.com/sourcegraph/srclib-python]
failed to install/upgrade Python (sourcegraph.com/sourcegraph/srclib-python) toolchain: GOPATH not set

Googling around I coudn't find what exact location should I set to GOPATH as I'm not familiar with the language and it's packaging system and the context on which I should set it.

samertm commented 9 years ago

Hey klonuo, thanks for checking srclib out! Yeah, srclib-python currently has a rather large dependency on Go, so you'll need to set up your GOPATH after downloading Go.

The GOPATH is what Go uses as its "workstation": it will download code to $GOPATH/src, install binaries in $GOPATH/bin, and put object files in $GOPATH/pkg. You can set it to anything you want, but I have a "code" directory in my home directory, and I added the line "export GOPATH=/home/samer/code/go" to my .bashrc.

If you're on a Mac, setting environmental variables is a bit tricky for gui applications. I pushed a change so that you can specify the full path for the "src" tool, but it hasn't taken on Package Control yet. I can ping you when it's up to date, though I didn't expect it to take this long.

Let me know if you have any other questions!

klonuo commented 9 years ago

Thanks for your explanation.

Additionally I had to add $GOPATH/bin to my PATH. After successfully finishing previous command, it seems like Python support is present:

$ src toolchain list-tools
TOOLCHAIN                                 TOOL                OP               SOURCE UNIT TYPES        
sourcegraph.com/sourcegraph/srclib-go     scan                scan             GoPackage                
sourcegraph.com/sourcegraph/srclib-go     graph               graph            GoPackage                
sourcegraph.com/sourcegraph/srclib-go     depresolve          depresolve       GoPackage                
sourcegraph.com/sourcegraph/srclib-python  scan                scan             PipPackage               
sourcegraph.com/sourcegraph/srclib-python  graph               graph            PipPackage               
sourcegraph.com/sourcegraph/srclib-python  depresolve          depresolve       PipPackage 

Maybe I don't understand how this is supposed to work, but I can't get anything out in Sublime Text. I created a file with simple statement import sys; print(sys.path) and calling the plugin on highlighted sys.path - here is the result:

sourcegraph: ERROR: src api describe failed: Command '['src', 'api', 'describe', '--file', '/home/klo/temp/test.py', '--start-byte', '12', '--no-examples']' returned non-zero exit status 1

On a side note, I'd like to mention that plugin currently does not handle opened buffer file, if it is not saved to a file on disk:

sourcegraph: ERROR: src api describe failed: Can't convert 'NoneType' object to str implicitly