py-load-pymacs sets load path incorrectly

Bug #913289 reported by Richard Everson
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

So far as I can tell py-load-pymacs adds .../pymacs/pymacs.el to the load-path, but should add .../pymacs. Also I suggest that py-install-directory should by expanded with expand-file-name so that users can put things like:

(add-to-list 'load-path "~/el/python-mode/")
(setq py-install-directory "~/el/python-mode/")

in .emacs

Here's a slightly modified function to do these:

(defun py-load-pymacs ()
  "Load Pymacs as delivered with python-mode.el.

Pymacs has been written by François Pinard and many others.
See original source: http://pymacs.progiciels-bpi.ca"
  (interactive)
  (if (or (not (boundp 'py-install-directory)) (not (stringp py-install-directory)))
      (error "`py-install-directory' not set, see INSTALL")
    (load (expand-file-name (concat py-install-directory "/pymacs/pymacs.el")) nil t)
    (add-to-list 'load-path (expand-file-name (concat py-install-directory "/pymacs/")))
    (setenv "PYMACS_PYTHON" "python2.7")
    (autoload 'pymacs-apply "pymacs")
    (autoload 'pymacs-call "pymacs")
    (autoload 'pymacs-eval "pymacs")
    (autoload 'pymacs-exec "pymacs")
    (autoload 'pymacs-load "pymacs")
    (require 'pymacs)))

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.0.5
importance: Undecided → Medium
Changed in python-mode:
status: New → Fix Committed
Revision history for this message
Richard Everson (r-m-everson) wrote : Re: [Bug 913289] py-load-pymacs sets load path incorrectly
Download full text (9.3 KiB)

Hi Andreas,

A bit more on this. I think that some extra expand-file-name calls are needed -- see diff below.

Also, if the user (like me) chooses IPython as the default interpreter by customizing py-shell, then pymacs tries to start IPython rather than python or jython is its inferior process. This is done by setting the PYMACS_PYTHON environment variable with py-choose-shell. For the time being, I've just specified "python" instead of calling py-choose-shell; I never use jython and I pymacs never wants Ipython.

Unfortunately for me, pymacs doesn't start cleanly even when I make sure that python is the inferior shell. In the *Pymacs* buffer I get:

----------------------------------------------------------
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named Pymacs.pymacs

Process pymacs exited abnormally with code 1
-----------------------------------------------------------

This seems to be because the "standard" pymacs is a package, probably located in .../lib/pythonX.Y/site-packages, but with the automatic loading from python-mode.el it's not in a package and the py-install-directory is not in sys.path. I'm not sure of the best way to tell the inferior Python where to find pymacs -- one possibility would be to mess with PYTHONPATH, but that might be messy if the user has also set it; another might be to add py-install-directory directly to sys.path in pymacs.el. Hardcoding my .../python-mode/pymacs directory (it has to be the full path) and changing Pymacs to pymacs in a couple of places (see patch) helps, but it looks as if pymacs.py still differs from Pymacs enough to break it. Here's what happens in *Pymacs* with the patched code:

-------------------------------------------------------------
['', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.21-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/src/scipy', '/System/Library/Frameworks/Python.framework/Versions/src/matplotlib/lib', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages', '/Users/reverson/Emacs/el/python-mode/pymacs']
Traceback (most recent call las...

Read more...

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.