path wrong expanded

Bug #955338 reported by Andreas Roehler
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
High
Andreas Roehler

Bug Description

Am 14.03.2012 18:52, schrieb Richard Stanton:
> My Mac really doesn’t like this!
>
> I pressed C-c ! to open a new python shell, then C-c C-c to run the
> script, resulting in the following error message:
>
> Debugger entered--Lisp error: (file-error "Opening output file" "No such file or directory" "/var/folders/zf/bgjm4tvs3wv_6q7_6z3b2nx00000gn/T/*/Library/Frameworks/EPD64.framework/Versions/7.2/bin/IPython*55019M_B.py")
> write-region(1 5270 "/var/folders/zf/bgjm4tvs3wv_6q7_6z3b2nx00000gn/T/*/Library/Frameworks/EPD64.framework/Versions/7.2/bin/IPython*55019M_B.py" nil t nil ask)
> (let* ((pop-up-windows py-shell-switch-buffers-on-execute-p) (shell (or shell (py-choose-shell))) (regbuf (current-buffer)) (py-execute-directory (or (ignore-errors (file-name-directory (buffer-file-name))) (getenv "WORKON_HOME") (getenv "HOME"))) (strg (buffer-substring-no-properties start end)) (sepchar (or sepchar (py-separator-char))) (name (py-shell-name-prepare shell sepchar)) (temp (make-temp-name name)) (file (concat (expand-file-name temp py-temp-directory) ".py")) (filebuf (get-buffer-create file)) (proc (or (get-process name) (get-process (py-shell nil dedicated (or shell (downcase shell)) switch sepchar)))) (procbuf (if dedicated (buffer-name (get-buffer (current-buffer))) (buffer-name (get-buffer (py-process-name name dedicated nostars sepchar))))) (pec (if (string-match "Python *3" name) (format "exec(compile(open('%s').read(), '%s', 'exec')) # PYTHON-MODE\n" file file) (format "execfile(r'%s') # PYTHON-MODE\n" file))) (wholebuf (when (boundp (quote wholebuf)) wholebuf)) (comint-scroll-to-bottom-on-output t) erg) (set-buffer filebuf) (erase-buffer) (insert strg) (unless wholebuf (py-fix-start (point-min) (point-max)) (py-if-needed-insert-shell name) (py-insert-coding) (py-insert-execute-directory)) (set-buffer filebuf) (write-region (point-min) (point-max) file nil t nil (quote ask)) (set-buffer-modified-p (quote nil)) (kill-buffer filebuf) (if (file-readable-p file) (progn (when (string-match "IPython" (process-name proc)) (unless (get-process "*IPython*") (sit-for py-ipython-execute-delay))) (setq erg (py-execute-file-base proc file pec)) (setq py-exception-buffer (cons file (current-buffer))) (cond ((eq switch (quote switch)) (if py-split-windows-on-execute-p (progn (delete-other-windows) (funcall py-split-windows-on-execute-function)) (set-buffer regbuf)) (set-buffer procbuf) (switch-to-buffer (current-buffer)) (goto-char (point-max))) ((eq switch (quote noswitch)) (when py-split-windows-on-execute-p (delete-other-windows) (funcall py-split-windows-on-execute-function)) (set-buffer regbuf) (switch-to-buffer (current-buffer))) ((and py-shell-switch-buffers-on-execute-p py-split-windows-on-execute-p) (funcall py-split-windows-on-execute-function) (switch-to-buffer (current-buffer)) (switch-to-buffer regbuf) (pop-to-buffer procbuf)) (py-split-windows-on-execute-p (delete-other-windows) (pop-to-buffer procbuf) (set-buffer procbuf) (funcall py-split-windows-on-execute-function) (switch-to-buffer regbuf)) (py-shell-switch-buffers-on-execute-p (set-buffer procbuf) (switch-to-buffer (current-buffer)))) (unless (string= (buffer-name (current-buffer)) procbuf) (when py-verbose-p (message "Output buffer: %s" procbuf))) (sit-for 0.1) (unless py-execute-keep-temporary-file-p (delete-file file) (when (buffer-live-p file) (kill-buffer file))) erg) (message "%s not readable. %s" file "Do you have write permissions?")))
> py-execute-base(1 5270 nil nil nil)
> (let ((shell (cond ((eq 4 (prefix-numeric-value shell)) (default-value (quote py-shell-name))) ((and (numberp shell) (not (eq 1 ...))) (read-from-minibuffer "(path-to-)shell-name: " (default-value (quote py-shell-name)))) (t shell)))) (py-execute-base start end shell dedicated switch))
> py-execute-region(1 5270 nil nil nil)
> (let ((wholebuf t) (py-master-file (or py-master-file (py-fetch-py-master-file))) beg end) (when py-master-file (let* ((filename (expand-file-name py-master-file)) (buffer (or (get-file-buffer filename) (find-file-noselect filename)))) (set-buffer buffer))) (setq beg (point-min)) (setq end (point-max)) (py-execute-region beg end shell dedicated switch))
> (save-excursion (let ((wholebuf t) (py-master-file (or py-master-file (py-fetch-py-master-file))) beg end) (when py-master-file (let* ((filename (expand-file-name py-master-file)) (buffer (or (get-file-buffer filename) (find-file-noselect filename)))) (set-buffer buffer))) (setq beg (point-min)) (setq end (point-max)) (py-execute-region beg end shell dedicated switch)))
> py-execute-buffer(nil)
> call-interactively(py-execute-buffer nil nil)
>

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.0.6
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
Andreas Roehler (a-roehler) wrote :

