Testing python command line apps -- Running from within the projects w/o installing

Göktuğ Kayaalp self at gkayaalp.com
Thu Oct 31 16:12:07 EDT 2013


Hi all,

I'm using python to write command line apps from time to time. I wonder
*what is the conventional way to test-run these apps from within the
project itself, while developing, without installing*.

My usual practise is to have two entry points to the program as
executable scripts.  I usually put executables into a directory called
`scripts/'.  The source code of the program is organized into a package,
and the package has an entry point which is a function that is passed
the command line arguments (sys.argv[1:]).  One of the scripts -- the
one that will be installed -- assumes that the package is installed.  It
imports the entry function of the package and calls it:

    #!/usr/bin/env python3.3
    from package.module import main
    import sys

    if __name__ == '__main__':
        exit(main(sys.argv[1:]))

The other script is for running the version of the package that is
currently being developed in the project directory.  In that script,
I manipulate sys.path to have the project root at the very front:

    #!/usr/bin/env python3.3
    import sys
    import os

    sys.path.insert(0, os.path.join(os.path.realpath(".."), "sug/"))

    from package import module

    if __name__ == '__main__':
        exit(module.main(sys.argv[1:]))

Even though I use virtualenvs for each project and have tests, I still
want to run and see effects of my changes immediately and do not like to
install the package every time I make a small change.

I have surveyed most popular projects on Github, only to see nothing in
common: some only have scripts like the first example, some use entry
point attributes in setup.py, some have these scripts very deep in the
package hierarchy etc.  What is the `one true way' to achieve this?
I want to emphasise that I do not want to have to install the package
in order to be able to run the executable scripts.

cheers,
	göktuğ

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20131031/16c02264/attachment.sig>


More information about the Python-list mailing list