Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #335 from tango-controls/issue-300-310-libboost
Browse files Browse the repository at this point in the history
Generalise search for libboost_python on POSIX
  • Loading branch information
ajoubertza authored Mar 9, 2020
2 parents 3d478a8 + 000a3c3 commit e56888e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 52 deletions.
15 changes: 8 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ General dependencies:
Python dependencies:

- numpy_ >= 1.1
- six_
- six_ >= 1.10

Build dependencies:

Expand All @@ -51,7 +51,9 @@ Optional dependencies:

.. note:: As a general rule, libtango_ and pytango_ should share the same major
and minor version (for a version ``X.Y.Z``, ``X`` and ``Y`` should
match)
match).
On some systems you may need to install ``libtango``, ``omniORB4`` and ``libzmq`` related
development packages.


Install
Expand All @@ -70,9 +72,9 @@ In both cases, the installation takes a few minutes since the ``_tango`` boost
extension has to compile.

.. note::

On some systems you may need to install ``libtango``, ``omniORB4`` and ``libzmq`` related
developement packages.
For custom `Boost.Python`_ installation locations, environment variables can be used
to modify the default paths. See the description of the ``BOOST_ROOT`` and related
variables in the ``setup.py`` file.

Usage
-----
Expand All @@ -92,7 +94,6 @@ To test the installation, import ``tango`` and check ``tango.utils.info()``::
Python : 2.7.15
Numpy : 1.16.2
Tango : 9.3.3
Boost : 0.0.0

