Skip to content

Commit 075a213

Browse files
committed
PkgConfigExtension: DRY
1 parent 6da9767 commit 075a213

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

setup.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import commands
1111
except ImportError:
1212
import subprocess as commands
13-
run = commands.getstatusoutput
1413

1514
version = '0.12'
1615

@@ -54,28 +53,27 @@ def _str2list(cls, pkgstr, onlystr):
5453
res.append(l.replace(onlystr, "", 1))
5554
return res
5655

57-
@property
58-
def include_dirs(self):
59-
res, includes = run('pkg-config --cflags-only-I %s' % self._pkg)
56+
@classmethod
57+
def _run(cls, command_string):
58+
res, output = commands.getstatusoutput(command_string)
6059
if res != 0:
61-
print('Failed to query pkg-config --cflags-only-I %s' % self._pkg)
60+
print('Failed to query %s' % command_string)
6261
sys.exit(1)
62+
return output
63+
64+
@property
65+
def include_dirs(self):
66+
includes = self._run('pkg-config --cflags-only-I %s' % self._pkg)
6367
return self._str2list(includes, '-I')
6468

6569
@property
6670
def library_dirs(self):
67-
res, libdirs = run('pkg-config --libs-only-L %s' % self._pkg)
68-
if res != 0:
69-
print('Failed to query pkg-config --libs-only-L %s' % self._pkg)
70-
sys.exit(1)
71+
libdirs = self._run('pkg-config --libs-only-L %s' % self._pkg)
7172
return self._str2list(libdirs, '-L')
7273

7374
@property
7475
def libraries(self):
75-
res, libs = run('pkg-config --libs-only-l %s' % self._pkg)
76-
if res != 0:
77-
print('Failed to query pkg-config --libs-only-l %s' % self._pkg)
78-
sys.exit(1)
76+
libs = self._run('pkg-config --libs-only-l %s' % self._pkg)
7977
return self._str2list(libs, '-l') + self._extra_libraries
8078

8179
@include_dirs.setter

0 commit comments

Comments
 (0)