jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 262 forks source link

Function elpy-library-root does not support Python namespace packages #375

Open amzz opened 10 years ago

amzz commented 10 years ago

Hi

I'm using nosetests to test python code with the convenient C-x C-t test command. However it seems that the package root is not found correctly when working with namespace packages. Currently the package root is found on the same path as the current buffer path. That affects where the nosetests start to look for test cases.

Below is temporal fix that I made.

The temp fix requires setup.py or setup.cfg in the root of packages

Below is the small change done to the elpy.el code

(defun elpy-library-root ()
  "Return the root of the Python package chain of the current buffer.

That is, if you have /foo/package/module.py, it will return /foo,
so that import package.module will pick up module.py."
  (elpy-project-find-python-root))
  ;; (locate-dominating-file default-directory
  ;;                         (λ (dir)
  ;;                           (not (file-exists-p
  ;;                                 (format "%s/__init__.py"
  ;;                                         dir))))))
jorgenschaefer commented 10 years ago

Thank you for the report. Supporting namespace packages correctly is tricky, I'll take a look for 1.7.

TauPan commented 8 years ago

This (obviously) also applies to python3 namespace packages, which might be even harder to support. :-(