setup.py 4.31 KB
Newer Older
1 2 3 4
#!/usr/bin/env python

from setuptools import setup, find_packages
import os
5
import re
6
import subprocess
7

8 9 10 11 12 13
try:
    import pypandoc
    README = pypandoc.convert('README.md', 'rst')
except(IOError, ImportError):
    README = open('README.md').read()

14 15 16 17 18 19 20 21 22 23
try:
    unicode
except NameError:
    # Required for Python 3.x
    class unicode(object):
        def __new__(cls, s):
            if isinstance(s, str):
                return s
            return s and s.decode('utf-8') or None

24 25 26 27
SCRIPTS = [os.path.join('bin', n) for n in [
    'debops', 'debops-init', 'debops-task',
    'debops-defaults', 'debops-padlock', 'debops-update']]

28 29 30 31 32 33
# Retrieve the project version from 'git describe' command and store it in the
# VERSION file, needed for correct installation of the Python package
try:
    with open(os.devnull, 'w') as devnull:
        RELEASE = subprocess.check_output(
                ['git describe'], shell=True, stderr=devnull
34
                ).strip(b'\n').lstrip(b'v')
35 36 37 38 39 40
    with open('VERSION', 'w') as version_file:
        version_file.write('{}\n'.format(RELEASE))
except subprocess.CalledProcessError:
    try:
        RELEASE = open('VERSION').read().strip()
    except Exception:
41 42 43 44 45 46 47 48 49 50
        try:
            with file('CHANGELOG.rst') as changelog:
                for count, line in enumerate(changelog):
                    if re.search('^`debops v', line):
                        RELEASE = line.split()[1].rstrip(b'`_').lstrip(b'v')
                        break
            with open('VERSION', 'w') as version_file:
                version_file.write('{}\n'.format(RELEASE))
        except Exception:
            RELEASE = '0.0.0'
51

52 53 54 55 56
try:
    # Symlink the 'ansible/' directory inside of the 'debops/' Python package
    # directory. The files will be included in the package using the
    # MANIFEST.in file. This requires 'python-setuptools' APT package from
    # 'jessie-backports' repository.
57
    if not os.path.exists('debops/ansible'):
58
        os.symlink('../ansible', 'debops/ansible')
59 60
    setup(
        name="debops",
61
        version=unicode(RELEASE),
62 63 64 65 66
        install_requires=['argparse', 'future'],
        extras_require={
            'ansible': ['ansible', 'netaddr', 'passlib',
                        'python-ldap', 'dnspython']
            },
67

68 69 70
        scripts=SCRIPTS,
        packages=find_packages(exclude=['tests']),
        include_package_data=True,
71

72 73 74 75 76 77 78 79 80 81 82
        # metadata for upload to PyPI
        author="DebOps Developers",
        author_email="debops-users@lists.debops.org",
        description="Your Debian-based data center in a box",
        long_description=README,
        license="GPL-3.0",
        keywords="ansible debian sysadmin",
        url="https://debops.org/",
        python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, '
                        '!=3.3.*, !=3.4.*, <4',
        download_url="https://github.com/debops/debops"
83
                    "/archive/v" + unicode(RELEASE) + ".tar.gz",
84
        classifiers=[
85
                    'Development Status :: 5 - Production/Stable',
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                    'Environment :: Console',
                    'Intended Audience :: Information Technology',
                    'Intended Audience :: System Administrators',
                    'License :: OSI Approved :: GNU General Public License v3 '
                    'or later (GPLv3+)',
                    'Natural Language :: English',
                    'Operating System :: POSIX',
                    'Programming Language :: Other Scripting Engines',
                    'Programming Language :: Python',
                    'Programming Language :: Python :: 2',
                    'Programming Language :: Python :: 2.7',
                    'Programming Language :: Python :: 3',
                    'Programming Language :: Python :: 3.5',
                    'Programming Language :: Python :: 3.6',
                    'Topic :: System :: Installation/Setup',
                    'Topic :: System :: Systems Administration',
                    'Topic :: Utilities'
        ],
104

105 106 107 108 109 110 111 112 113 114
        # these are for easy_install (used by bdist_*)
        zip_safe=True
        #    entry_points = {
        #        "console_scripts": [
        #            "debops = debops.cmds.main:run",
        #        ],
        #    },
    )
finally:
    # Unlink the symlinked 'ansible/' directory
115 116
    if os.path.islink('debops/ansible'):
        os.unlink('debops/ansible')