Skip to content

Commit dacfaf1

Browse files
committed
setup.py: Fallback to use the system hiredis library.
Fixes #158 fully, including using a system-provided hiredis. When the hiredis git submodule hasn't been initialized, print a message about it, and attempt to link against the a system-provided hiredis library instead. * setup.py (is_hiredis_bundled): New procedure. (get_hiredis_bundled_sources): Likewise. Print a message when bundled_hiredis_sources is empty. (get_sources): Adjust to use the above procedure. (get_linker_args): Add -lhiredis when the bundled hiredis is not used.
1 parent 8adb1b3 commit dacfaf1

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

setup.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import importlib
88
import glob
99
import io
10+
import os
1011
import sys
1112

1213

@@ -17,16 +18,39 @@ def version():
1718
return module.__version__
1819

1920

21+
def is_hiredis_bundled():
22+
hiredis_submodule = 'vendor/hiredis'
23+
if (os.path.exists(hiredis_submodule)
24+
and not os.path.isfile(hiredis_submodule)):
25+
return not os.listdir()
26+
return False
27+
28+
29+
def get_hiredis_bundled_sources():
30+
hiredis_sources = ("alloc", "async", "hiredis", "net", "read",
31+
"sds", "sockcompat")
32+
if is_hiredis_bundled():
33+
return ["vendor/hiredis/%s.c" % src for src in hiredis_sources]
34+
return []
35+
36+
37+
if not is_hiredis_bundled():
38+
print('the bundled hiredis sources were not found;'
39+
' system hiredis will be used\n'
40+
'to use the bundled hiredis sources instead,'
41+
' run "git submodule update --init"')
42+
43+
2044
def get_sources():
21-
hiredis_sources = ("alloc", "async", "hiredis", "net", "read", "sds", "sockcompat")
22-
return sorted(glob.glob("src/*.c") + ["vendor/hiredis/%s.c" % src for src in hiredis_sources])
45+
return sorted(glob.glob("src/*.c") + get_hiredis_bundled_sources())
2346

2447

2548
def get_linker_args():
2649
if 'win32' in sys.platform or 'darwin' in sys.platform:
2750
return []
2851
else:
29-
return ["-Wl,-Bsymbolic", ]
52+
return ["-Wl,-Bsymbolic", ] + \
53+
['-lhiredis'] if not is_hiredis_bundled() else []
3054

3155

3256
def get_compiler_args():

0 commit comments

Comments
 (0)