tkf / emacs-jedi

Python auto-completion for Emacs
http://tkf.github.io/emacs-jedi/latest/
666 stars 89 forks source link

Completion on non-global python module in virtualenv #316

Open nrsaty opened 6 years ago

nrsaty commented 6 years ago

I setup my emacs for specific python virtual environment, named ahone. But jediepcserver can not complete that environment's module name.

I use emacs 26.09 and python 3.6.5 on Windows/10. My configuration is:

(setq jedi:environment-root         "~/.emacs.d/site-lisp/jedi/env")
(setq jedi:complete-on-dot t)
(setq jedi:use-shortcuts nil)
(setq jedi:server-args `("--virtual-env" "~/ahone/Lib/site-packages"
                                 "--sys-path"    "~/ahone"))
(require 'jedi-core)
(require 'company-jedi)
(setq python-shell-interpreter      "ipython")
(setq python-shell-interpreter-args "--simple-prompt -i")
(setq python-indent-offset          2)
(setq python-indent-guess-indent-offset nil)
(add-hook 'python-mode-hook 'jedi:setup)
(add-hook 'python-mode-hook
          (lambda ()
            (set (make-local-variable 'company-backends)
                 '((company-jedi company-dabbrev-code company-yasnippet)))))

I did not activate ahone environment before starting emacs. But only specified the environment in --virtual-env parameter of jdeiepcserver as above. It's seems that this way is not good for specify python's virtual environment. Does anyone show me the correct way?

By the way, I glanced at codes, and found jedi.api.Script class has sys_path parameter in init(). Why jediepcserver did not use this? I'm not expert, and not sure that jedi module can handle this option correctly. But according to the comment, use this option is easy way to use with virtualenv, I feel.

In jediepcserver.py

    def jedi_script(source, line, column, source_path):
        :
        return jedi.Script(source, line, column, source_path or '')

will be something like this

    def jedi_script(source, line, column, source_path):
        :
        if (< Is jediepcserver has --virtual-env option? >) :
            return jedi.Script(source, line, column, source_path or ''
                               'utf-8' <current sys.path of jediepcserver>)
        else:
            return jedi.Script(source, line, column, source_path or '')

Does I misunderstand something?

immerrr commented 5 years ago

@nrsaty please try expanding tildes, they have no special meaning in how jedi or emacs-jedi treat file paths (expand-file-name is the elisp function if I read my configurations correctly).