-
Notifications
You must be signed in to change notification settings - Fork 43
/
setup.py
71 lines (65 loc) · 2.77 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
# setup.py script for pyparted
# Copyright (C) 2011-2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author(s): David Cantrell <[email protected]>
# Alex Skinner <[email protected]>
#
# pylint: skip-file
import subprocess
import glob
import os
import platform
import sys
from setuptools import setup, Extension
pyparted_version = '3.13.0'
python_version = sys.version_info
need_libparted_version = '3.4'
need_python_version = (3, 5)
if python_version < need_python_version:
raise RuntimeError("pyparted requires Python version %d.%d or higher"
% need_python_version)
# Recipe from:
# http://code.activestate.com/recipes/502261-python-distutils-pkg-config/
def pkgconfig(*packages, **kwargs):
flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
try:
for token in subprocess.check_output(["pkg-config", "--libs", "--cflags"] + list(packages),
universal_newlines=True).split():
kwargs.setdefault(flag_map.get(token[:2]), []).append(token[2:])
return kwargs
except subprocess.CalledProcessError as e:
sys.exit("Cannot find pkg-config dependencies:\n" + e.output)
# This list is in the format necessary for the define_macros parameter
# for an Extension() module definition. See:
# http://docs.python.org/distutils/setupscript.html#preprocessor-options
features = [('PYPARTED_VERSION', "\"%s\"" % pyparted_version),
('PY_SSIZE_T_CLEAN', None)]
setup(name='pyparted',
version=pyparted_version,
author='David Cantrell',
author_email='[email protected]',
url='https://github.com/dcantrell/pyparted/',
description='Python bindings for GNU parted',
license='GPLv2+',
packages=['parted'],
package_dir={'parted': 'src/parted'},
ext_modules=[Extension('_ped',
sorted(glob.glob(os.path.join('src', '*.c'))),
define_macros=features,
**pkgconfig('libparted >= %s' % need_libparted_version,
include_dirs=['include']))
])