pythonic-emacs / anaconda-mode

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

Prevent conflicts with stdlib modules by changing working directory #392

Closed schmir closed 4 years ago

schmir commented 4 years ago

Change the current directory when starting the anaconda server.

The current directory will be added to sys.path and we may end up with files that conflict with stdlib modules. That may prevent the anaconda server from starting:

Let's say we're working on a package 'foo', that contains a module 'foo.logging'.

The following commands can be used to create such a package:

,----
| mkdir foo
| touch foo/__init__.py
| touch foo/logging.py
| touch foo/core.py
`----

If we then open foo/core.py with emacs foo/core.py, the *anaconda-mode* buffer contains the following error:

,----
| Traceback (most recent call last):
|   File "<string>", line 65, in <module>
|   File "/home/ralf/.emacs.d/anaconda-mode/0.1.13/jedi-0.17.2-py3.8.egg/jedi/__init__.py", line 32, in <module>
|     from jedi.api import Script, Interpreter, set_debug_function, \
|   File "/home/ralf/.emacs.d/anaconda-mode/0.1.13/jedi-0.17.2-py3.8.egg/jedi/api/__init__.py", line 15, in <module>
|     import parso
|   File "/home/ralf/.emacs.d/anaconda-mode/0.1.13/parso-0.7.0-py3.8.egg/parso/__init__.py", line 42, in <module>
|     from parso.grammar import Grammar, load_grammar
|   File "/home/ralf/.emacs.d/anaconda-mode/0.1.13/parso-0.7.0-py3.8.egg/parso/grammar.py", line 7, in <module>
|     from parso.python.diff import DiffParser
|   File "/home/ralf/.emacs.d/anaconda-mode/0.1.13/parso-0.7.0-py3.8.egg/parso/python/diff.py", line 39, in <module>
|     LOG = logging.getLogger(__name__)
| AttributeError: module 'logging' has no attribute 'getLogger'
`----

In that case python tried to import the stdlib logging module from foo/logging.py, which is of course bound to fail.

schmir commented 4 years ago

I just noticed this doesn't work if you start without the anaconda server directory already being created. I'll update this PR later.

schmir commented 4 years ago

I just noticed this doesn't work if you start without the anaconda server directory already being created. I'll update this PR later.

This is fixed. Not sure if what I did works with tramp though.

CeleritasCelery commented 4 years ago

Thanks