Eclectic Media Git eclecti_deploy / master setup.py
master

Tree @master (Download .tar.gz)

setup.py @masterraw · history · blame

from setuptools import setup, find_packages
from distutils.cmd import Command
from sphinx.setup_command import BuildDoc
from sys import executable
from os import system, access, F_OK

with open("Readme.rst", "r") as fh:
    long_description = fh.read()

with open("requirements.txt", "r") as f:
    required = f.read().splitlines()

version = 0.1
name = 'eclecti_deploy'


class Docs(Command):
    user_options = [
        ('manpage=', None, 'The man page section you want to view (likely 5)'),
        ('compile', None, 'Force recompile of the docs'),
    ]

    def initialize_options(self):
        self.manpage = '1'
        self.compile = False

    def finalize_options(self):
        try:
            int(self.manpage)
        except ValueError:
            print('--manpage must be an int between 1 and 8')
            exit(1)

    def run(self):
        if not access('docs/build/man', F_OK) or self.compile:
            self.announce('Compiling docs...', level=4)
            system('%s setup.py build_sphinx' % executable)

        if self.manpage == '':
            system('man ./docs/build/man/*.1')
        else:
            system('man ./docs/build/man/*.%s' % self.manpage)


class InstallDocs(Command):
    user_options = [
        ('system-wide', None, 'Install pages system wide'),
    ]

    def initialize_options(self):
        self.system_wide = False

    def finalize_options(self):
        pass

    def run(self):
        self.announce('Compiling docs...')
        system('%s setup.py build_sphinx' % executable)
        self.announce('Installing docs')
        system('mkdir -p ~/.local/man/man1 ~/.local/man/man5')
        system('cp docs/build/man/%s.1 ~/.local/man/man1/' % name)
        system('cp docs/build/man/%s.5 ~/.local/man/man5/' % name)
        system('mandb')


class UninstallDocs(Command):
    user_options = [
        ('system-wide', None, 'Install pages system wide'),
    ]

    def initialize_options(self):
        self.system_wide = False

    def finalize_options(self):
        pass

    def run(self):
        self.announce('Uninstalling manpages')
        system('rm ~/.local/man/man1/%s.1' % name)
        system('rm ~/.local/man/man5/%s.5' % name)
        system('mandb')


setup(
    name=name,
    version=0.1,
    description='Custom Eclectic Media Solutions deploy script f/ flask',
    long_description=long_description,
    # long_description_content_type="text/x-rst",
    install_requires=required,
    url='git-server:arianagiroux/eclecti_deploy.git',
    author='Ariana Giroux',
    author_email='ariana.giroux@gmail.com',
    license='MIT',
    packages=find_packages(),
    setup_requires=["pytest-runner"],
    tests_require=["pytest"],
    zip_safe=True,
    entry_points={
        'console_scripts': ['eclecti_deploy=eclecti_deploy.__main__:run'],
    },
    cmdclass={
        'build_sphinx': BuildDoc,
        'docs': Docs,
        'install_docs': InstallDocs,
        'uninstall_docs': UninstallDocs,
    },
    package_data={'eclecti_deploy': ['.deploy.template.yml',
                                     'fab/commands/deploy/*.conf']},
    command_options={
        'build_sphinx': {
            'project': ('setup.py', name),
            'version': ('setup.py', str(0.1)),
            'source_dir': ('setup.py', 'docs'),
            'build_dir': ('setup.py', 'docs/build'),
            'builder': ('setup.py', 'man'),
        }},
    classifiers=(
                "Programming Language :: Python :: 3",
                "License :: OSI Approved :: MIT License",
                "Operating System :: OS Independent",
                "Development Status :: 4 - Beta",
                "Environment :: Console",
                "Intended Audience :: Developers",
                "Intended Audience :: End Users/Desktop",
                "Intended Audience :: Information Technology",
                "License :: OSI Approved :: MIT License",
                "Operating System :: Unix",
                "Topic :: System :: Networking :: Monitoring",
                "Topic :: Utilities",
    ),
)