@@ -293,18 +293,41 @@ it at one time."
293293
294294(defvar lispy--python-init-file nil )
295295
296+ (defun lispy--python-poetry-name ()
297+ (let ((pyproject (expand-file-name " pyproject.toml" (counsel-locate-git-root))))
298+ (and (file-exists-p pyproject)
299+ (with-current-buffer (find-file-noselect pyproject)
300+ (goto-char (point-min ))
301+ (when (re-search-forward " \\ [tool.poetry\\ ]\n name *= *\" \\ ([^\" ]+\\ )\" " nil t )
302+ (match-string-no-properties 1 ))))))
303+
304+ (defun lispy--python-proc-name ()
305+ (or (and (process-live-p (get-buffer-process lispy-python-buf))
306+ (process-name (get-buffer-process lispy-python-buf)))
307+ (let ((name
308+ (or (lispy--python-poetry-name)
309+ (if (string-match " \\ (?::python \\ |python_\\ )\\ (.*\\ )\\ '" python-shell-interpreter-args)
310+ (match-string 1 python-shell-interpreter-args)
311+ " default" ))))
312+ (concat " lispy-python-" name))))
313+
296314(defun lispy--python-proc (&optional name )
297315 (let* ((proc-name (or name
298- (and (process-live-p (get-buffer-process lispy-python-buf))
299- (process-name (get-buffer-process lispy-python-buf)))
300- (if (string-match " \\ (?::python \\ |python_\\ )\\ (.*\\ )\\ '" python-shell-interpreter-args)
301- (concat " lispy-python-" (match-string 1 python-shell-interpreter-args))
302- " lispy-python-default" )))
316+ (lispy--python-proc-name)))
303317 (process (get-process proc-name)))
304318 (if (process-live-p process)
305319 process
306320 (let* ((python-shell-font-lock-enable nil )
307321 (inferior-python-mode-hook nil )
322+ (poetry-name (lispy--python-poetry-name))
323+ (python-shell-interpreter
324+ (if poetry-name
325+ " poetry"
326+ python-shell-interpreter))
327+ (python-shell-interpreter-args
328+ (if poetry-name
329+ " run python"
330+ python-shell-interpreter-args))
308331 ; ; (python-shell-interpreter
309332 ; ; (cond
310333 ; ; ((and (file-exists-p python-shell-interpreter)
0 commit comments