Add option for inhibiting the core build while installing the python components. Add option for loading the core from a custom path. (#1089)
diff --git a/bindings/python/README.txt b/bindings/python/README.txt
index 82fe148..69e36bb 100644
--- a/bindings/python/README.txt
+++ b/bindings/python/README.txt
@@ -8,10 +8,18 @@
installing Visual Studio and using the "Developer Command Prompt" to perform the
installation. See BUILDING.txt for more information.
+By default, attempting to install the python bindings will trigger a build of
+the capstone native core. If this is undesirable for whatever reason, for
+instance, you already have a globally installed copy of libcapstone, you may
+inhibit the build by setting the environment variable LIBCAPSTONE_PATH. The
+exact value is not checked, just setting it will inhibit the build. During
+execution, this variable may be set to the path of a directory containing a
+specific version of libcapstone you would like to use.
+
If you don't want to build your own copy of Capstone, you can use a precompiled
binary distribution from PyPI. Saying `pip install capstone` should
automatically obtain an appropriate copy for your system. If it does not, please
-open an issue at https://github.com/aquynh/capstone and tag @rhelmot - they
+open an issue at https://github.com/aquynh/capstone and tag @rhelmot - she
will fix this, probably!
--------------------------------------------------------------------------------
diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py
index 3c9be87..bfd2e02 100644
--- a/bindings/python/capstone/__init__.py
+++ b/bindings/python/capstone/__init__.py
@@ -230,19 +230,22 @@
_cs = None
# Loading attempts, in order
+# - user-provided environment variable
# - pkg_resources can get us the path to the local libraries
# - we can get the path to the local libraries by parsing our filename
# - global load
# - python's lib directory
# - last-gasp attempt at some hardcoded paths on darwin and linux
-_path_list = [pkg_resources.resource_filename(__name__, 'lib'),
+_path_list = [os.getenv('LIBCAPSTONE_PATH', None),
+ pkg_resources.resource_filename(__name__, 'lib'),
join(split(__file__)[0], 'lib'),
'',
distutils.sysconfig.get_python_lib(),
"/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64']
for _path in _path_list:
+ if _path is None: continue
_cs = _load_lib(_path)
if _cs is not None: break
else:
diff --git a/bindings/python/setup.py b/bindings/python/setup.py
index a7f2472..0798e7a 100755
--- a/bindings/python/setup.py
+++ b/bindings/python/setup.py
@@ -156,8 +156,11 @@
class custom_build(build):
def run(self):
- log.info('Building C extensions')
- build_libraries()
+ if 'LIBCAPSTONE_PATH' in os.environ:
+ log.info('Skipping building C extensions since LIBCAPSTONE_PATH is set')
+ else:
+ log.info('Building C extensions')
+ build_libraries()
return build.run(self)