From 801178bea41398c62be271a8682c8fabcfd3dfdd Mon Sep 17 00:00:00 2001 From: Alex Chernetz Date: Fri, 19 Jun 2015 23:18:52 -0700 Subject: [PATCH 1/2] [Python binding] Fix setup.py to allow installing in a virtualenv In a virtualenv: - site.getusersitepackages() won't import - get_python_lib() will return the directory inside the virtualenv - the "--user" option can therefore be safely ignored. --- bindings/python/setup.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bindings/python/setup.py b/bindings/python/setup.py index d9f15e10d0..c8bc6a0d7f 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -6,7 +6,6 @@ import stat import sys -from site import getusersitepackages from distutils import log from distutils import dir_util from distutils.command.build_clib import build_clib @@ -26,10 +25,14 @@ VERSION = '3.0.3' SYSTEM = sys.platform +# virtualenv breaks import, but get_python_lib() will work. +SITE_PACKAGES = os.path.join(get_python_lib(), "capstone") if "--user" in sys.argv: - SITE_PACKAGES = os.path.join(getusersitepackages(), "capstone") -else: - SITE_PACKAGES = os.path.join(get_python_lib(), "capstone") + try: + from site import getusersitepackages + SITE_PACKAGES = os.path.join(getusersitepackages(), "capstone") + except ImportError: + pass SETUP_DATA_FILES = [] From 6f1e543c53285940558893bc36b7ae56a00cfdb0 Mon Sep 17 00:00:00 2001 From: Alex Chernetz Date: Fri, 19 Jun 2015 23:20:27 -0700 Subject: [PATCH 2/2] [Python binding] Add capstone.egg-info to .gitignore This directory gets created if you install using pip in editable mode. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c38e5f84fa..bbe0c16cc6 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ # python bindings/python/build/ +bindings/python/capstone.egg-info/ *.pyc # java