from distutils.command.bdist import bdist as _bdist
from distutils.core import Command
import os
import shutil
import subprocess
import sys

from setuptools import setup
from setuptools.command.sdist import sdist as _sdist

from pyleus import __version__
from pyleus import BASE_JAR

JAVA_SRC_DIR = "topology_builder/"
BASE_JAR_SRC = os.path.join(JAVA_SRC_DIR, "dist", BASE_JAR)
BASE_JAR_DST = os.path.join("pyleus", BASE_JAR)


class build_java(Command):

    description = "Build the topology base JAR"
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def _make_jar(self):
        subprocess.check_call(["make", "-C", JAVA_SRC_DIR])

    def _copy_jar(self):
        shutil.copy(BASE_JAR_SRC, BASE_JAR_DST)

    def run(self):
        self._make_jar()
        self._copy_jar()


class bdist(_bdist):

    sub_commands = [('build_java', None)]

    def run(self):
        for cmd_name in self.get_sub_commands():
            self.run_command(cmd_name)

        _bdist.run(self)


class sdist(_sdist):

    sub_commands = [('build_java', None)]

    def run(self):
        for cmd_name in self.get_sub_commands():
            self.run_command(cmd_name)

        _sdist.run(self)


extra_install_requires = []
if sys.version_info < (2, 7):
    # argparse is in the standard library of Python >= 2.7
    extra_install_requires.append("argparse")


setup(
    name="pyleus",
    version=__version__,
    author="Patrick Lucas",
    author_email="plucas@yelp.com",
    description="Standard library and deployment tools for using Python "
        "with Storm",
    url="http://pyleus.org",
    classifiers=[
        "Programming Language :: Python",
        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
        "Operating System :: OS Independent",
        "License :: OSI Approved :: Apache Software License",
        "Intended Audience :: Developers",
        "Topic :: Software Development :: Libraries",
        "Topic :: System :: Distributed Computing",
        "Development Status :: 4 - Beta",
    ],
    packages=[
        "pyleus", "pyleus.cli", "pyleus.cli.commands",
        "pyleus.storm", "pyleus.storm.serializers"],
    scripts=["scripts/pyleus"],
    install_requires=[
        "PyYAML",
        "msgpack-python",
        "virtualenv",
    ] + extra_install_requires,
    package_data={'pyleus': [BASE_JAR]},
    cmdclass={
        'build_java': build_java,
        'bdist': bdist,
        'sdist': sdist,
    },
)

@@ -1246,16 +1246,90 @@
 self)%0A%0A%0A
+def readme():%0A    with open(%22README.rst%22) as f:%0A        return f.read()%0A%0A%0A
 extra_in
@@ -1692,24 +1692,55 @@
 ith Storm%22,%0A
+    long_description=readme(),%0A
     url=%22htt

Include README.rst as project long_description