From 40641209ee4013741d2755bb5a62514caf801a1b Mon Sep 17 00:00:00 2001 From: Al Date: Tue, 15 Dec 2015 12:19:40 -0500 Subject: [PATCH] [build] Build shared lib in site-packages --- setup.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index e5f38557..b357a263 100644 --- a/setup.py +++ b/setup.py @@ -13,17 +13,23 @@ SRC_DIR = 'src' this_dir = os.path.realpath(os.path.dirname(__file__)) virtualenv_path = os.environ.get('VIRTUAL_ENV') +site_packages_dir = None if virtualenv_path: virtualenv_path = os.path.abspath(virtualenv_path) + site_packages_dirs = [d for d in sys.path if d.startswith(virtualenv_path) and d.rstrip(os.sep).endswith('site-packages')] + if site_packages_dirs: + site_packages_dir = site_packages_dirs[0] -def build_dependencies(data_dir=None, prefix=None): +def build_dependencies(data_dir=None, prefix=None, lib_dir=None): subprocess.check_call(['sh', os.path.join(this_dir, 'bootstrap.sh')]) configure_command = ['sh', os.path.join(this_dir, 'configure')] if data_dir: configure_command.append('--datadir={}'.format(data_dir)) if prefix: configure_command.append('--prefix={}'.format(prefix)) + if lib_dir: + configure_command.append('--libdir={}'.format(lib_dir)) subprocess.check_call(configure_command) subprocess.check_call(['make', 'install']) @@ -46,6 +52,7 @@ class InstallWithDependencies(install): user_options = install.user_options + [ ('datadir=', None, 'Data directory for libpostal models'), ('prefix=', None, 'Install prefix for libpostal'), + ('libdir=', None, 'lib directory for libpostal') ] def initialize_options(self): @@ -57,7 +64,7 @@ class InstallWithDependencies(install): self.prefix = get_prefix_path(self.prefix) if self.prefix is not None and not os.path.exists(self.prefix): - os.mkdir(self.prefix) + os.mkdir(self.prefix) if self.datadir is None and self.prefix: self.datadir = os.path.join(self.prefix, 'data') @@ -66,10 +73,14 @@ class InstallWithDependencies(install): self.datadir = normalized_path(self.datadir) if not os.path.exists(self.datadir): os.mkdir(self.datadir) + + if self.libdir is None and site_packages_dir is not None: + self.libdir = site_packages_dir + install.finalize_options(self) def run(self): - build_dependencies(self.datadir, prefix=self.prefix) + build_dependencies(self.datadir, prefix=self.prefix, lib_dir=self.libdir) install.run(self)