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