-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
executable file
·108 lines (96 loc) · 3.34 KB
/
setup.py
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
108
#!/usr/bin/env python
#
# pystatgrab
# https://libstatgrab.org/pystatgrab/
# Copyright (C) 2004-2019 Tim Bishop
# Copyright (C) 2005-2013 Adam Sampson
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# $Id$
#
"""Python bindings for libstatgrab."""
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
from subprocess import check_call, check_output, CalledProcessError
import sys
import os
# version of pystatgrab
VERSION = "0.7.3"
# required version of libstatgrab
LIBSTATGRAB = "0.91"
def warn(*s):
sys.stderr.write("".join(map(str, s)) + "\n")
def die(*s):
warn("Error: ", *s)
sys.exit(1)
def pkg_config(*args):
"""Run pkg-config with the given arguments.
Return the output as a byte string, or None if it failed."""
prog = os.environ.get("PKG_CONFIG", "pkg-config")
try:
return check_output([prog] + list(args))
except OSError:
die("could not run ", prog)
except CalledProcessError:
return None
# test for libstatgrab version using pkg-config
if pkg_config("--atleast-version", LIBSTATGRAB, "libstatgrab") is None:
die("libstatgrab version ", LIBSTATGRAB, " or better is not installed (according to pkg-config)")
# get cflags and libs for libstatgrab
cflags = pkg_config("--cflags", "libstatgrab")
libs = pkg_config("--libs", "libstatgrab")
try:
import Cython.Distutils
from Cython.Build import cythonize
cmdclass = {"build_ext": Cython.Distutils.build_ext}
ext_modules = cythonize(
[Extension(
"statgrab",
["statgrab.pyx"],
extra_compile_args = cflags.decode("utf-8").split(),
extra_link_args = libs.decode("utf-8").split(),
)],
language_level="3str",
)
except ImportError:
# Cython is not installed; use the shipped copy of statgrab.c.
cmdclass = {}
ext_modules = [Extension(
"statgrab",
["statgrab.c"],
extra_compile_args = cflags.decode("utf-8").split(),
extra_link_args = libs.decode("utf-8").split()
)]
# setup information
setup(name = "pystatgrab",
version = os.getenv("PYSTATGRAB_VERSION", VERSION),
description = "Python bindings for libstatgrab",
maintainer = "Tim Bishop",
maintainer_email = "[email protected]",
url = "https://libstatgrab.org/pystatgrab/",
license = "GNU LGPL v2 or later",
classifiers = [
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: System :: Monitoring",
],
cmdclass = cmdclass,
ext_modules = ext_modules,
)