Organize Python package to run from its top-level directory?
<p>How do I organize a Python package so its code runs from the top-level directory without adding that directory to the host's Python path?  </p>

<p>I would also like to organize the code so I can run tests from the various test subdirectories, again without adding the package's top-level directory to the python path.</p>

<p>Consider the following code layout:</p>

<pre><code>foobar/
  __init__.py
  README.txt
  its_a_module.py
  one_package/
    __init__.py
    foo.py
    bar.py
    tests/
      __init__.py
       testing_one_package.py
  tests/
    __init__.py
    test_foobar.py
</code></pre>

<ul>
<li>When in foobar/, I should be able to import foobar and all its submodules in the python interpreter</li>
<li>From foobar/, I should be able to run tests/test_foobar.py.</li>
<li>From foobar/tests, I should be able to run test_foobar.py</li>
<li>From one_package/tests, I should be able to run testing_one_package.py.</li>
</ul>

<p>How do I organize the import statements of my various modules, and the contents of my <strong>init</strong>.py files, to meet those objectives?</p>

<p>(I would like to use distutils to manage the code, and I read that running the code from the top-level directory is a useful precursor.)</p>
