File: setup.py

package info (click to toggle)
pygattlib 0~20210616-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 508 kB
  • sloc: ansic: 5,031; cpp: 1,681; python: 386; makefile: 46; sh: 1
file content (107 lines) | stat: -rwxr-xr-x 3,343 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python3
# -*- mode: python; coding: utf-8 -*-

import os
import sys
import subprocess
from setuptools import setup, Extension
# from versions import get_boost_version

extension_modules = []


def get_boost_version(out=None):
    return 'boost_python%s%s' \
            % (sys.version_info.major, sys.version_info.minor)

def tests():
    # case: python3-py3x.so
    out = b"""
        libboost_python3-py36.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libboost_python3-py36.so
        libboost_python-py27.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libboost_python-py27.so
    """
    got = get_boost_version(out)
    expected = 'boost_python3-py36'
    assert got == expected, "Case 1: got: '{}'".format(got)

    # case: python3x.so
    out = b"""
        libboost_python38.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libboost_python38.so
    """
    got = get_boost_version(out)
    expected = 'boost_python38'
    assert got == expected, "Case 2: got: '{}'".format(got)

    # case: python-py3x
    out = b"""
	    libboost_python-py35.so (libc6,hard-float) => /usr/lib/arm-linux-gnueabihf/libboost_python-py35.so
	    libboost_python-py27.so (libc6,hard-float) => /usr/lib/arm-linux-gnueabihf/libboost_python-py27.so
    """
    got = get_boost_version(out)
    expected = 'boost_python-py35'
    assert got == expected, "Case 3: got: '{}'".format(got)

    print("OK, all seems fine.")


if sys.platform.startswith('linux'):
    glib_headers = subprocess.check_output(
        "pkg-config --cflags glib-2.0".split()).decode('utf-8')
    glib_headers = glib_headers.strip().split("-I")
    glib_headers = [x.strip() for x in glib_headers if x]

    glib_libs = subprocess.check_output(
        "pkg-config --libs glib-2.0".split()).decode('utf-8')
    glib_libs = glib_libs.strip().split("-l")
    glib_libs = [x.strip() for x in glib_libs if x]

    boost_py = get_boost_version()

    extension_modules = [
        Extension(
            'gattlib',
            ['src/gattservices.cpp',
             'src/beacon.cpp',
             'src/bindings.cpp',
             'src/gattlib.cpp',
             'src/bluez/lib/uuid.c',
             'src/bluez/attrib/gatt.c',
             'src/bluez/attrib/gattrib.c',
             'src/bluez/attrib/utils.c',
             'src/bluez/attrib/att.c',
             'src/bluez/src/shared/crypto.c',
             'src/bluez/src/log.c',
             'src/bluez/btio/btio.c'],

            libraries=glib_libs + [boost_py, "boost_thread", "bluetooth"],
            include_dirs=glib_headers + ['src/bluez'],
            define_macros=[('VERSION', '"5.25"')]
        )
    ]
else:
    raise OSError("Not supported OS")


if __name__ == "__main__":
    if len(sys.argv) >= 2:
        if sys.argv[1] == "--get-boost-lib":
            print(get_boost_version())
            sys.exit(0)
        if sys.argv[1] == "--run-test":
            tests()
            sys.exit(0)

with open("README.md", "r") as fh:
    long_description = fh.read()

setup(
    name='gattlib',
    version="0.20210616",
    description="Library to access Bluetooth LE devices",
    long_description=long_description,
    long_description_content_type="text/markdown",
    author="Oscar Acena",
    author_email="oscar.acena@gmail.com",
    url="https://github.com/oscaracena/pygattlib",
    ext_modules=extension_modules,
)