setup.py 6.01 KB
Newer Older
1 2 3 4 5 6 7
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.

Vincent Michel's avatar
Vincent Michel committed
8 9
import os
import sys
10
import inspect
Vincent Michel's avatar
Vincent Michel committed
11

12 13
from distutils.cmd import Command
from setuptools import setup, find_packages
14

15 16
TESTING = any(x in sys.argv for x in ['test', 'pytest'])

Vincent Michel's avatar
Vincent Michel committed
17

18 19 20 21 22 23
def abspath(*path):
    """A method to determine absolute path for a given relative path to the
    directory where this setup.py script is located"""
    setup_dir = os.path.dirname(os.path.abspath(__file__))
    return os.path.join(setup_dir, *path)

Vincent Michel's avatar
Vincent Michel committed
24

25 26 27
def find_commands(module):
    """
    Finds instances of distutils.Command in a module.
28
    Returns a dict<command name: command class>
29 30 31 32 33 34 35 36 37 38 39 40 41 42
    """
    items = (getattr(module, item) for item in dir(module)
             if not item.startswith('_'))
    classes = (item for item in items if inspect.isclass(item))
    commands = (cls for cls in classes if issubclass(cls, Command))
    local_commands = (cmd for cmd in commands
                      if cmd.__module__.startswith('extensions.'))
    return dict(((cmd.cmd_name, cmd) for cmd in local_commands))


def find_extensions():
    """Find bliss extensions. Returns a list of distutils.Command"""
    top = abspath('extensions')
    commands = {}
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    for name in os.listdir(top):
        if name.startswith('_'):
            continue
        full_name = os.path.join(top, name)
        if os.path.isdir(full_name):
            ext_type_name = 'extensions.' + name
            try:
                ext_type_module = __import__(ext_type_name, None, None,
                                             ext_type_name)
                for ext_name in ext_type_module.__all__:
                    ext_name = ext_type_name + '.' + ext_name
                    ext_module = __import__(ext_name, None, None, ext_name)
                    commands.update(find_commands(ext_module))
            except Exception:
                continue
        else:
            # must be a python module
            name, ext = os.path.splitext(name)
            if ext != '.py':
                continue
            ext_name = 'extensions.' + name
            try:
65 66
                ext_module = __import__(ext_name, None, None, ext_name)
                commands.update(find_commands(ext_module))
67 68
            except Exception:
                continue
69 70 71 72 73 74
    return commands


def main():
    """run setup"""

75
    py_xy = sys.version_info[:2]
76
    py_xy_str = '.'.join(map(str, py_xy))
77

78 79 80
    if py_xy < (2, 7) or py_xy >= (3, 0):
        print("Incompatible python version ({0}). Needs python 2.x " \
              "(where x > 6).".format(py_xy_str))
81 82
        sys.exit(1)

83 84 85 86 87 88
    meta = {}
    execfile(abspath('bliss', 'release.py'), meta)

    packages = find_packages(where=abspath(), exclude=('extensions*',))

    cmd_class = find_extensions()
89

90 91 92 93 94 95 96 97 98 99
    install_requires = [
        "redis  >= 2.8",
        "PyYaml",
        "netifaces < 0.10.5",
        "louie",
        "jinja2 >= 2.7",
        "flask",
        "treelib",
        "gipc",
        "jedi",
100
        "ptpython >= 0.39",
101 102 103 104
        "docopt",
        "bottle",
        "six >= 1.10",
        "tabulate",
105
        "pyserial",
Matias Guijarro's avatar
Matias Guijarro committed
106
        "ruamel.yaml == 0.11.15",
107 108 109 110 111
        "zerorpc",
        "msgpack_numpy",
        "blessings",
        "posix_ipc",
        "h5py",
112 113 114 115
        "gevent >= 1.2.2",
        "pygments",
        "numpy",
        'enum34 ; python_version < "3.4"',
116 117
        "h5py",
        "mendeleev",
Vincent Michel's avatar
Vincent Michel committed
118
        "pint",
119
        'mock ; python_version < "3.3"',
120 121 122
    ]

    tests_require = [
123
        'pytest',
124
        'pytest-mock',
125
        'pytest-cov',
126 127
    ]

128
    setup_requires = [
129
#        'setuptools >= 37',
130 131 132 133
    ]

    if TESTING:
        setup_requires += ['pytest-runner']
134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    setup(name=meta['name'],
          author=meta['author'],
          version=meta['version'],
          description=meta['description'],
          license=meta['license'],
          url=meta['url'],
          package_dir={"bliss": "bliss"},
          packages=packages,
          package_data={"bliss.config.redis": ["redis.conf"],
                        "bliss.config.plugins": ["*.html"],
                        "bliss.config.conductor.web": ["*.html",
                                                       "css/*.*",
                                                       "css/jstree/*.*",
                                                       "js/*.*",
                                                       "res/*.*"],
                        'bliss.shell.web': ['*.html', 'css/*.css', "js/*.js"]},
          cmdclass=cmd_class,
          scripts=["bin/beacon-server-list", 'bin/bliss_webserver',
                   'bin/sps_data_watch', 'bin/flint'],
          entry_points={
              'console_scripts': [
                  'bliss = bliss.shell.cli.main:main',
                  'bliss-emulator = bliss.controllers.emulator:main',
                  'beacon-server = bliss.config.conductor.server:main',
159
                  'bliss-ct2-server = bliss.controllers.ct2.server:main',
160 161 162 163 164 165 166 167 168 169 170 171 172
                  'CT2 = bliss.tango.servers.ct2_ds:main',
                  'Bliss = bliss.tango.servers.bliss_ds:main',
                  'BlissAxisManager =  bliss.tango.servers.axis_ds:main',
                  'BlissTempManager = bliss.tango.servers.temp_ds:main',
                  'Musst = bliss.tango.servers.musst_ds:main',
                  'Nanodac = bliss.tango.servers.nanodac_ds:main',
                  'FuelCell = bliss.tango.servers.fuelcell_ds:main',
                  'Gpib = bliss.tango.servers.gpib_ds:main',
                  'Keithley428 = bliss.tango.servers.keithley428_ds:main',
                  'Multiplexer = bliss.tango.servers.multiplexer_ds:main',
                  'LinkamDsc = bliss.tango.servers.linkamdsc_ds:main',
                  'NanoBpm = bliss.tango.servers.nanobpm_ds:main',
                  'NanoBpmServo = bliss.tango.servers.nanobpm_servo_ds:main'
173 174
              ],
          },
175 176
          install_requires=install_requires,
          tests_require=tests_require,
177
          setup_requires=setup_requires)
178 179 180 181


if __name__ == "__main__":
    main()