Skip to content
This repository was archived by the owner on Mar 24, 2021. It is now read-only.

Commit 673914b

Browse files
author
Emmett Butler
authored
Merge pull request #931 from carsonip/fix-rdkafka-setup
Use env var to explicitly specify rdkafka setup
2 parents 5da8a89 + e0fd8a9 commit 673914b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,16 @@ Using the librdkafka extension
159159
------------------------------
160160

161161
PyKafka includes a C extension that makes use of librdkafka to speed up producer
162-
and consumer operation. PyKafka requires librdkafka v0.9.1+. Some system package managers may
163-
not have up-to-date versions. To use the librdkafka extension, you need to make sure the header
162+
and consumer operation.
163+
164+
To ensure the C extension is compiled, set environment variable ``RDKAFKA_INSTALL=system`` during
165+
``pip install`` or ``setup.py``, i.e. ``RDKAFKA_INSTALL=system pip install pykafka``.
166+
The setup will fail if C extension is not compiled. Oppositely, if ``RDKAFKA_INSTALL=''``, this
167+
explicitly specifies that the C extension should not be compiled. The current default behavior is
168+
to compile the extension but will not fail the setup if compilation fails.
169+
170+
PyKafka requires librdkafka v0.9.1+. Some system package managers may not have
171+
up-to-date versions. To use the librdkafka extension, you need to make sure the header
164172
files and shared library are somewhere where python can find them, both when you build
165173
the extension (which is taken care of by ``setup.py develop``) and at run time.
166174
Typically, this means that you need to either install librdkafka in a place

setup.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,19 @@ def run_setup(with_rdkafka=True):
184184
]
185185
)
186186

187+
188+
# Use environment variable RDKAFKA_INSTALL to explicitly specify whether rdkafka c extension should be compiled
189+
# 'system': Compile with librdkafka installed in system
190+
# '' (empty string): No compile
191+
rdkafka_install_type = os.environ.get('RDKAFKA_INSTALL')
192+
187193
try:
188-
if not is_cpython:
194+
if rdkafka_install_type == '':
195+
run_setup(with_rdkafka=False)
196+
elif not is_cpython:
197+
if rdkafka_install_type == 'system':
198+
raise Exception("librdkafka is not supported under %s, but RDKAFKA_INSTALL specified"
199+
% python_implementation)
189200
print("librdkafka is not supported under %s" % python_implementation)
190201
print(15 * "-")
191202
print("INFO: Failed to build rdkafka extension:")
@@ -195,6 +206,8 @@ def run_setup(with_rdkafka=True):
195206
else:
196207
run_setup()
197208
except ve_build_ext.BuildFailed as exc:
209+
if rdkafka_install_type == 'system':
210+
raise
198211
print(15 * "-")
199212
print("INFO: Failed to build rdkafka extension:")
200213
print(exc.cause)

0 commit comments

Comments
 (0)