please re-open, if the very same bug still exists.

Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
Richard Stanton (a-stanton) wrote :
Download full text (4.3 KiB)

I just tried on my Windows machine, and got the following error:

Debugger entered--Lisp error: (file-error "Opening output file" "invalid argument" "c:/Users/stanton/AppData/Local/Temp/*c:/python27/Scripts/IPython.bat*7800HUF.py")
  write-region(1 5270 "c:/Users/stanton/AppData/Local/Temp/*c:/python27/Scripts/IPython.bat*7800HUF.py" nil t nil ask)
  (let* ((pop-up-windows py-shell-switch-buffers-on-execute-p) (shell (or shell (py-choose-shell))) (regbuf (current-buffer)) (py-execute-directory (or (ignore-errors (file-name-directory (buffer-file-name))) (getenv "WORKON_HOME") (getenv "HOME"))) (strg (buffer-substring-no-properties start end)) (sepchar (or sepchar (py-separator-char))) (name (py-shell-name-prepare shell sepchar)) (temp (make-temp-name name)) (file (concat (expand-file-name temp py-temp-directory) ".py")) (filebuf (get-buffer-create file)) (proc (or (get-process name) (get-process (py-shell nil dedicated (or shell (downcase shell)) switch sepchar)))) (procbuf (if dedicated (buffer-name (get-buffer (current-buffer))) (buffer-name (get-buffer (py-process-name name dedicated nostars sepchar))))) (pec (if (string-match "Python *3" name) (format "exec(compile(open('%s').read(), '%s', 'exec')) # PYTHON-MODE\n" file file) (format "execfile(r'%s') # PYTHON-MODE\n" file))) (wholebuf (when (boundp (quote wholebuf)) wholebuf)) (comint-scroll-to-bottom-on-output t) erg) (set-buffer filebuf) (erase-buffer) (insert strg) (unless wholebuf (py-fix-start (point-min) (point-max)) (py-if-needed-insert-shell name) (py-insert-coding) (py-insert-execute-directory)) (set-buffer filebuf) (write-region (point-min) (point-max) file nil t nil (quote ask)) (set-buffer-modified-p (quote nil)) (kill-buffer filebuf) (if (file-readable-p file) (progn (when (string-match "IPython" (process-name proc)) (unless (get-process "*IPython*") (sit-for py-ipython-execute-delay))) (setq erg (py-execute-file-base proc file pec)) (setq py-exception-buffer (cons file (current-buffer))) (cond ((eq switch (quote switch)) (if py-split-windows-on-execute-p (progn (delete-other-windows) (funcall py-split-windows-on-execute-function)) (set-buffer regbuf)) (set-buffer procbuf) (switch-to-buffer (current-buffer)) (goto-char (point-max))) ((eq switch (quote noswitch)) (when py-split-windows-on-execute-p (delete-other-windows) (funcall py-split-windows-on-execute-function)) (set-buffer regbuf) (switch-to-buffer (current-buffer))) ((and py-shell-switch-buffers-on-execute-p py-split-windows-on-execute-p) (funcall py-split-windows-on-execute-function) (switch-to-buffer (current-buffer)) (switch-to-buffer regbuf) (pop-to-buffer procbuf)) (py-split-windows-on-execute-p (delete-other-windows) (pop-to-buffer procbuf) (set-buffer procbuf) (funcall py-split-windows-on-execute-function) (switch-to-buffer regbuf)) (py-shell-switch-buffers-on-execute-p (set-buffer procbuf) (switch-to-buffer (current-buffer)))) (unless (string= (buffer-name (current-buffer)) procbuf) (when py-verbose-p (message "Output buffer: %s" procbuf))) (sit-for 0.1) (unless py-execute-keep-temporary-file-p (delete-file file) (when (buffer-live-p file) (kill-buffer file))) erg) (message "%s not readable. %s" file "Do you h...

Read more...

Changed in python-mode:
status: Fix Committed → In Progress
Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 955338] Re: path wrong expanded
Download full text (4.7 KiB)

Am 15.03.2012 05:41, schrieb Richard Stanton:
> I just tried on my Windows machine, and got the following error:
>
>
> Debugger entered--Lisp error: (file-error "Opening output file" "invalid argument" "c:/Users/stanton/AppData/Local/Temp/*c:/python27/Scripts/IPython.bat*7800HUF.py")
> write-region(1 5270 "c:/Users/stanton/AppData/Local/Temp/*c:/python27/Scripts/IPython.bat*7800HUF.py" nil t nil ask)
> (let* ((pop-up-windows py-shell-switch-buffers-on-execute-p) (shell (or shell (py-choose-shell))) (regbuf (current-buffer)) (py-execute-directory (or (ignore-errors (file-name-directory (buffer-file-name))) (getenv "WORKON_HOME") (getenv "HOME"))) (strg (buffer-substring-no-properties start end)) (sepchar (or sepchar (py-separator-char))) (name (py-shell-name-prepare shell sepchar)) (temp (make-temp-name name)) (file (concat (expand-file-name temp py-temp-directory) ".py")) (filebuf (get-buffer-create file)) (proc (or (get-process name) (get-process (py-shell nil dedicated (or shell (downcase shell)) switch sepchar)))) (procbuf (if dedicated (buffer-name (get-buffer (current-buffer))) (buffer-name (get-buffer (py-process-name name dedicated nostars sepchar))))) (pec (if (string-match "Python *3" name) (format "exec(compile(open('%s').read(), '%s', 'exec')) # PYTHON-MODE\n" file file) (format "execfile(r'%s') # PYTHON-MODE\n" file))) (wholebuf (when (boundp (quote wholebu
f)) wholebuf)) (comint-scroll-to-bottom-on-output t) erg) (set-buffer filebuf) (erase-buffer) (insert strg) (unless wholebuf (py-fix-start (point-min) (point-max)) (py-if-needed-insert-shell name) (py-insert-coding) (py-insert-execute-directory)) (set-buffer filebuf) (write-region (point-min) (point-max) file nil t nil (quote ask)) (set-buffer-modified-p (quote nil)) (kill-buffer filebuf) (if (file-readable-p file) (progn (when (string-match "IPython" (process-name proc)) (unless (get-process "*IPython*") (sit-for py-ipython-execute-delay))) (setq erg (py-execute-file-base proc file pec)) (setq py-exception-buffer (cons file (current-buffer))) (cond ((eq switch (quote switch)) (if py-split-windows-on-execute-p (progn (delete-other-windows) (funcall py-split-windows-on-execute-function)) (set-buffer regbuf)) (set-buffer procbuf) (switch-to-buffer (current-buffer)) (goto-char (point-max))) ((eq switch (quote noswitch)) (when py-split-windows-on-execute-p (delete-other-windows)
(funcall py-split-windows-on-execute-function)) (set-buffer regbuf) (switch-to-buffer (current-buffer))) ((and py-shell-switch-buffers-on-execute-p py-split-windows-on-execute-p) (funcall py-split-windows-on-execute-function) (switch-to-buffer (current-buffer)) (switch-to-buffer regbuf) (pop-to-buffer procbuf)) (py-split-windows-on-execute-p (delete-other-windows) (pop-to-buffer procbuf) (set-buffer procbuf) (funcall py-split-windows-on-execute-function) (switch-to-buffer regbuf)) (py-shell-switch-buffers-on-execute-p (set-buffer procbuf) (switch-to-buffer (current-buffer)))) (unless (string= (buffer-name (current-buffer)) procbuf) (when py-verbose-p (message "Output buffer: %s" procbuf))) (sit-for 0.1) (unless py-execute-keep-temporary-file-p (delete-file file) (when (buffer-live-p file) (kill-buffe...

Read more...

Revision history for this message
Richard Stanton (a-stanton) wrote :

> > I just tried on my Windows machine, and got the following error:
> >
> >
> > Debugger entered--Lisp error: (file-error "Opening output file" "invalid
> argument"
> "c:/Users/stanton/AppData/Local/Temp/*c:/python27/Scripts/IPython.bat*
> 7800HUF.py")

 [...]

> hmm, need some more info for this
>
> what's the value of `py-shell-name'?

py-shell-name is a variable defined in `python-mode.el'.
Its value is "c:/python27/Scripts/ipython.bat"
Original value was "python"

> also some example script triggering the bug would be helpful

I don't think the contents of the script matters much. This is what I've been using - it's quite simple...:

-------
Print "Hi, Richard"
-------

I suspect it may have something to do with the file name python-mode has created. The characters ":" and "*" are, I'm pretty sure, illegal in Windows file names, and I'm not sure what Windows is going to do with the "/" characters after the temp file name. Maybe try replacing all of these characters with legal characters, such as "_".

Revision history for this message
Richard Stanton (a-stanton) wrote :

Follow-up to my comment above: It would be nice to have the Buffer name not necessarily equal to the lengthy full path of the python executable, plus I think this would solve the current problem. How about another variable for buffer name?

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 15.03.2012 18:42, schrieb Richard Stanton:
> Follow-up to my comment above: It would be nice to have the Buffer name
> not necessarily equal to the lengthy full path of the python executable,

what the error displays is bug when making a temporary file

> plus I think this would solve the current problem. How about another
> variable for buffer name?
>

I'm on it

Revision history for this message
Richard Stanton (a-stanton) wrote :

On 3/15/12 11:16 AM, "Andreas Roehler" <email address hidden> wrote:

>Am 15.03.2012 18:42, schrieb Richard Stanton:
>> Follow-up to my comment above: It would be nice to have the Buffer name
>> not necessarily equal to the lengthy full path of the python executable,
>
>what the error displays is bug when making a temporary file

Yes, the link is indirect, but it looks like you use the buffer name to
construct the temp file name, which can lead to problems if the buffer
name contains either illegal characters for a file name or directory
separators.

Revision history for this message
Richard Stanton (a-stanton) wrote :

A request: could we make this bug high, rather than medium, priority? It makes rather fundamental commands like py-execute-buffer completely unusable. Thanks!

Revision history for this message
Andreas Roehler (a-roehler) wrote :

you could give it another try, thanks

Changed in python-mode:
importance: Medium → High
Changed in python-mode:
status: In Progress → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.