|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +import io |
| 4 | +import os |
| 5 | +import sys |
| 6 | +import re |
| 7 | +from setuptools import setup, find_packages |
| 8 | +from distutils.command.build_clib import build_clib |
| 9 | +from distutils.command.install_lib import install_lib |
| 10 | +from distutils import log |
| 11 | + |
| 12 | +NAME = "pyaloha" |
| 13 | +DESCRIPTION = "Alohalytics statistics engine python parser" |
| 14 | +URL = "https://github.com/mapsme/Alohalytics" |
| 15 | +EMAIL = "me@alex.bio" |
| 16 | +AUTHOR = "Alexander Zolotarev" |
| 17 | + |
| 18 | +here = os.path.abspath(os.path.dirname(__file__)) |
| 19 | +about = {} |
| 20 | +project_slug = NAME.lower().replace("-", "_").replace(" ", "_") |
| 21 | +with open(os.path.join(here, project_slug, '__init__.py')) as f: |
| 22 | + exec(f.read(), about) |
| 23 | + |
| 24 | +class build_clib_shared(build_clib, object): |
| 25 | + def build_libraries(self, libraries): |
| 26 | + for (lib_name, build_info) in libraries: |
| 27 | + sources = build_info.get('sources') |
| 28 | + if sources is None or not isinstance(sources, (list, tuple)): |
| 29 | + raise DistutilsSetupError( |
| 30 | + "in 'libraries' option (library '%s'), " |
| 31 | + "'sources' must be present and must be " |
| 32 | + "a list of source filenames" % lib_name) |
| 33 | + sources = list(sources) |
| 34 | + |
| 35 | + log.info("building '%s' library", lib_name) |
| 36 | + |
| 37 | + # First, compile the source code to object files in the library |
| 38 | + # directory. (This should probably change to putting object |
| 39 | + # files in a temporary build directory.) |
| 40 | + macros = build_info.get('macros') |
| 41 | + include_dirs = build_info.get('include_dirs') |
| 42 | + extra_preargs = build_info.get('extra_preargs') |
| 43 | + extra_postargs = build_info.get('extra_postargs') |
| 44 | + target_lang = build_info.get('target_lang') |
| 45 | + objects = self.compiler.compile(sources, |
| 46 | + output_dir=self.build_temp, |
| 47 | + macros=macros, |
| 48 | + include_dirs=include_dirs, |
| 49 | + extra_preargs=extra_preargs, |
| 50 | + extra_postargs=extra_postargs, |
| 51 | + debug=self.debug) |
| 52 | + |
| 53 | + # Now "link" the object files together into a static library. |
| 54 | + # (On Unix at least, this isn't really linking -- it just |
| 55 | + # builds an archive. Whatever.) |
| 56 | + self.compiler.link_shared_object(objects, lib_name, |
| 57 | + output_dir=self.build_clib, |
| 58 | + target_lang=target_lang, |
| 59 | + debug=self.debug) |
| 60 | + |
| 61 | + |
| 62 | +class install_lib_custom(install_lib, object): |
| 63 | + def install(self): |
| 64 | + outfiles = super(install_lib_custom, self).install() |
| 65 | + |
| 66 | + log.info("copying additional libraries") |
| 67 | + build_clib = self.get_finalized_command('build_clib') |
| 68 | + for lib in build_clib.libraries: |
| 69 | + libname = lib[0] |
| 70 | + ext = build_clib.compiler.shared_lib_extension |
| 71 | + target_libname = os.path.join( |
| 72 | + self.install_dir, *libname.split(".") |
| 73 | + ) + ext |
| 74 | + |
| 75 | + self.copy_file( |
| 76 | + os.path.join(build_clib.build_clib, libname), |
| 77 | + target_libname |
| 78 | + ) |
| 79 | + if outfiles is None: |
| 80 | + outfiles = [] |
| 81 | + outfiles.append(target_libname) |
| 82 | + return outfiles |
| 83 | + |
| 84 | + |
| 85 | +c_api = ( |
| 86 | + 'pyaloha.iterate_events', |
| 87 | + { |
| 88 | + 'sources': ['c_api/iterate_events.cc'], |
| 89 | + 'include_dirs': ['../Alohalytics/src'], |
| 90 | + 'extra_preargs': ['-std=c++11'], |
| 91 | + 'target_lang': 'c++', |
| 92 | + } |
| 93 | +) |
| 94 | + |
| 95 | +setup( |
| 96 | + name=NAME, |
| 97 | + version=about['__version__'], |
| 98 | + description=DESCRIPTION, |
| 99 | + author=AUTHOR, |
| 100 | + author_email=EMAIL, |
| 101 | + url=URL, |
| 102 | + license='MIT', |
| 103 | + libraries=[c_api], |
| 104 | + packages=find_packages(), |
| 105 | + cmdclass={ |
| 106 | + 'build_clib': build_clib_shared, |
| 107 | + 'install_lib': install_lib_custom, |
| 108 | + }, |
| 109 | + classifiers=[ |
| 110 | + # Trove classifiers |
| 111 | + # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers |
| 112 | + 'License :: OSI Approved :: MIT License', |
| 113 | + 'Programming Language :: Python', |
| 114 | + 'Programming Language :: Python :: 2', |
| 115 | + 'Programming Language :: Python :: 2.7', |
| 116 | + 'Programming Language :: Python :: 3', |
| 117 | + 'Programming Language :: Python :: 3.5', |
| 118 | + 'Programming Language :: Python :: 3.6', |
| 119 | + 'Programming Language :: Python :: Implementation :: CPython', |
| 120 | + ], |
| 121 | +) |
| 122 | + |
0 commit comments