#!/usr/bin/env python2
# coding=utf-8

import sys

try:
    import pypandoc
except ImportError:
    print "The \"pypandoc\" package and the pandoc binary on your system " \
          "need to be present to run setuptools."
    sys.exit(1)


from setuptools import setup
from gitver.version import gitver_version, gitver_pypi

try:
    import gitver._version_next as next
    vtype = '(NEXT)'
except ImportError:
    vtype = '(RELEASE)'


def readme():
    return pypandoc.convert('README.md', 'rst')


def requirements():
    with open('requirements.txt') as f:
        return f.read()


def main():
    """Runs setuptools.setup()"""

    scripts = [
        'bin/gitver'
    ]

    print "--------------------------------------------------"
    print "Setting up for " + vtype + " v" + gitver_version
    print "--------------------------------------------------"

    setup(
        name='gitver',
        version=gitver_pypi,
        description='Simple version string management for git',
        long_description=readme(),
        license='Apache License, Version 2.0',
        author='Manuel Bua',
        url='https://github.com/manuelbua/gitver',
        scripts=scripts,
        packages=['gitver'],
        install_requires=requirements(),
        classifiers=[
            'Development Status :: 4 - Beta',
            'License :: OSI Approved :: Apache Software License',
            'Programming Language :: Python :: 2.7',
            'Topic :: Software Development :: Version Control',
        ]
    )


if __name__ == '__main__':
    main()

@@ -46,199 +46,8 @@
  sys
-%0A%0Atry:%0A    import pypandoc%0Aexcept ImportError:%0A    print %22The %5C%22pypandoc%5C%22 package and the pandoc binary on your system %22 %5C%0A          %22need to be present to run setuptools.%22%0A    sys.exit(1)%0A%0A
 %0Afro
@@ -128,16 +128,74 @@
 r_pypi%0A%0A
+make_sdist = len(%7B'sdist', 'build'%7D & set(sys.argv)) %3E 0%0A%0A
 try:%0A   
@@ -320,51 +320,552 @@
     
-return pypandoc.convert('README.md', 'rst')
+if make_sdist:%0A        try:%0A            import pypandoc%0A            return pypandoc.convert('README.md', 'rst')%0A        except ImportError:%0A            print %22Warning: the %5C%22pypandoc%5C%22 package and/or the pandoc %22 %5C%0A                  %22binary can't be found on your system: if you want to %22 %5C%0A                  %22generate the README.rst for PyPI you'll need to install %22 %5C%0A                  %22them properly, else a fallback description will be used.%22%0A%0A    # falling back to a simple description%0A    return 'Simple version string management for git'
 %0A%0A%0Ad

Fix issue #2