Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running any command prepends a long string to every output #1586

Closed
rsuhada opened this issue Apr 22, 2019 · 10 comments
Closed

Running any command prepends a long string to every output #1586

rsuhada opened this issue Apr 22, 2019 · 10 comments

Comments

@rsuhada
Copy link

rsuhada commented Apr 22, 2019

Summary

Running any command prepends a long string to every command output:

import sys, codecs, os, ast, readline;__pyfile = codecs.open('''/tmp/pyw50Zmi''', encoding='''utf-8''');__code = __pyfile.read().encode('''utf-8''');__pyfile.close();os.remove('''/tmp/pyw50Zmi''');__block = ast.parse(__code, '''/home/XXXXXXX.py''', mode='exec'); __block.body = (__block.body if not isinstance(__block.body[0], ast.If) else __block.body if not isinstance(__block.body[0].test, ast.Name) else __block.body if not __block.body[0].test.id == 'True' else __block.body[0].body) if sys.version_info[0] < 3 else (__block.body if not isinstance(__block.body[0], ast.If) else __block.body if not isinstance(__block.body[0].test, ast.NameConstant) else __block.body if not __block.body[0].test.value is True else __block.body[0].body);__last = __block.body[-1];__isexpr = isinstance(_last,ast.Expr); = __block.body.pop() if __isexpr else None;exec(compile(__block, '''/home/rxsXXXX.py''', mode='exec'));eval(compile(ast.Expression(__last.value), '''/home/XXXXXXXX.py''', mode='eval')) if __isexpr else None

(I replaced the paths/filenames with Xs)

Steps to reproduce

Running any command with e.g. elpy-shell-send-statement-and-step

My configuration

OS

Ubuntu 18.04

Result of (elpy-config)

Virtualenv........: None
RPC Python........: 3.7.3 (/home/XXX/anaconda3/bin/python)
Interactive Python: python (/home/XXX/anaconda3/bin/python)
Emacs.............: 26.2
Elpy..............: 1.28.0
Jedi..............: 0.13.3
Rope..............: 0.12.0
Autopep8..........: Not found (1.4.4 available)
Yapf..............: Not found (0.27.0 available)
Black.............: Not found (19.3b0 available)
Syntax checker....: Not found (flake8)

Elpy configuration in my init.el

