jorgenschaefer/elpy

Wrong Python shell used when editing two files with the same name in different directories

Closed this issue · 4 comments

Summary

When two Python files with the same name but located into two separate directories of a project are sent to the Python shell, the same shell is used for the two files, even with elpy-shell-toggle-dedicated-shell set to 1.

Steps to reproduce

  1. Open two Python files with the same name (for example test.py) but located into two separate directories (dir1 and dir2). The corresponding buffers are named test.py<dir1> and test.py<dir2>.
  2. Type C-c in each buffers. The Python code is sent to the same Python shell *Python[test]*. One would expect the code to bet sent to two separate shells, *Python[test<dir1>]* and *Python[test<dir2>]*.

My configuration

OS

macOS 12.6

Result of (elpy-config)

Emacs.............: 28.1
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python3 3.10.8 (/usr/local/bin/python3)
RPC virtualenv....: rpc-venv (/Users/smaret/.emacs.d/elpy/rpc-venv)
 Python...........: python3 3.8.2 (/Users/smaret/.emacs.d/elpy/rpc-venv/bin/python3)
 Jedi.............: 0.18.0 (0.18.1 available)
 Autopep8.........: 1.5.7 (1.7.0 available)
 Yapf.............: 0.31.0 (0.32.0 available)
 Black............: 21.7b0 (22.10.0 available)
Syntax checker....: flake8 (/usr/local/bin/flake8)

Elpy configuration in my init.el

(use-package elpy
  :mode ("\\.py\\'" . python-mode)
  :interpreter ("python" . python-mode)
  :init
  (setq-default python-shell-interpreter "python3")
  (setq elpy-shell-use-project-root nil)
  (setq elpy-rpc-python-command "python3")
  (setq elpy-modules (quote
    (elpy-module-company elpy-module-eldoc
    elpy-module-highlight-indentation elpy-module-yasnippet
    elpy-module-autodoc elpy-module-sane-defaults)))
  (elpy-enable))

(add-hook 'elpy-mode-hook (lambda () (elpy-shell-toggle-dedicated-shell 1)))
gopar commented

Note: The code for this only grabs buffer name. Doesn't try to do anything like uniqify does.

Note: The code for this only grabs buffer name. Doesn't try to do anything like uniqify does.

In my example the buffer name is test.py<dir1>, but the the name of the Python buffer is *Python[test]*. So the code doesn't only grab the buffer name, it also removes everything after ..

gopar commented

Ah you are right. Looks like file-name-sans-extension is removing the uniquenes. Should be an easy fix, main thing would be to remove that func and test that nothing else breaks (update/add tests appropriately)

gopar commented

Should be resolved due to PR linked. Please re-open if not the case