Code Monkey home page Code Monkey logo

Comments (7)

davidhalter avatar davidhalter commented on July 20, 2024

I explain you how it currently works:
https://github.com/davidhalter/jedi/blob/master/jedi/builtin.py#L16

takes the sys path at startup and saves it. All further uses of Jedi depend on that line.

What do you think? Should we change that? I don't know why anyone would use it...
Basically virtualenv support should be something that Jedi does and not some plugin.

from jedi.

tkf avatar tkf commented on July 20, 2024

I am using the code above in my Emacs plugin and wonder why it does not work. If Jedi provides API to add module path I think that's fine. Why do you need to cache sys.path anyway? Because you need to cache the result of analyzing modules?

BTW if you want to filter out an empty string from sys.path I think it's better to use filter(None, sys.path) as the empty string might be anywhere in the list.

from jedi.

dbrgn avatar dbrgn commented on July 20, 2024

In jedi-vim, the problem is that the interpreter used by vim is not using the virtualenv at all. So you can't detect the virtualenv from "within" the Python code, as it's not in PYTHONPATH used by vim.

If you want to provide virtualenv support from jedi itself, there might be different possibilities:

  • Generic approach: Provide an easy way to add additional PYTHONPATH parts to a completion object
  • Specialized approach: Provide a virtualenv=<path> parameter
  • Rely on env variables (see code at davidhalter/jedi-vim#31 (comment))

I think the plugins should be responsable for PYTHONPATH magic (as long as they don't use a separate python environment it already works as is), but jedi should provide tools to easily detect and/or register virtualenvs.

from jedi.

tkf avatar tkf commented on July 20, 2024

I am running this function before importing jedi. Doesn't this work in vim, provided that you start vim from a shell in which virtualenv is activated?

def add_virtualenv_path():
    """Add virtualenv's site-packages to `sys.path`."""
    venv = os.getenv('VIRTUAL_ENV')
    if not venv:
        return
    venv = os.path.abspath(venv)
    path = os.path.join(
        venv, 'lib', 'python%d.%d' % sys.version_info[:2], 'site-packages')
    sys.path.insert(0, path)

https://github.com/tkf/emacs-jedi/blob/master/jediepcserver.py

from jedi.

dbrgn avatar dbrgn commented on July 20, 2024

I guess that fix is the best solution we'll be able to come up with, but it could be moved into jedi itself as a helper function. What do you think? @tkf @davidhalter @strycore

from jedi.

davidhalter avatar davidhalter commented on July 20, 2024

I wouldn't use it as a helper function but as the default importing behavior, which means adding this to the cached builtin.module_find_path. (Maybe getting rid of the module_find_path would also be an option if we're changing things).

Probably we should also add an option to settings.py, which could turn this behavior off.

from jedi.

tkf avatar tkf commented on July 20, 2024

I agree with you. Having the same function in vim/emacs/sublime text bindings does not make sense.

But at same time, I think jedi should expose an API to set sys.path. I am doing lazy import in Emacs binding and because of that, I can't use jedi against jedi functions, which is kind of sad. It's not urgent as we have a workaround, though.

from jedi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.