(use-package elpy
  ;; usel m-x elpy-config to check/debug pathsA
  :ensure t
  :defer t
  :init
  ;; to get rid of the annoying message
  (add-to-list 'warning-suppress-types '(undo discard-info))
  :config
  (elpy-enable)
  (flymake-mode-off)
  (setq elpy-rpc-backend "jedi")
  ;; (setq elpy-rpc-backend "python3")

  (defun elpy-goto-definition-or-rgrep ()
    "Go to the definition of the symbol at point, if found. Otherwise, run `elpy-rgrep-symbol'."
    (interactive)
    (ring-insert find-tag-marker-ring (point-marker))
    (condition-case nil (elpy-goto-definition)
      (error (elpy-rgrep-symbol
              (concat "\\(def\\|class\\)\s" (thing-at-point 'symbol) "(")))))
  (define-key elpy-mode-map (kbd "M-.") 'elpy-goto-definition-or-rgrep)

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;
  ;; ESS-mode like behaviour
  ;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (defun elpy-shell-send-current-statement-and-stay-put ()
    "Send current statement to Python shell."
    (interactive)
    (let ((beg (python-nav-beginning-of-statement))
          (end (python-nav-end-of-statement)))
      (elpy-shell-get-or-create-process)
      (python-shell-send-string (buffer-substring beg end)))
    (elpy-shell-display-buffer)
    )
  (define-key elpy-mode-map (kbd "<S-return>") 'elpy-shell-send-current-statement-and-stay-put)

  (defun python-para-send-and-step ()
    "Sends the current paragraph to the python REPL and goes to the next one"
    (interactive)
    (mark-paragraph)
    (elpy-shell-get-or-create-process)
    (python-shell-send-region (region-beginning) (region-end))
    (elpy-shell-display-buffer)
    (deactivate-mark)
    (forward-paragraph)
    (python-nav-forward-statement)
    )

  (defun send-region-or-para-and-step ()
    (interactive)
    (if (use-region-p)
        (progn
          (elpy-shell-get-or-create-process)
          (python-shell-send-region (region-beginning) (region-end))
          (elpy-shell-display-buffer)
          (goto-char (region-end))
          (deactivate-mark)
          (python-nav-forward-statement)
          )
      (python-para-send-and-step)))

  (define-key elpy-mode-map (kbd "C-c C-c") 'send-region-or-para-and-step)
  (define-key elpy-mode-map (kbd "C-c C-n") 'sk/python-str)
  (define-key elpy-mode-map (kbd "C-c C-v") 'sk/python-help)
  (define-key elpy-mode-map (kbd "C-c C-b") 'elpy-shell-send-region-or-buffer)
  (define-key elpy-mode-map (kbd "M-]") 'ess-separator-major)
  (define-key elpy-mode-map (kbd "M-}") 'ess-separator-minor)
  )
@gopar
Copy link
Collaborator

gopar commented Apr 23, 2019

Can verify this.

@galaunay
Copy link
Collaborator

Yes, I merged a bad commit a while ago (my bad).
It should be fixed in elpy 1.29.1, could you try updating elpy ?

@galaunay
Copy link
Collaborator

galaunay commented Sep 5, 2019

I hope it worked.
Please re-open if not.

@waqarsaleem
Copy link

I have the same problem which I believe is also the cause for this issue: #1550

Environment

  • elpy 1.31.0
  • GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-09-02
  • macOS Catalina 10.15

.emacs

;; ;; Use python3 for python interpreter
;; (setq python-shell-interpreter "python3"
;;       python-shell-interpreter-args "-i")
;; Remove annoying readline warning when python loads
;; https://emacs.stackexchange.com/a/35969/11143
(setq python-shell-completion-native-disabled-interpreters '("python"))
;; https://emacs.stackexchange.com/a/30970/11143
(with-eval-after-load 'python
  (defun python-shell-completion-native-try ()
    "Return non-nil if can trigger native completion."
    (let ((python-shell-completion-native-enable t)
          (python-shell-completion-native-output-timeout
           python-shell-completion-native-try-output-timeout))
      (python-shell-completion-native-get-completions
       (get-buffer-process (current-buffer))
       nil "_"))))

;; Enable ELPY, python IDE
(elpy-enable)
(setq elpy-rpc-backend "jedi")  
;; Use IPython for REPL
(setq python-shell-interpreter "jupyter"
      python-shell-interpreter-args "console --simple-prompt"
      python-shell-prompt-detect-failure-warning nil)
(add-to-list 'python-shell-completion-native-disabled-interpreters
              "jupyter")
;; Enable Flycheck
(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))
;; Enable autopep8
(require 'py-autopep8)
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)

Elpy Configuration

Virtualenv........: None
RPC Python........: 2.7.16 (/usr/bin/python)
Interactive Python: python3 (/Library/Frameworks/Python.framework/Versions/3.8/bin/python3)
Emacs.............: 26.3
Elpy..............: 1.31.0
Jedi..............: 0.15.1
Rope..............: Not found (0.14.0 available)
Autopep8..........: 1.4.4
Yapf..............: Not found (0.28.0 available)
Black.............: Not found (19.3b0 available)
Syntax checker....: flake8 (/Library/Frameworks/Python.framework/Versions/3.8/bin/flake8)

@galaunay
Copy link
Collaborator

Is it better with elpy-shell-echo-output set to nil ?

@waqarsaleem
Copy link

waqarsaleem commented Oct 30, 2019

Thanks, that helps. I can now use python3 and IPython for REPL. The Jupyter REPL receives the buffer contents and does not show any extraneous text but does not seem to evaluate the recipe code and hangs. It then has to be killed with C-c C-k.

@galaunay
Copy link
Collaborator

I merged a PR today (#1712) that may help.
Could you check if it is still happening with the latest version ?

@waqarsaleem
Copy link

waqarsaleem commented Nov 10, 2019

I already have elpy-shell-echo-output set to nil and things were working fine. I updated elpy through the package manager after reading your message. Things still seem to be fine. How do you want me to test?

@galaunay
Copy link
Collaborator

I thought you said it was still not working with the jupyter repl ?

The Jupyter REPL receives the buffer contents and does not show any extraneous text but does not seem to evaluate the recipe code and hangs.

@waqarsaleem
Copy link

Thanks for reminding. I had forgotten about this. I upgraded to 1.32.0 and the problem persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants