A helper for python package development
Posted 2011-09-03 12:48:32 by .

I like breaking Python development up into packages I can roll into eggs. The downside of this approach is typing "python setup.py ..." a lot from the command line. To reduce typing I came up with the following Bash function. I use it a lot and would like to share with others. I place it in the public domain.

  
#!/bin/bash


# Wrap python setup.py . By default it will
# run a python setup.py develop. If there is a BASKET
# environment variable set it will use this as the
# sole source for egg dependancies.
#
# The function will first test for the presence of
# the setup.py file. If its not present it will exit.
#
function sd() {
    if [ "$1" == "" ]; then
        COMMAND="develop"
    else
        COMMAND=$1
    fi

    if [ -e setup.py ]; then
        if [ -z "$BASKET" ]; then
            # No basket defined so don't use it as a source
            python setup.py $COMMAND
        else
            # The BASKET if set will need to specify -i/-f.
            # For example: BASKET="-i http...."
            # For example: BASKET="-f http...."
            #
            if [ $COMMAND == "develop" ]; then
                # only use basket for develop. It does not work
                # with other options.
                python setup.py develop $BASKET
            else
                python setup.py $COMMAND
            fi
        fi
    else
        echo "No setup.py found here: '"`pwd`"'"
    fi
}

You can add this to your ~/.bashrc or just use it from the command line:

source pythonsetup.sh

The 'sd' command willl now be available. Any command you can do to "python setup.py" can be used with "sd".

#Example calls:


# Default (python setup.py develop):
$ sd
running develop
running egg_info
writing lib/boaconstructor.egg-info/PKG-INFO
writing eager_resources to lib/boaconstructor.egg-info/eager_resources.txt
:
etc
:
Installed /Users/omul/Dropbox/src/boaconstructor/lib
Processing dependencies for boaconstructor==0.4.0
Finished processing dependencies for boaconstructor==0.4.0



# Running tests (python setup.py test:
$ sd test
running test
running egg_info
:
etc
:
Test the utils module render which is used by the Template class. ... ok
testValueParsing (boaconstructor.tests.testboaconstructor.BoaConstructor)
Test parsing a dict entries value to recover the reference and ... ok

----------------------------------------------------------------------
Ran 15 tests in 0.010s

OK

 

Comments

Commenting is currently disabled on this post.