Problem with py-separator-char under Windows

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

Bug Description

Usiong r922, py-separator-char returns the following on my Windows machine:

"/usr/bin/bash: -c: line 0: syntax error near unexpected token `os.sep'/usr/bin/bash: -c: line 0: `c:/python27/Scripts/ipython.bat -W ignore -c \\import os; print(os.sep)\\'"

On my Mac, it returns "/", which seems more reasonable.

NOTE: On a Windows machine I *strongly* recommend just hard-coding (or at least letting the user hard-code) the directory separator. Even if we could get the current code to work under Windows, it would return "\", and this would still lead to problems because Emacs under Windows likes to use the default Unix "/" separator, so it makes more sense to tell python-mode to use "/".

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

okay, think we may come along with two variables

- hard-coded-separator-char (string)
- use-hard-coded-separator-char-p (boolean)

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

new customizable py-separator-char should do it

please flag "new" if not done

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

When I try to customize this variable, it only gives me the choice of on vs. off, rather than allowing me to select a particular character. Is that correct?

Changed in python-mode:
status: Fix Committed → New
Revision history for this message
Andreas Roehler (a-roehler) wrote :

no, should be of type string. fixed. thx

Changed in python-mode:
status: New → Fix Committed
Revision history for this message
Richard Stanton (a-stanton) wrote : RE: [Bug 975539] Re: Problem with py-separator-char under Windows
Download full text (16.3 KiB)

I set py-separator-char to "/", and now when I open a python script I get the following error

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  replace-regexp-in-string("\n" "" nil)
  (let (erg) (cond ((not (string= "" py-separator-char)) py-separator-char) ((and (string-match "[Ii][Pp]ython" py-shell-name) (string-match "epd\\|EPD" py-shell-name)) (setq erg (shell-command-to-string (concat py-shell-name " -c \"import os; print(os.sep)\""))) (setq erg (replace-regexp-in-string "\n" "" erg)) (when (string-match "^$" erg) (setq erg (substring erg (string-match "^$" erg))))) (t (setq erg (shell-command-to-string (concat py-shell-name " -W ignore" " -c \"import os; print(os.sep)\""))))) (replace-regexp-in-string "\n" "" erg))
  (py-separator-char)
  (or sepchar (py-separator-char))
  (let* ((sepchar (or sepchar (py-separator-char))) (thisname (if name (if (string-match sepchar name) (substring name (progn (string-match ... name) (match-beginning 2))) name) (substring py-shell-name (or (string-match (concat sepchar ".+$") py-shell-name) 0)))) (nname (cond (dedicated (make-temp-name (concat thisname "-"))) (t thisname))) (erg (cond ((or (string-match "ipython" nname) (string-match "IPython" nname)) "IPython") (nname)))) (unless (or nostars (string-match "^*" erg)) (setq erg (concat "*" erg "*"))) erg)
  py-process-name()
  (get-process (py-process-name))
  (if (get-process (py-process-name)) nil (let ((oldbuf (current-buffer))) (save-excursion (py-shell) (set-buffer oldbuf))))
  (unless (get-process (py-process-name)) (let ((oldbuf (current-buffer))) (save-excursion (py-shell) (set-buffer oldbuf))))
  (progn (window-configuration-to-register 213465879) (unless (get-process (py-process-name)) (let ((oldbuf (current-buffer))) (save-excursion (py-shell) (set-buffer oldbuf)))) (jump-to-register 213465879))
  (if py-start-run-py-shell (progn (window-configuration-to-register 213465879) (unless (get-process (py-process-name)) (let ((oldbuf (current-buffer))) (save-excursion (py-shell) (set-buffer oldbuf)))) (jump-to-register 213465879)))
  (when py-start-run-py-shell (window-configuration-to-register 213465879) (unless (get-process (py-process-name)) (let ((oldbuf (current-buffer))) (save-excursion (py-shell) (set-buffer oldbuf)))) (jump-to-register 213465879))
  (let ((delay-mode-hooks t)) (kill-all-local-variables) (setq major-mode (quote python-mode)) (setq mode-name "Python") nil (use-local-map python-mode-map) (set-syntax-table python-mode-syntax-table) (setq local-abbrev-table python-mode-abbrev-table) (set (make-local-variable (quote font-lock-defaults)) (quote (python-font-lock-keywords nil nil nil nil (font-lock-syntactic-keywords . python-font-lock-syntactic-keywords)))) (set (make-local-variable (quote parse-sexp-lookup-properties)) t) (set (make-local-variable (quote parse-sexp-ignore-comments)) t) (set (make-local-variable (quote comment-start)) "# ") (set (make-local-variable (quote comment-start-skip)) "^[ ]*#+ *") (set (make-local-variable (quote comment-column)) 40) (set (make-local-variable (quote comment-indent-function)) (function py-comment-indent-function)) (set (make-local-variable (quote inden...

Changed in python-mode:
status: Fix Committed → New
Revision history for this message
Andreas Roehler (a-roehler) wrote :

made some related changes, please try again

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

R927 worked as long as I set py-separator-char to 47.

R928 doesn't work with either 47 or "/". I suspect this may be because with the new sepchar code in r928, sepchar ends up being set to "\"/\"".

With py-separator-char set to 47, here's what I get when I press C-c C-c to run my script under r928:

Debugger entered--Lisp error: (error "No buffer named *IPython*")
  set-buffer("*IPython*")
  (cond ((unless (eq switch (quote noswitch)) (and py-split-windows-on-execute-p (or (eq switch (quote switch)) py-shell-switch-buffers-on-execute-p))) (unless (string-match "[Ii][Pp]ython" py-buffer-name) (delete-other-windows)) (when (window-full-height-p) (funcall py-split-windows-on-execute-function)) (pop-to-buffer py-buffer-name)) ((and py-split-windows-on-execute-p (or (eq switch (quote noswitch)) (not (eq switch (quote switch))))) (when (window-full-height-p) (funcall py-split-windows-on-execute-function)) (set-buffer py-buffer-name) (switch-to-buffer (current-buffer)) (other-window 1)) ((or (eq switch (quote switch)) (and (not (eq switch (quote noswitch))) py-shell-switch-buffers-on-execute-p)) (pop-to-buffer py-buffer-name) (goto-char (point-max))) ((or (eq switch (quote noswitch)) (not py-shell-switch-buffers-on-execute-p)) (set-buffer oldbuf) (switch-to-buffer (current-buffer))))
  py-shell-manage-windows(nil t nil #<buffer run.py> "*IPython*")
  (progn (when (string-match "ipython" (process-name proc)) (sit-for py-ipython-execute-delay)) (setq erg (py-execute-file-base proc file pec)) (setq py-exception-buffer (cons file (current-buffer))) (py-shell-manage-windows switch py-split-windows-on-execute-p py-shell-switch-buffers-on-execute-p oldbuf procbuf) (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)
  (if (file-readable-p file) (progn (when (string-match "ipython" (process-name proc)) (sit-for py-ipython-execute-delay)) (setq erg (py-execute-file-base proc file pec)) (setq py-exception-buffer (cons file (current-buffer))) (py-shell-manage-windows switch py-split-windows-on-execute-p py-shell-switch-buffers-on-execute-p oldbuf procbuf) (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?"))
  (let* ((oldbuf (current-buffer)) (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 (if sepchar (regexp-quote sepchar) (py-separator-char))) (name (py-buffer-name-prepare shell sepchar)) (temp (make-temp-name shell)) (file (concat (expand-file-name temp py-temp-directory) ".py")) (filebuf (get-buffer-create file)) (proc (if dedicated (get-buffer-process (py-shell nil dedicated (or shell (downcase shell)) sw...

Read more...

Changed in python-mode:
status: Fix Committed → New
Changed in python-mode:
status: New → In Progress
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 09.04.2012 05:57, schrieb Richard Stanton:
> R927 worked as long as I set py-separator-char to 47.
>
> R928 doesn't work with either 47 or "/". I suspect this may be because
> with the new sepchar code in r928, sepchar ends up being set to "\"/\"".
>

Hi Richard,

thanks a lot. Being determined to cure the source of bugs rather than implementing a workaround, please stay patient with me :)

As for the latest report, could reproduce it, but it's quite simple: executing functions need a running shell, otherwise it fails first time.

Therefor I have `py-start-run-py-shell' to non-nil.

As with several possible shells, will see to introduce something to repeat the call - which always should do it.

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

> As for the latest report, could reproduce it, but it's quite simple:
> executing functions need a running shell, otherwise it fails first time.
>
> Therefor I have `py-start-run-py-shell' to non-nil.

It fails on my system regardless of the setting of py-start-run-py-shell (or of whether I have set py-separator-char). Things are OK if I use the default python shell (e.g., "ipython"), but I cannot run anything at all without an error if I have py-shell-name set to "/Library/Frameworks/EPD64.framework/Versions/7.2/bin/ipython".

For me, and probably anyone else who's set py-shell-name to anything including a directory separator, this makes this quite a major problem right now...

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

Am 09.04.2012 18:45, schrieb Richard Stanton:
>> As for the latest report, could reproduce it, but it's quite simple:
>> executing functions need a running shell, otherwise it fails first time.
>>
>> Therefor I have `py-start-run-py-shell' to non-nil.
>
> It fails on my system regardless of the setting of py-start-run-py-shell
> (or of whether I have set py-separator-char). Things are OK if I use the
> default python shell (e.g., "ipython"), but I cannot run anything at all
> without an error if I have py-shell-name set to
> "/Library/Frameworks/EPD64.framework/Versions/7.2/bin/ipython".
>
> For me, and probably anyone else who's set py-shell-name to anything
> including a directory separator, this makes this quite a major problem
> right now...
>

just seeing another bug which puts separator-char into shell buffer-name
maybe that's it

should have access to a Windows machine tomorrow

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

I don't think this is a Windows-specific problem. It fails on my Mac too.

> -----Original Message-----
> From: <email address hidden> [mailto:<email address hidden>] On Behalf
> Of Andreas Roehler
> Sent: Monday, April 09, 2012 10:44 AM
> To: Richard Stanton
> Subject: Re: [Bug 975539] Re: Problem with py-separator-char under
> Windows
>
> Am 09.04.2012 18:45, schrieb Richard Stanton:
> >> As for the latest report, could reproduce it, but it's quite simple:
> >> executing functions need a running shell, otherwise it fails first time.
> >>
> >> Therefor I have `py-start-run-py-shell' to non-nil.
> >
> > It fails on my system regardless of the setting of
> > py-start-run-py-shell (or of whether I have set py-separator-char).
> > Things are OK if I use the default python shell (e.g., "ipython"), but
> > I cannot run anything at all without an error if I have py-shell-name
> > set to
> "/Library/Frameworks/EPD64.framework/Versions/7.2/bin/ipython".
> >
> > For me, and probably anyone else who's set py-shell-name to anything
> > including a directory separator, this makes this quite a major problem
> > right now...
> >
>
> just seeing another bug which puts separator-char into shell buffer-name
> maybe that's it
>
> should have access to a Windows machine tomorrow
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/975539
>
> Title:
> Problem with py-separator-char under Windows
>
> Status in An Emacs mode for editing Python code:
> In Progress
>
> Bug description:
> Usiong r922, py-separator-char returns the following on my Windows
> machine:
>
> "/usr/bin/bash: -c: line 0: syntax error near unexpected token
> `os.sep'/usr/bin/bash: -c: line 0: `c:/python27/Scripts/ipython.bat -W
> ignore -c \\import os; print(os.sep)\\'"
>
> On my Mac, it returns "/", which seems more reasonable.
>
> NOTE: On a Windows machine I *strongly* recommend just hard-coding (or
> at least letting the user hard-code) the directory separator. Even if
> we could get the current code to work under Windows, it would return
> "\", and this would still lead to problems because Emacs under Windows
> likes to use the default Unix "/" separator, so it makes more sense to
> tell python-mode to use "/".
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/python-mode/+bug/975539/+subscriptions

Changed in python-mode:
importance: Medium → High
Revision history for this message
Richard Stanton (a-stanton) wrote :
Download full text (10.7 KiB)

Current status update under r930:

1) The variable py-separator-char is set by default (line 374) to the
backslash character, \. The default setting should probably either be
blank or a forward slash, /, since the backslash is wrong under Unix and
even causes trouble under Windows.

2) If I set py-separator-char to nil on my Mac and then call the function
py-separator-char, I get the following output (with py-shell-name set to
"ipython"):

(py-separator-char)
"[TerminalIPythonApp] Bad config encountered during
initialization:[TerminalIPythonApp] Unrecognized flag: '-W'=========
IPython=========Tools for Interactive Computing in
Python========================================= A Python shell with
automatic history (input and output), dynamic object introspection,
easier configuration, command completion, access to the system shell
and more. IPython can also be embedded in running programs.Usage
ipython [subcommand] [options] [files] If invoked with no options, it
executes all the files listed in sequence and exits, use -i to enter
interactive mode after running the files. Files ending in .py will be
treated as normal Python, but files ending in .ipy can contain special
IPython syntax (magic commands, shell expansions, etc.) Almost all
configuration in IPython is available via the command-line. Do `ipython
--help-all` to see all available options. For persistent
configuration, look into your `ipython_config.py` configuration file for
 details. This file is typically installed in the `IPYTHON_DIR`
directory, and there is a separate configuration directory for each
profile. The default profile directory will be located in
$IPYTHON_DIR/profile_default. For Linux users, IPYTHON_DIR defaults to
`$HOME/.config/ipython`, and for other Unix systems to
`$HOME/.ipython`. For Windows users, $HOME resolves to C:\\Documents
and Settings\\YourUserName in most instances. To initialize a profile
with the default configuration file, do:: $> ipython profile create
 and start editing `IPYTHON_DIR/profile_default/ipython_config.py` In
IPython's documentation, we will refer to this directory as
`IPYTHON_DIR`, you can change its default location by creating an
environment variable with this name and setting it to the desired path.
For more information, see the manual available in HTML and PDF in your
installation, or online at
http://ipython.org/documentation.html.Subcommands-----------Subcommands
are launched as `ipython cmd [args]`. For information on usingsubcommand
'cmd', do: `ipython cmd -h`.profile Create and manage IPython
profiles.kernel Start a kernel without an attached frontend.notebook
Launch the IPython HTML Notebook Server.console Launch the IPython
terminal-based Console.qtconsole Launch the IPython Qt
Console.Options-------Arguments that take values are actually convenience
aliases to fullConfigurables, whose aliases are listed on the help line.
For more informationon full configurables, see
'--help-all'.--no-autoindent Turn off autoindenting.--autoedit-syntax
 Turn on auto editing of files with syntax errors.--deep-reload Enable
deep (recursive) reloading by default. IPython c...

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

One further thought - at some point, while you want a single character
separator when *creating* a file name, you might want to allow for a regex
when *searching* for a directory separator (both c:\temp and c:/temp are
valid ways of referring to the same file under Windows, at least under
Emacs).

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

Done?

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

The new default setting of 47 works fine, but the actual code inside the
function py-separator-char still doesn't work. If I set py-separator-char
to "" then run the function py-separator-char on my Mac, I get the output
shown below. Personally, rather than fix the code, I'd just delete the
entire function and insist that the variable be customized properly.

(py-separator-char)

"[TerminalIPythonApp] Bad config encountered during
initialization:[TerminalIPythonApp] Unrecognized flag: '-W'=========
IPython=========Tools for Interactive Computing in
Python========================================= A Python shell with
automatic history (input and output), dynamic object introspection,
easier configuration, command completion, access to the system shell
and more. IPython can also be embedded in running programs.Usage
ipython [subcommand] [options] [files] If invoked with no options, it
executes all the files listed in sequence and exits, use -i to enter
interactive mode after running the files. Files ending in .py will be
treated as normal Python, but files ending in .ipy can contain special
IPython syntax (magic commands, shell expansions, etc.) Almost all
configuration in IPython is available via the command-line. Do `ipython
--help-all` to see all available options. For persistent
configuration, look into your `ipython_config.py` configuration file for
 details. This file is typically installed in the `IPYTHON_DIR`
directory, and there is a separate configuration directory for each
profile. The default profile directory will be located in
$IPYTHON_DIR/profile_default. For Linux users, IPYTHON_DIR defaults to
`$HOME/.config/ipython`, and for other Unix systems to
`$HOME/.ipython`. For Windows users, $HOME resolves to C:\\Documents
and Settings\\YourUserName in most instances. To initialize a profile
with the default configuration file, do:: $> ipython profile create
 and start editing `IPYTHON_DIR/profile_default/ipython_config.py` In
IPython's documentation, we will refer to this directory as
`IPYTHON_DIR`, you can change its default location by creating an
environment variable with this name and setting it to the desired path.
For more information, see the manual available in HTML and PDF in your
installation, or online at
http://ipython.org/documentation.html.Subcommands-----------Subcommands
are launched as `ipython cmd [args]`. For information on usingsubcommand
'cmd', do: `ipython cmd -h`.profile Create and manage IPython
profiles.kernel Start a kernel without an attached frontend.notebook
Launch the IPython HTML Notebook Server.console Launch the IPython
terminal-based Console.qtconsole Launch the IPython Qt
Console.Options-------Arguments that take values are actually convenience
aliases to fullConfigurables, whose aliases are listed on the help line.
For more informationon full configurables, see
'--help-all'.--no-autoindent Turn off autoindenting.--autoedit-syntax
 Turn on auto editing of files with syntax errors.--deep-reload Enable
deep (recursive) reloading by default. IPython can use the deep_reload
module which reloads changes in modules recursively (it...

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

Remote bug watches

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