from setuptools import setup, find_packages, Command
from setuptools.command.build_py import build_py as _build_py
from distutils.spawn import find_executable
from glob import glob
import os.path
import imp


THRIFT = find_executable('thrift')

ROOT = os.path.abspath(os.path.dirname(__file__))

def read(fname):
    return open(os.path.join(ROOT, fname)).read()

def version():
    file, pathname, description = imp.find_module('sparts', [ROOT])
    return imp.load_module('sparts', file, pathname, description).__version__

class gen_thrift(Command):
    user_options=[]
    def initialize_options(self):
        pass
    def finalize_options(self):
        pass
    def run(self):
        self.mkpath(os.path.join(ROOT, 'sparts', 'gen'))
        for f in glob(os.path.join(ROOT, 'thrift', '*.thrift')):
            self.spawn([THRIFT, '-out', os.path.join(ROOT, 'sparts', 'gen'),
                        '-v', '--gen', 'py:new_style',
                        os.path.join(ROOT, 'thrift', f)])

class build_py(_build_py):
    def run(self):
        self.run_command('gen_thrift')
        _build_py.run(self)


cmdclass = {}
# If we have a thrift compiler installed, let's use it to re-generate
# the .py files.  If not, we'll use the pre-generated ones.
if THRIFT is not None:
    cmdclass = {'gen_thrift': gen_thrift,
                'build_py': build_py}

setup(
    name="sparts",
    version=version(),
    packages=find_packages(),
    description="Build services in python with as little code as possible",
    long_description=read("README.rst"),

    install_requires=[],
    setup_requires=['unittest2'],
    author='Peter Ruibal',
    author_email='ruibalp@gmail.com',
    license='ISC',
    keywords='service boostrap daemon thrift tornado',
    url='http://github.com/fmoo/sparts',

    test_suite="tests",
    cmdclass=cmdclass,

    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "Topic :: Software Development :: Libraries :: Application Frameworks",
        "License :: OSI Approved :: ISC License (ISCL)",
    ],
)

@@ -1353,16 +1353,36 @@
 ld_py%7D%0A%0A
+VERSION = version()%0A
 setup(%0A 
@@ -1411,25 +1411,23 @@
 version=
-version()
+VERSION
 ,%0A    pa
@@ -1806,16 +1806,95 @@
 sparts',
+%0A    download_url='https://github.com/fmoo/sparts/archive/%25s.tar.gz' %25 VERSION,
 %0A%0A    te

Set download_url in setup.py do github source .tar.gz