OK this should get you started
(defvar my-python-shell-dir-setup-code
"import os
home = os.path.expanduser('~')
while os.path.isfile('__init__.py') and (os.getcwd() != home):
os.chdir('..')
del os")
(defun my-python-shell-dir-setup ()
(let ((process (get-buffer-process (current-buffer))))
(python-shell-send-string my-python-shell-dir-setup-code process)
(message "Setup project path")))
(add-hook 'inferior-python-mode-hook 'my-python-shell-dir-setup)
Here is what we are doing my-python-shell-dir-setup-code
is simple python code to find project-dir
and set it (it quick and dirty you may want to modify it according to your needs). Then we add a inferior-python-mode-hook
(i.e. my-shell-dir-setup
) to execute the python code in out inferior shell whenever the shell is created.