PyTango running on:
('Linux', 'hostname', '4.4.0-131-generic', '#157-Ubuntu SMP Sat Jul 27 06:00:36 UTC 2019', 'x86_64', 'x86_64')
Expand Down Expand Up @@ -149,7 +150,7 @@ All contributions, `PR and bug reports`_ are welcome, please see: `How to Contr
.. _PyPI: http://pypi.python.org/pypi/pytango

.. _libtango: http://tango-controls.org/downloads
.. _Boost.Python: http://boost.org/doc/libs/1_61_0/libs/python/doc/html
.. _Boost.Python: https://www.boost.org/doc/libs/release/libs/python/doc/html/index.html
.. _numpy: http://pypi.python.org/pypi/numpy
.. _six: http://pypi.python.org/pypi/six
.. _setuptools: http://pypi.python.org/pypi/setuptools
Expand Down
122 changes: 79 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import struct
import subprocess

from ctypes.util import find_library

from setuptools import setup, Extension
from setuptools import Command
from setuptools.command.build_ext import build_ext as dftbuild_ext
Expand All @@ -26,12 +28,6 @@
from distutils.unixccompiler import UnixCCompiler
from distutils.version import LooseVersion as V

# Distro import
try:
from pip._vendor import distro
except ImportError:
import platform as distro

# Sphinx imports
try:
import sphinx
Expand All @@ -55,14 +51,6 @@
PYTHON2 = (2,) <= PYTHON_VERSION < (3,)
PYTHON3 = (3,) <= PYTHON_VERSION < (4,)

# Linux distribution
distribution = distro.linux_distribution()[0].lower() if POSIX else ""
distribution_match = lambda names: any(x in distribution for x in names)
DEBIAN = distribution_match(['debian', 'ubuntu', 'mint'])
REDHAT = distribution_match(['redhat', 'fedora', 'centos', 'opensuse'])
GENTOO = distribution_match(['gentoo'])
CONDA = 'CONDA_PREFIX' in os.environ

# Arguments
TESTING = any(x in sys.argv for x in ['test', 'pytest'])

Expand Down Expand Up @@ -170,6 +158,82 @@ def add_lib(name, dirs, sys_libs,
dirs['libraries'].append(lib_name)


def add_lib_boost(dirs):
"""Add boost-python configuration details.
There are optional environment variables that can be used for
non-standard boost installations.
The BOOST_ROOT can be used for a custom boost installation in
a separate directory, like:
/opt/my_boost
|- include
|- lib
In this case, use:
BOOST_ROOT=/opt/my_boost
Alternatively, the header and library folders can be specified
individually (do not set BOOST_ROOT). For example, if the
python.hpp file is in /usr/local/include/boost123/boost/:
BOOST_HEADERS=/usr/local/include/boost123
If the libboost_python.so file is in /usr/local/lib/boost123:
BOOST_LIBRARIES=/usr/local/lib/boost123
Lastly, the boost-python library name can be specified, if the
automatic detection is not working. For example, if the
library is libboost_python_custom.so, then use:
BOOST_PYTHON_LIB=boost_python_custom
"""

BOOST_ROOT = os.environ.get('BOOST_ROOT')
BOOST_HEADERS = os.environ.get('BOOST_HEADERS')
BOOST_LIBRARIES = os.environ.get('BOOST_LIBRARIES')
BOOST_PYTHON_LIB = os.environ.get('BOOST_PYTHON_LIB')
boost_library_name = BOOST_PYTHON_LIB if BOOST_PYTHON_LIB else 'boost_python'
if BOOST_ROOT is None:
if POSIX and not BOOST_PYTHON_LIB:
# library name differs widely across distributions, so if it
# wasn't specified as an environment var, then try the
# various options, being as Python version specific as possible
suffixes = [
"{v[0]}{v[1]}".format(v=PYTHON_VERSION),
"-{v[0]}{v[1]}".format(v=PYTHON_VERSION),
"-py{v[0]}{v[1]}".format(v=PYTHON_VERSION),
"{v[0]}-py{v[0]}{v[1]}".format(v=PYTHON_VERSION),
"{v[0]}".format(v=PYTHON_VERSION),
""
]
for suffix in suffixes:
candidate = boost_library_name + suffix
if find_library(candidate):
boost_library_name = candidate
break
if BOOST_HEADERS:
dirs['include_dirs'].append(BOOST_HEADERS)
if BOOST_LIBRARIES:
dirs['library_dirs'].append(BOOST_LIBRARIES)
else:
inc_dir = os.path.join(BOOST_ROOT, 'include')
lib_dirs = [os.path.join(BOOST_ROOT, 'lib')]
if IS64:
lib64_dir = os.path.join(BOOST_ROOT, 'lib64')
if os.path.isdir(lib64_dir):
lib_dirs.insert(0, lib64_dir)

dirs['include_dirs'].append(inc_dir)
dirs['library_dirs'].extend(lib_dirs)

dirs['libraries'].append(boost_library_name)


class build(dftbuild):

user_options = list(dftbuild.user_options)
Expand Down Expand Up @@ -366,35 +430,7 @@ def setup_args():
add_lib('omni', directories, sys_libs, lib_name='omniORB4')
add_lib('zmq', directories, sys_libs, lib_name='libzmq')
add_lib('tango', directories, sys_libs, inc_suffix='tango')

# special boost-python configuration

BOOST_ROOT = os.environ.get('BOOST_ROOT')
boost_library_name = 'boost_python'
if BOOST_ROOT is None:
if CONDA:
suffix = ''
elif DEBIAN:
suffix = "-py{v[0]}{v[1]}".format(v=PYTHON_VERSION)
boost_library_name += suffix
elif REDHAT:
if PYTHON3:
boost_library_name += '3'
elif GENTOO:
suffix = "-{v[0]}.{v[1]}".format(v=PYTHON_VERSION)
boost_library_name += suffix
else:
inc_dir = os.path.join(BOOST_ROOT, 'include')
lib_dirs = [os.path.join(BOOST_ROOT, 'lib')]
if IS64:
lib64_dir = os.path.join(BOOST_ROOT, 'lib64')
if os.path.isdir(lib64_dir):
lib_dirs.insert(0, lib64_dir)

directories['include_dirs'].append(inc_dir)
directories['library_dirs'].extend(lib_dirs)

directories['libraries'].append(boost_library_name)
add_lib_boost(directories)

# special numpy configuration

Expand Down
1 change: 0 additions & 1 deletion tango/pytango_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class Compile(object):
class Runtime(object):
PY_VERSION = ".".join(map(str, sys.version_info[:3]))
TANGO_VERSION = tg_rt_ver
BOOST_VERSION = '0.0.0'
if constants.NUMPY_SUPPORT:
import numpy
NUMPY_VERSION = numpy.__version__
Expand Down
1 change: 0 additions & 1 deletion tango/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,6 @@ def info():
Python : {2.PY_VERSION}
Numpy : {2.NUMPY_VERSION}
Tango : {2.TANGO_VERSION}
Boost : {2.BOOST_VERSION}
PyTango running on:
{2.UNAME}
Expand Down

0 comments on commit e56888e

Please sign in to comment.