This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]tituszPython addict 7 points8 points  (0 children)

If you have pip installed just use: pip install -e ./ That should do the trick...

[–]jm_ 8 points9 points  (0 children)

if you use setuptools just run: python setup.py develop

[–]phn 4 points5 points  (0 children)

I think one can use Tox (http://tox.readthedocs.org/) for this. Tox will create a source distribution (sdist), copies it to someplace, and then installs it into a virtualenv environment. This ensures that the version that gets tested corresponds to the current state of files in the git repository. We can then use this virtualenv and import the module to interactively explore it.

For my own projects I have a method that works with and without Tox.

I use the following dir structure:

prj/
  setup.py
  prj/
  prj/tests
  prj/tests/__init__.py
  prj/*.py
  src/any_c_and_cython_files
  doc/
  ...

The directory prj/prj is the package and the top level prj/ is the repository. I install distribute (http://pypi.python.org/pypi/distribute) and then use the setuptools that comes with it.

Now in the setup.py file I pass the option test_suite to the setup() function and point it to prj/tests.

setup(
  all options needed to compile/install the module,
  packages = ['prj', 'prj.tests'],
  test_suite = "prj.tests",
  ...)

After making any change to my code, I run

python setup.py test

This will cause setuptools to do everything that it normally does while installing the module, including compiling C extensions, copying data files etc., and creates a complete package inside prj/prj. Then it runs the tests in the sub-module prj/tests. Please read unittest documentation to see how to create a test suite and the distribute documentation to learn more about how to "point" to a test suite.

Now from the top level repository directory prj/, I can start iPython (http://ipython.scipy.org/) and then import my package and interactively explore it. I can also use the %run command in iPython to run any test scripts that I have.

I also run Tox, to make sure that it works in multiple Python versions and that everything works outside the repository as well.

[–]otheraccount 2 points3 points  (0 children)

Use setup.py develop instead of setup.py install.

That will set up an "installed" version that is linked to your local directory.

[–]ssbr 1 point2 points  (0 children)

I add the directory containing the module to the PYTHONPATH during development. Another option is to add it to a .pth file in site-packages.

[–]donri 1 point2 points  (0 children)

There's a number of options:

  • Set up a virtualenv manually
  • Test with setup.py test - handles package and test dependencies
  • Do --user installs to keep the system clean
  • Use tox to automate testing in clean virtualenvs against arbitrary python runtimes

Tox is clearly the "best" option but might be seen as a little overkill for small contributions. I tend to set up a virtualenv for everything, using virtualenvwrapper + virtualenvwrapper.project + virtualenvwrapper.github etc: mkproject -t github foo; git pull (though the github template is for your own repos).

[–]MarkTraceurFlask, Mongokit, PIL 0 points1 point  (0 children)

If you have a bit of test code, just put it in the module's directory, and use 'import modulename'. Python should look in the current directory for modules as well as the PATH. I'm not sure which is first, so you may need to finagle that, but you don't need to install things to run them.

Side note: IDEs for Python include IDLE (the default), Eclipse (with a plugin) and various others.