1

I'm working on a project that uses whoosh. I wish to leave the source tree of whoosh in-place and be able to import from higher levels.

The location of the actual whoosh module is:

project\libs\whoosh\src\whoosh

I wish to import as:

import libs.whoosh
import libs.whoosh.index
etc.

It is simple enough to convert each subdirectory into a python module by placing a __init__.py file that imports the next subdirectory.

The issue, however, is that whoosh's __init__.py does not expose any of its submodules. Therefore import libs.whoosh.index only works when whoosh is in the system path; this is a constraint, I do not wish to manipulate the system path nor install whoosh into site-packages.

Ordinarily (when whoosh is on the system path), it seems whoosh's internal imports are named fully; ie, from project\libs\whoosh\src\whoosh\index.py:

from whoosh import __version__
from whoosh.legacy import toc_loaders
from whoosh.compat import pickle, string_type
from whoosh.fields import ensure_schema

legacy, compat and fields are all siblings to index. Importing whoosh through a chain of whoosh\src\whoosh breaks its import scheme.

How do I go about this without:

  • installing whoosh
  • manipulating the system path
Community
  • 1
  • 1
dilbert
  • 3,008
  • 1
  • 25
  • 34
  • if you don't want to "manipulate the system path nor install whoosh into site-packages", then use virtualenv. Hacking the package system brings more troubles than polluting site-packages – Leonardo.Z Nov 13 '13 at 07:33
  • But I definitely want to "hack the package system". – dilbert Nov 13 '13 at 10:04

1 Answers1

0

You could use add your module path to PYTHONPATH environment variable either persistently or before you run the code.

setenv PYTHONPATH $PYTHONPATH:project\libs\whoosh\src

Or you could do this in your code:

sys.path.append('project\libs\whoosh\src')
scriptmonster
  • 2,741
  • 21
  • 29
  • I'm aware of this, however, this is explicitly want I didn't want to do. – dilbert Nov 13 '13 at 10:01
  • Then you could add `whoosh\src\whoosh` as whoosh in your project, thus you won't need neither installing that module nor manipulating system path. – scriptmonster Nov 13 '13 at 10:38