[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.
This commit is contained in:
Alex Chernetz 2015-06-19 23:18:52 -07:00
parent 36d05945f9
commit 801178bea4
1 changed files with 7 additions and 4 deletions

View File

@ -6,7 +6,6 @@ import shutil
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 @@ if os.path.exists(PATH_LIB64) and os.path.exists(PATH_LIB32):
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 = []