Commit 1da0b5e8 authored by André Anjos's avatar André Anjos 💬

Replace the use of string.maketrans with something that can also work with Python3

parent de834bdd
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <>
# Mon 28 Jan 2013 16:40:27 CET
# Mon 28 Jan 2013 16:40:27 CET
"""A custom build class for Bob/Python extensions
......@@ -92,8 +92,15 @@ def pkgconfig(package):
for k, v in kw.items(): # remove duplicated
kw[k] = uniq(v)
# Python 3 style
maketrans = ''.maketrans
except AttributeError:
# fallback for Python 2
from string import maketrans
# adds version and HAVE flags
PACKAGE = package.upper().translate(string.maketrans(" -", "__"))
PACKAGE = package.upper().translate(maketrans(" -", "__"))
kw['define_macros'] = [
('HAVE_%s' % PACKAGE, '1'),
('%s_VERSION' % PACKAGE, '"%s"' % version),
......@@ -110,28 +117,28 @@ def uniq(seq):
class Extension(ExtensionBase):
"""Extension building with Bob/Python bindings.
See the documentation for :py:class:`distutils.extension.Extension` for more
details on input parameters.
def __init__(self, *args, **kwargs):
"""Initialize the extension with parameters.
"""Initialize the extension with parameters.
Bob/Python adds a single parameter to the standard arguments of the
pkgconfig : [list]
This should be a list of strings indicating the name of the bob
(pkg-config) modules you would like to have linked to your extension
**additionally** to ``bob-python``. Candidates are module names like
"bob-machine" or "bob-math".
"bob-machine" or "bob-math".
For convenience, you can also specify "opencv" or other 'pkg-config'
registered packages as a dependencies.
modules = ['bob-python']
if 'pkgconfig' in kwargs and kwargs['pkgconfig']:
......@@ -170,7 +177,7 @@ class Extension(ExtensionBase):
# Filter and make unique
for key in parameters.keys():
parameters[key] = uniq(parameters[key])
# Tune input parameters if they were set
if key in kwargs: kwargs[key].extend(parameters[key])
else: kwargs[key] = parameters[key]
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment