diff --git a/README.rst b/README.rst index 6407c00ea820080f237311e5fa92f9ebc9a6678f..3c3989549295e33ca876229e08216c2a6756d6c9 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,11 @@ -========================== - Buildout Recipes for Bob -========================== +=================================== + Buildout Recipes for Bob Packages +=================================== This package contains a number of recipes to be used to build `Satellite -Packages <http://www.idiap.ch/software/bob/docs/releases/last/sphinx/html/OrganizeYourCode.html>`_ for `Bob <http://idiap.github.com/bob/>`_, a signal-processing and machine learning toolbox originally developed by the Biometrics Group at Idiap, in Switzerland. +Packages <http://www.idiap.ch/software/bob/docs/releases/last/sphinx/html/OrganizeYourCode.html>`_ for `Bob <http://idiap.github.com/bob/>`_, +a signal-processing and machine learning toolbox originally developed by the +Biometrics Group at Idiap, in Switzerland. .. note:: @@ -25,7 +27,8 @@ Supported Options verbose - If set, it will output the compilation commands while compiling the module. + If set, buildout it will output the compilation commands while compiling the + module. prefixes @@ -39,11 +42,13 @@ debug If set, the module will be compiled with debugging symbols and with optimization turned off. -flags +environ - Adds the given flags to ``CFLAGS`` and ``CXXFLAGS``. It can also be used to - set debugging or release options if you prefer. This list of flags has - priority over the ``debug`` settings. + The name of a section on your configuration file that contains the names and + values of environment variables that should be used through the build. This + section is named, by default, ``environ``. If a section named ``environ`` + exists, it is read and the environment variables are set **before** the + specified eggs are developed. Multi-Script Installer ---------------------- @@ -62,12 +67,9 @@ called ``eggs``, but that can be overriden locally. It generates these scripts: python A pre-configured python interpreter -ipython - Makes sure ipython is installed and ready for use. - -pylint - A code checker using PyLint will be created so you can check your code for - conformance. +gdb-python + A pre-configured python interpreter, prefixed with ``gdb`` to make debugging + easier. Use it like you use ``python``. nosetests A test runner called ``nosetests`` will be created on the bin directory of @@ -143,9 +145,9 @@ ipython This recipe generates an IPython interpreter on the binary directory. Extra options considered: ``interpreter``. -egg.scripts - This recipe generates only the scripts (and dependent scripts) for the - package. Extra options considered: ``dependent-scripts``. +gdb-python + This recipe generates a gdb launcher using the python interpreter so you can + start your scripts directly typing ``gdb-python myscript.py``. pylint No extra options for this recipe. @@ -158,6 +160,6 @@ sphinx This recipe generates only the Sphinx documentation generator applications. Extra options considered: none. -gdb-python - This recipe generates a gdb launcher using the python interpreter so you can - start your scripts directly typing ``gdb-python myscript.py``. +egg.scripts + This recipe generates only the scripts (and dependent scripts) for the + package. Extra options considered: ``dependent-scripts``. diff --git a/xbob/buildout/envwrapper.py b/xbob/buildout/envwrapper.py index a47a5cd5e52569fbe20bc20c08f7fef52bd66af0..49394838270c25f39333ce8da3ad198407bb9e8c 100644 --- a/xbob/buildout/envwrapper.py +++ b/xbob/buildout/envwrapper.py @@ -7,80 +7,74 @@ """ import os +import string import logging -from . import tools + +def substitute(value, d): + """Substitutes ${} expressions on ``value`` with values from ``d``, using + string.Template""" + + return string.Template(value).substitute(**d) class EnvironmentWrapper(object): """Provides methods for wrapping other install() methods with environment settings from initialization. """ - def __init__(self, logger, debug, prefixes, flags=None): + DEBUG_FLAGS = '-O0 -g' + RELEASE_FLAGS = '-O3' - self.debug = debug - self.logger = logger - self.flags = ' '.join(flags) if flags else '' + def __init__(self, logger, debug=None, prefixes=None, environ=None): - # set the pkg-config paths to look at - pkgcfg = [os.path.join(k, 'lib', 'pkgconfig') for k in prefixes] + self.debug = debug + self.environ = dict(environ) if environ else {} + + # do environment variable substitution on user dictionary + for key in self.environ: + self.environ[key] = substitute(self.environ[key], self.environ) + + # if PKG_CONFIG_PATH is set on self.environ, then prefix it + pkgcfg = [] + if 'PKG_CONFIG_PATH' in self.environ: + pkgcfg += self.environ['PKG_CONFIG_PATH'].split(os.pathsep) + + # set the pkg-config paths to look at, environment settings in front + prefixes = prefixes if prefixes else [] + if 'XBOB_PREFIX_PATH' in self.environ: + prefixes = self.environ['XBOB_PREFIX_PATH'].split(os.pathsep) + prefixes + pkgcfg += [os.path.join(k, 'lib', 'pkgconfig') for k in prefixes] pkgcfg += [os.path.join(k, 'lib64', 'pkgconfig') for k in prefixes] pkgcfg += [os.path.join(k, 'lib32', 'pkgconfig') for k in prefixes] - self.pkgcfg = [os.path.abspath(k) for k in pkgcfg if os.path.exists(k)] - - def set(self): - """Sets the current environment for variables needed for the setup of the - package to be compiled""" - - self._saved_environment = {} - if self.pkgcfg: + # joins all paths + if prefixes: + self.environ['XBOB_PREFIX_PATH'] = os.pathsep.join(prefixes) + if pkgcfg: + self.environ['PKG_CONFIG_PATH'] = os.pathsep.join(pkgcfg) - self._saved_environment['PKG_CONFIG_PATH'] = os.environ.get('PKG_CONFIG_PATH', None) + # reset the CFLAGS and CXXFLAGS depending on the user input + cflags = None + if self.debug is True: cflags = str(EnvironmentWrapper.DEBUG_FLAGS) + elif self.debug is False: cflags = str(EnvironmentWrapper.RELEASE_FLAGS) + # else: pass - tools.prepend_env_paths('PKG_CONFIG_PATH', self.pkgcfg) - for k in reversed(self.pkgcfg): - self.logger.info("Adding pkg-config path '%s'" % k) + if cflags: + self.environ['CFLAGS'] = cflags + ' ' + self.environ.get('CFLAGS', '') + self.environ['CFLAGS'] = self.environ['CFLAGS'].strip() #clean-up + self.environ['CXXFLAGS'] = cflags + ' ' + self.environ.get('CXXFLAGS', '') + self.environ['CXXFLAGS'] = self.environ['CXXFLAGS'].strip() #clean-up - self.logger.debug('PKG_CONFIG_PATH=%s' % os.environ['PKG_CONFIG_PATH']) - - if 'CFLAGS' in os.environ: - self._saved_environment['CFLAGS'] = os.environ['CFLAGS'] - else: - self._saved_environment['CFLAGS'] = None - - if 'CXXFLAGS' in os.environ: - self._saved_environment['CXXFLAGS'] = os.environ['CXXFLAGS'] - else: - self._saved_environment['CXXFLAGS'] = None - - if self.debug: - # Disables optimization, enable debug symbols - flags = '-O0 -g' - self.logger.info("Setting debug build options") - - else: - # Disables debug symbols, enable extra optimizations - flags = '-O3 -g0' - self.logger.info("Setting release build options") - - if self.flags: - flags += ' ' + self.flags - self.logger.info("Setting user build options (%s)" % (self.flags,)) - - tools.append_environ_flags(flags, 'CFLAGS') - self.logger.debug('CFLAGS=%s' % os.environ['CFLAGS']) + def set(self): + """Sets the current environment for variables needed for the setup of the + package to be compiled""" - tools.append_environ_flags(flags, 'CXXFLAGS') - self.logger.debug('CXXFLAGS=%s' % os.environ['CXXFLAGS']) + self._saved_environment = dict(os.environ) #copy + os.environ.update(self.environ) def unset(self): """Resets the environment back to its previous state""" - for key in self._saved_environment: - if self._saved_environment[key] is None: - try: - del os.environ[key] - except KeyError: - pass - else: - os.environ[key] = self._saved_environment[key] + # cleanup + if self._saved_environment: + os.environ = self._saved_environment + self._saved_environment = {} diff --git a/xbob/buildout/extension.py b/xbob/buildout/extension.py index aad8a1f568c2ef8810ec4eaf65a17003ebdad4ae..9f6d1d557533893606938a9dba822a8694032ac3 100644 --- a/xbob/buildout/extension.py +++ b/xbob/buildout/extension.py @@ -47,12 +47,16 @@ class Extension: prefixes = tools.parse_list(buildout['buildout'].get('prefixes', '')) # shall we compile in debug mode? - debug = bool_option(self.buildout['buildout'], 'debug', 'false') + debug = self.buildout['buildout'].get('debug', None) + if isinstance(debug, str): + debug = bool_option(self.buildout['buildout'], 'debug', 'false') - # gets list of flags - flags = tools.parse_list(buildout['buildout'].get('flags', '')) + # has the user established an enviroment? + environ_section = self.buildout['buildout'].get('environ', 'environ') + environ = self.buildout.get(environ_section, {}) - self.envwrapper = EnvironmentWrapper(logger, debug, prefixes, flags) + # finally builds the environment wrapper + self.envwrapper = EnvironmentWrapper(logger, debug, prefixes, environ) def develop(self, setup, dest, build_ext=None, executable=sys.executable): diff --git a/xbob/buildout/scripts.py b/xbob/buildout/scripts.py index 2a4f4d32f819e0fdf5dd3818813bbd08ce26bf6c..b16af17dbb8697386783da8b7524a2b9fa539063 100644 --- a/xbob/buildout/scripts.py +++ b/xbob/buildout/scripts.py @@ -188,8 +188,6 @@ class Recipe(object): self.python = PythonInterpreter(buildout, 'Python', options.copy()) self.gdbpy = GdbPythonInterpreter(buildout, 'GdbPython', options.copy()) self.scripts = UserScripts(buildout, 'Scripts', options.copy()) - self.ipython = IPythonInterpreter(buildout, 'IPython', options.copy()) - self.pylint = PyLint(buildout, 'PyLint', options.copy()) self.nose = NoseTests(buildout, 'Nose', options.copy()) self.sphinx = Sphinx(buildout, 'Sphinx', options.copy())