pythonic-emacs / anaconda-mode

Code navigation, documentation lookup and completion for Python.
GNU General Public License v3.0
706 stars 87 forks source link

Prioritise server directory dependencies over virtual environment's #416

Closed MarTango closed 2 years ago

MarTango commented 3 years ago

I was using poetry.el and anaconda-mode together, and anaconda was using the project's jedi package instead of the one in the server, as site.addsitedir() .append()s the folder to the path, instead of prepending it.

This is a rather rudimentary fix as I'm not entirely sure what site.addsitedir() does.

Feedback/alternative fix is welcome.

dakra commented 2 years ago

Sorry for the late response. I installed the patch with a few changes. addsitedir is not needed anymore any you should insert on 1 instead of 0, as 0 is the python interpreter path and someone could depend on that (even if it's unlikely).

Thanks

MarTango commented 2 years ago

you should insert on 1 instead of 0, as 0 is the python interpreter path and someone could depend on that (even if it's unlikely).

@dakra doesn't this mean that (e.g.) if you have a folder called jedi in your current directory (default-directory when the anaconda server starts), the server will/might break?

The only usecase of allowing the interpreter path take precedence is if you want the user to override anaconda behaviour on a per-project basis?

dakra commented 2 years ago

I got the hint with sys.path 1 from https://stackoverflow.com/a/10097543/480468

The reasoning is that someone (/some lib) could depend on sys.path[0] to receive the folder for the script that called the python process.

I think it's not really relevant for our anaconda script as we only use jedi and service_factory as external dependencies.

For me sys.path[0] is '/home/daniel/.emacs.d/lib/anaconda-mode' which is where the anaconda-mode.py script is stored. Maybe it's even a positive to leave it as it is now, then you could put a jedi folder into your Emacs anaconda-mode folder to easier test local dev jedi versions?!

So I would say we leave it at position 1, but I don't have a strong opinion and also don't mind to change it to 0 if you want and find a good reason to.

MarTango commented 2 years ago

Yep, makes sense!

I wasn't aware that :cwd (anaconda-mode-get-server-process-cwd) is set when starting the server, so I was worried that sys.path[0] would just be an arbitrary path from where the user opened emacs