2

(I now submitted this as an issue in GitHub: https://github.com/jorgenschaefer/elpy/issues/1249)

I'm using Emacs 25.3.1, Elpy v20171212.850, and Python 3.6.3 on MacOS 10.13.2 .

I have a project tracked with Git in ~/MyProject, with the usual git data in ~/MyProject/.git and ~/MyProject/.gitignore. I have some Python modules in ~/MyProject/Python. If, for example, I open one of these modules and, from that buffer, call elpy-shell-switch-to-shell, or elpy-shell-send-region-or-buffer, then Elpy starts a new Python process in ~/MyProject instead of ~/MyProject/Python. This odd behaviour has only started occurring recently (might be since the last Elpy upgrade, but not sure - I upgrade fairly frequently).

Interestingly, if I delete the Git data and kill/reopen the Python module (simply killing the Python REPL buffer is insufficient), then Elpy behaves properly, starting the Python process in ~/MyProject/Python.

Any idea how I can debug this?

jerome
  • 183
  • 6

2 Answers2

2

Answered at github:

You can set elpy-shell-use-project-root to nil to start the shell in the directory of the Python file as before. Alternatively, modify your MyProject/Python directory so that it is detected as a project root; see elpy-project-root-finder-functions.

The elpy-project-root-finder-functions have the options:

  • Projectile project root
  • Python project (setup.py, setup.cfg)
  • Git repository root (.git)
  • Mercurial project root (.hg)
  • Subversion project root (.svn)
serv-inc
  • 816
  • 6
  • 26
1

(I'm posting a slightly modified version of the comment I left on the GitHub issue Elpy starts Python processes at the root of my git tree, not the module's directory.)

The solution described in another answer here

(setq elpy-shell-use-project-root nil)

isn't working for me with elpy 1.34. It used to work, but no longer does.

I checked, and the following text appears in customize, in the elpy-shell-use-project-root section.

elpy-shell-use-project-root is a variable defined in ‘elpy-shell.el’. Its value is nil Original value was t

This variable is obsolete since 1.32.0; use ‘elpy-shell-starting-directory’ instead.

But elpy-shell-use-project-root still appears in customize. If it's obsolete (and apparently not working, in any case), it should just be removed.

Anyway, I set elpy-shell-starting-directory via customize, and the correct syntax, per customize, is

(setq elpy-shell-starting-directory (quote current-directory))

which works.

Faheem Mitha
  • 406
  • 4
  • 16