Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58205

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

Date 2013-10-31 22:12 +0200
From Göktuğ Kayaalp <self@gkayaalp.com>
Subject Testing python command line apps -- Running from within the projects w/o installing
Newsgroups comp.lang.python
Message-ID <mailman.1890.1383251481.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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ğ

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Testing python command line apps -- Running from within the projects w/o installing Göktuğ Kayaalp <self@gkayaalp.com> - 2013-10-31 22:12 +0200

csiph-web