srusskih / SublimeJEDI

awesome Python autocompletion with SublimeText
MIT License
938 stars 109 forks source link

Support Expanding $virtualenv in `python_package_paths` #237

Closed gtalarico closed 6 years ago

gtalarico commented 6 years ago

$project_path can be used to to get python_package_paths to include the project's packages like this: `$project_path/venv/...

This however does not allow me to use envs that are stored centrally, like when using virtualenvwrapper: ~/envs/project_name/...

The virtualenv settings is set in the project settings, and is used by several other packages for setting the project's virtual environment

Proposal

Support expanding $virtualenv when used in the jedi's settings, more specifically in the python_package_paths key

Implementation

I have zero experience with Sublime packages :) but I think this might be all we need? https://github.com/srusskih/SublimeJEDI/blob/master/sublime_jedi/utils.py#L326

# utils.py # L326
def expand_path(view, path):
    subl_vars = {}
    try:
        subl_vars['$file'] = view.file_name()
        subl_vars['$packages'] = sublime.packages_path()
        subl_vars['$virtualenv'] = view.window().project_data().get('virtualenv')  # << Add this line
# Jedi Settings
{
    "python_package_paths": [
                             "$virtualenv\\Lib\\site-packages",
...

I made the edit in place in it seems to be working perfectly. Please let me know if this makes sense, I would be happy to send a PR and include in the Docs

srusskih commented 6 years ago

virtualenv is a good way to point to python environment that should be used by jedi.

can I ask why you want do something like this

# Jedi Settings
{
    "python_package_paths": [
                             "$virtualenv\\Lib\\site-packages",
...

this can got a side effect where python interpreter are difference from virtualenv python interpreter

gtalarico commented 6 years ago

Are you talking about the virtualenv package? If so, I have that installed, but jedi does not seem to pick up the packages in those locations unless I add them to the jedi settings a shown above : (

srusskih commented 6 years ago

if interpreter path pointed to bin/python from the venv then it should =(

srusskih commented 6 years ago

will be done in 0.12.0