From e7ebd88b2cdd0b3bf42888bcce46569e519aeee6 Mon Sep 17 00:00:00 2001 From: Thomas Ferreira de Lima Date: Tue, 9 Oct 2018 00:35:28 -0400 Subject: [PATCH] critical bugfix for pymod (db plugins failed to import) Cause: dbInit.cc:133 hardcodes the macos extension for shared libraries ('.dylib'), but setuptools builds it with '.so'. Current solution: Since the main build's qmake respects the dylib standard, I've adapted setuptools to use '.dylib'. --- .travis.yml | 1 + setup.py | 28 +++++++++++++++++++++++++--- test-klayout-db-plugins.py | 13 +++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test-klayout-db-plugins.py diff --git a/.travis.yml b/.travis.yml index 691fa5f30..a70551b6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -232,6 +232,7 @@ script: python setup.py build; python setup.py bdist_wheel; python setup.py install; + python test-klayout-db-plugins.py; mkdir -p deploy/dist-pymod; cp -a dist/* deploy/dist-pymod/; python -c 'import klayout.db as db; print(dir(db))'; diff --git a/setup.py b/setup.py index d29d9d1a4..a1f2c56e8 100644 --- a/setup.py +++ b/setup.py @@ -60,10 +60,10 @@ import os import platform import distutils.sysconfig as sysconfig from distutils.errors import CompileError +import distutils.command.build_ext import multiprocessing N_cores = multiprocessing.cpu_count() - # monkey-patch for parallel compilation # from https://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None): @@ -103,6 +103,24 @@ if sys.version_info[0] * 10 + sys.version_info[1] > 26: import distutils.ccompiler distutils.ccompiler.CCompiler.compile = parallelCCompile + +from distutils.command.build_ext import build_ext +_old_get_ext_filename = build_ext.get_ext_filename + + +def patched_get_ext_filename(self, ext_name): + r"""Convert the name of an extension (eg. "foo.bar") into the name + of the file from which it will be loaded (eg. "foo/bar.so", or + "foo\bar.pyd"). + """ + filename = _old_get_ext_filename(self, ext_name) + # Making sure this matches qmake's default extension .dylib, instead of .so + if platform.system() == "Darwin" and '_dbpi' in ext_name: + filename = filename.replace('.so', '.dylib') + return filename + + +distutils.command.build_ext.build_ext.get_ext_filename = patched_get_ext_filename # ---------------------------------------------------------------------------------------- @@ -121,6 +139,7 @@ class Config(object): self.build_platlib = build_cmd.build_platlib self.ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") + if self.ext_suffix is None: self.ext_suffix = ".so" @@ -131,7 +150,10 @@ class Config(object): Returns the library name for a given module The library name is usually decorated (i.e. "tl" -> "tl.cpython-35m-x86_64-linux-gnu.so"). """ - return mod + self.ext_suffix + ext_suffix = self.ext_suffix + if platform.system() == "Darwin" and '_dbpi' in mod: + ext_suffix = ext_suffix.replace('.so', '.dylib') + return mod + ext_suffix def path_of(self, mod): """ @@ -191,7 +213,7 @@ class Config(object): """ Gets the version string """ - return "0.26.0.dev2" + return "0.26.0.dev4" config = Config() diff --git a/test-klayout-db-plugins.py b/test-klayout-db-plugins.py new file mode 100644 index 000000000..ab05fdea0 --- /dev/null +++ b/test-klayout-db-plugins.py @@ -0,0 +1,13 @@ +import klayout.db as kdb + +layout = kdb.Layout() + +layer1 = layout.layer(kdb.LayerInfo('1/0')) + +TOP = layout.create_cell("TOP") + +box = kdb.DBox(kdb.DPoint(-4500, -4500), kdb.DPoint(4500, 4500)) + +TOP.shapes(layer1).insert(box) + +layout.write('test.gds')