How can I tell the shell to always open relative to my project root?
I have the following python project structure:
mypyjunk ├── mypyjunk │ ├── common.py │ ├── __init__.py │ └── jitter.py ├── README.md └── tests ├── __init__.py └── test_all.py
from mypyjunk.common import constants def do_things(): print(constants)
When I open this file and open a shell interpreter with
C-c C-p, I try to send the buffer to the interpreter with
C-c C-r, it says:
>>> from mypyjunk.common import constants ... ... ... def do_things(): ... print(constants) Traceback (most recent call last): File "<string>", line 17, in __PYTHON_EL_eval File "/home/user/mypyjunk/mypyjunk/jitter.py", line 1, in <module> from mypyjunk.common import constants ModuleNotFoundError: No module named 'mypyjunk'
Which tells me this shell has an unexpected root directory, eg:
>>> import os >>> os.getcwd() '/home/user/mypyjunk/mypyjunk'
/home/user/mypyjunk/ where my absolute imports would make sense.
What settings do I need to change to tell python-mode or compile-mode to respect the project root? Also, assume I have lots of projects in
~/ so I can't hard-code a path here in my
.emacs.d/init.el, without potentially clobbering my other projects.
M-x cd? If that works, then something might be done through a hook or an advice or some other Emacs means...