davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.27k stars 370 forks source link

Is here a way to config some thing like "sys.path" when jedi handle import statement? #182

Closed prim closed 10 years ago

prim commented 11 years ago

Hi, all. Here is my problem:

I am a mmo game server programmer. There are serveral server process share a common package and have their owner code. The directory looks like

    /Project/
        AuthServer/
            server.exe 
            script/
                init.py
                auth.py
        SceneServer/
            sever.exe 
            script/
                init.py
                scene.py
        Common
            Network/
                socket.py
            Database/
                sql.py

The python code is not run in a standard way like C:\Python27\python.exe or /usr/bin/pydothon, the python code is be call by cpp engine. When the SceneServer start, the sys.path will be modify to ["/Project/SceneServer/script","/Project/Common"]. When the AuthServer start, the sys.path will be modify to ["/Project/AuthServer/script","/Project/Common"].

Usually I code under .../SceneServer/script/ in vim, jedi can complete well when I import the other module in this directory. But I can not figure out how to make jedi complete the code in the Common package when I word in SceneServer/script or AuthServer/script.

Is there a way to solve this problem? Sorry for my poor English. :(

davidhalter commented 11 years ago

I'm not exactly sure if I understand the issue correctly. It seems like you're having problems problems with the sys.path. Is that right? In some cases your sys.path seems to be "missing" in Python code and Jedi cannot work because of that.

What you can always do is change the sys.path in vim manually (You can also add that to your .vimrc). This would make it work, if you don't want to modify your codebase. But it's just a poor workaround.

I guess I cannot offer another solution, except restructuring your code. Would that be an option? Just modify the sys.path to the parent folder of Project in cpp. You can use imports like from Project.Common.Network import socket then (and please use lower case letters :-)). You can also use from ..Database import sql if you're in Network/socket.py. That's IMHO the pythonic way. You should do it that way.

Sorry for my poor English. :(

No worries :-) A lot of us programmers are not excellent English speakers.

davidhalter commented 10 years ago

Closing because of inactivity.