From 7852634ffa8024401f8f0830625d208635a69def Mon Sep 17 00:00:00 2001 From: Thomas Ferreira de Lima Date: Mon, 8 Oct 2018 03:07:52 -0400 Subject: [PATCH 1/3] bugfix for setup.py sdist --- MANIFEST.in | 11 +++++++++++ setup.py | 24 ++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000..8088e14c0 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,11 @@ +recursive-include src/tl/tl *.cc *.h +recursive-include src/db/db *.cc *.h +recursive-include src/gsi/gsi *.cc *.h +recursive-include src/rdb/rdb *.cc *.h +recursive-include src/pya/pya *.cc *.h +recursive-include src/pymod *.cc *.h +include src/plugins/*/db_plugin/*.cc +include src/plugins/*/*/db_plugin/*.cc +include src/plugins/*/db_plugin/*.h +include src/plugins/*/*/db_plugin/*.h +recursive-include src/plugins/common *.h diff --git a/setup.py b/setup.py index f7b4d2c44..d29d9d1a4 100644 --- a/setup.py +++ b/setup.py @@ -191,7 +191,7 @@ class Config(object): """ Gets the version string """ - return "0.26.0.dev1" + return "0.26.0.dev2" config = Config() @@ -201,13 +201,15 @@ config = Config() _tl_path = os.path.join("src", "tl", "tl") -_tl_sources = glob.glob(os.path.join(_tl_path, "*.cc")) +_tl_sources = set(glob.glob(os.path.join(_tl_path, "*.cc"))) # Exclude sources which are compatible with Qt only -_tl_sources.remove(os.path.join(_tl_path, "tlHttpStreamQt.cc")) -_tl_sources.remove(os.path.join(_tl_path, "tlHttpStreamNoQt.cc")) -_tl_sources.remove(os.path.join(_tl_path, "tlFileSystemWatcher.cc")) -_tl_sources.remove(os.path.join(_tl_path, "tlDeferredExecutionQt.cc")) +# Caveat, in source distribution tarballs from pypi, these files will +# not exist. So we need an error-free discard method instead of list's remove. +_tl_sources.discard(os.path.join(_tl_path, "tlHttpStreamQt.cc")) +_tl_sources.discard(os.path.join(_tl_path, "tlHttpStreamNoQt.cc")) +_tl_sources.discard(os.path.join(_tl_path, "tlFileSystemWatcher.cc")) +_tl_sources.discard(os.path.join(_tl_path, "tlDeferredExecutionQt.cc")) _tl = Extension(config.root + '._tl', define_macros=config.macros() + [('MAKE_TL_LIBRARY', 1)], @@ -215,7 +217,7 @@ _tl = Extension(config.root + '._tl', libraries=['curl', 'expat'], extra_link_args=config.link_args('_tl'), extra_compile_args=config.compile_args('_tl'), - sources=_tl_sources) + sources=list(_tl_sources)) # ------------------------------------------------------------------ # _gsi dependency library @@ -249,10 +251,12 @@ _pya = Extension(config.root + '._pya', # _db dependency library _db_path = os.path.join("src", "db", "db") -_db_sources = glob.glob(os.path.join(_db_path, "*.cc")) +_db_sources = set(glob.glob(os.path.join(_db_path, "*.cc"))) # Not a real source: -_db_sources.remove(os.path.join(_db_path, "fonts.cc")) +# Caveat, in source distribution tarballs from pypi, these files will +# not exist. So we need an error-free discard method instead of list's remove. +_db_sources.discard(os.path.join(_db_path, "fonts.cc")) _db = Extension(config.root + '._db', define_macros=config.macros() + [('MAKE_DB_LIBRARY', 1)], @@ -261,7 +265,7 @@ _db = Extension(config.root + '._db', language='c++', extra_link_args=config.link_args('_db'), extra_compile_args=config.compile_args('_db'), - sources=_db_sources) + sources=list(_db_sources)) # ------------------------------------------------------------------ # _rdb dependency library 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 2/3] 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') From c78c2a02286ac60c2114e1cba00f736d00708ef7 Mon Sep 17 00:00:00 2001 From: Thomas Ferreira de Lima Date: Tue, 9 Oct 2018 18:00:38 -0400 Subject: [PATCH 3/3] unit-testing pymod with tl, rdb, and db (+plugins) tests --- .travis.yml | 2 +- test-klayout-db-plugins.py | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 test-klayout-db-plugins.py diff --git a/.travis.yml b/.travis.yml index a70551b6f..036ea13b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -232,7 +232,7 @@ script: python setup.py build; python setup.py bdist_wheel; python setup.py install; - python test-klayout-db-plugins.py; + python -m unittest testdata/pymod/import_db.py testdata/pymod/import_rdb.py testdata/pymod/import_tl.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/test-klayout-db-plugins.py b/test-klayout-db-plugins.py deleted file mode 100644 index ab05fdea0..000000000 --- a/test-klayout-db-plugins.py +++ /dev/null @@ -1,13 +0,0 @@ -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')