[build] Build shared lib in site-packages

This commit is contained in:
Al
2015-12-15 12:19:40 -05:00
parent 04430f1a8e
commit 40641209ee

View File

@@ -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)