From 61a61a2a5aefe9d9906195acf8f8492e633e7548 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 3 Apr 2019 01:07:22 +0200 Subject: [PATCH 1/2] WIP: added lib module to qmake-based python module build This works: import klayout.db import klayout.lib print(klayout.db.Library.library_names()) # says ["Basic"] Also works: from klayout import * Does not work: # import klayout.lib needs to be done before the libraries # are used initially import klayout.db print(klayout.db.Library.library_names()) # says [] import klayout.lib print(klayout.db.Library.library_names()) # says [] --- setup.py | 31 ++++++++++++++++- src/pymod/__init__.py.noqt | 2 +- src/pymod/__init__.py.qt4 | 2 +- src/pymod/__init__.py.qt5 | 2 +- src/pymod/__init__.py.qtless | 2 +- .../distutils_src/klayout/lib/__init__.py | 4 +++ src/pymod/distutils_src/pya/__init__.py | 1 + src/pymod/lib/lib.pro | 13 ++++++++ src/pymod/lib/libMain.cc | 33 +++++++++++++++++++ src/pymod/pymod.pro | 1 + 10 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 src/pymod/distutils_src/klayout/lib/__init__.py create mode 100644 src/pymod/lib/lib.pro create mode 100644 src/pymod/lib/libMain.cc diff --git a/setup.py b/setup.py index df4c6a573..df9715931 100644 --- a/setup.py +++ b/setup.py @@ -399,6 +399,22 @@ _db = Library(config.root + '._db', sources=list(_db_sources)) config.add_extension(_db) +# ------------------------------------------------------------------ +# _lib dependency library + +_lib_path = os.path.join("src", "lib", "lib") +_lib_sources = set(glob.glob(os.path.join(_lib_path, "*.cc"))) + +_lib = Library(config.root + '._lib', + define_macros=config.macros() + [('MAKE_LIB_LIBRARY', 1)], + include_dirs=[_tl_path, _db_path, _lib_path], + extra_objects=[config.path_of('_tl', _tl_path), config.path_of('_db', _db_path)], + language='c++', + extra_link_args=config.link_args('_lib'), + extra_compile_args=config.compile_args('_lib'), + sources=list(_lib_sources)) +config.add_extension(_lib) + # ------------------------------------------------------------------ # _rdb dependency library @@ -468,6 +484,19 @@ db = Extension(config.root + '.dbcore', extra_link_args=config.link_args('dbcore'), sources=list(db_sources)) +# ------------------------------------------------------------------ +# lib extension library + +lib_path = os.path.join("src", "pymod", "lib") +lib_sources = set(glob.glob(os.path.join(lib_path, "*.cc"))) + +lib = Extension(config.root + '.libcore', + define_macros=config.macros(), + include_dirs=[_lib_path, _tl_path, _db_path], + extra_objects=[config.path_of('_lib', _lib_path), config.path_of('_tl', _tl_path), config.path_of('_db', _db_path)], + extra_link_args=config.link_args('libcore'), + sources=list(lib_sources)) + # ------------------------------------------------------------------ # rdb extension library @@ -507,4 +536,4 @@ if __name__ == '__main__': url='https://github.com/klayoutmatthias/klayout', packages=find_packages('src/pymod/distutils_src'), package_dir={'': 'src/pymod/distutils_src'}, # https://github.com/pypa/setuptools/issues/230 - ext_modules=[_tl, _gsi, _pya, _db, _rdb] + db_plugins + [tl, db, rdb]) + ext_modules=[_tl, _gsi, _pya, _db, _lib, _rdb] + db_plugins + [tl, db, lib, rdb]) diff --git a/src/pymod/__init__.py.noqt b/src/pymod/__init__.py.noqt index dce96f8e4..4213afffb 100644 --- a/src/pymod/__init__.py.noqt +++ b/src/pymod/__init__.py.noqt @@ -1,5 +1,5 @@ # klayout library definition file -__all__ = [ "tl", "db", "lay", "rdb" ] +__all__ = [ "tl", "db", "lib", "lay", "rdb" ] diff --git a/src/pymod/__init__.py.qt4 b/src/pymod/__init__.py.qt4 index 18e5d527d..1404dbe71 100644 --- a/src/pymod/__init__.py.qt4 +++ b/src/pymod/__init__.py.qt4 @@ -1,5 +1,5 @@ # klayout library definition file -__all__ = [ "tl", "db", "rdb", "QtCore", "QtGui", "QtXml", "QtSql", "QtNetwork", "QtDesigner", "lay" ] +__all__ = [ "tl", "db", "lib", "rdb", "QtCore", "QtGui", "QtXml", "QtSql", "QtNetwork", "QtDesigner", "lay" ] diff --git a/src/pymod/__init__.py.qt5 b/src/pymod/__init__.py.qt5 index 9a943103f..6077d2f06 100644 --- a/src/pymod/__init__.py.qt5 +++ b/src/pymod/__init__.py.qt5 @@ -1,7 +1,7 @@ # klayout library definition file -__all__ = [ "tl", "db", "rdb", +__all__ = [ "tl", "db", "lib", "rdb", "QtCore", "QtGui", "QtNetwork", "QtSql", "QtWidgets", "QtDesigner", "QtMultimedia", "QtPrintSupport", "QtSvg", "QtXmlPatterns", "QtXml", "lay" ] diff --git a/src/pymod/__init__.py.qtless b/src/pymod/__init__.py.qtless index 6aef40aa9..776d25ace 100644 --- a/src/pymod/__init__.py.qtless +++ b/src/pymod/__init__.py.qtless @@ -1,4 +1,4 @@ # klayout library definition file -__all__ = [ "tl", "db", "rdb" ] +__all__ = [ "tl", "db", "lib", "rdb" ] diff --git a/src/pymod/distutils_src/klayout/lib/__init__.py b/src/pymod/distutils_src/klayout/lib/__init__.py new file mode 100644 index 000000000..90fb8d3de --- /dev/null +++ b/src/pymod/distutils_src/klayout/lib/__init__.py @@ -0,0 +1,4 @@ +import klayout.libcore +from klayout.libcore import * + +__all__ = klayout.libcore.__all__ diff --git a/src/pymod/distutils_src/pya/__init__.py b/src/pymod/distutils_src/pya/__init__.py index 70e2f49b9..08879d72b 100644 --- a/src/pymod/distutils_src/pya/__init__.py +++ b/src/pymod/distutils_src/pya/__init__.py @@ -3,5 +3,6 @@ # TODO: We need a specification document explaining what should go into pya from klayout.db import * # noqa +from klayout.lib import * # noqa from klayout.tl import * # noqa from klayout.rdb import * # noqa diff --git a/src/pymod/lib/lib.pro b/src/pymod/lib/lib.pro new file mode 100644 index 000000000..f78877a69 --- /dev/null +++ b/src/pymod/lib/lib.pro @@ -0,0 +1,13 @@ + +TARGET = libcore +REALMODULE = lib + +include($$PWD/../pymod.pri) + +SOURCES = \ + libMain.cc \ + +HEADERS += \ + +LIBS += -lklayout_lib + diff --git a/src/pymod/lib/libMain.cc b/src/pymod/lib/libMain.cc new file mode 100644 index 000000000..2e1a1fb38 --- /dev/null +++ b/src/pymod/lib/libMain.cc @@ -0,0 +1,33 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2019 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "../pymodHelper.h" + +// to force linking of the lib module +#include "../../lib/lib/libForceLink.h" + +static PyObject *lib_module_init (const char *pymod_name, const char *mod_name, const char *mod_description) +{ + return module_init (pymod_name, mod_name, mod_description); +} + +DEFINE_PYMOD_WITH_INIT(libcore, "lib", "KLayout core module 'lib'", lib_module_init) diff --git a/src/pymod/pymod.pro b/src/pymod/pymod.pro index ba4300cea..3cd7e2fe6 100644 --- a/src/pymod/pymod.pro +++ b/src/pymod/pymod.pro @@ -4,6 +4,7 @@ SUBDIRS = \ db \ tl \ rdb \ + lib \ !equals(HAVE_QT, "0") { From 86447506fd3d1f874876ad34c94c88c8b208aacf Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 3 Apr 2019 18:31:05 +0200 Subject: [PATCH 2/2] Fixed #252 - updated setup.py and pipelines. --- .travis.yml | 2 ++ azure-pipelines.yml | 1 + setup.py | 10 +++++----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 81e8318ec..c8db3c5dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -555,6 +555,7 @@ script: python testdata/pymod/import_db.py; python testdata/pymod/import_rdb.py; python testdata/pymod/import_tl.py; + python testdata/pymod/import_lib.py; python testdata/pymod/pya_tests.py; fi fi @@ -565,6 +566,7 @@ script: python testdata/pymod/import_db.py; python testdata/pymod/import_rdb.py; python testdata/pymod/import_tl.py; + python testdata/pymod/import_lib.py; python testdata/pymod/pya_tests.py; klayout_version=$(python -c 'import setup; print(setup.Config().version())'); mkdir -p deploy/dist-pymod/$klayout_version; diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 28804a941..08804ca66 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -84,6 +84,7 @@ jobs: python testdata/pymod/import_db.py python testdata/pymod/import_rdb.py python testdata/pymod/import_tl.py + python testdata/pymod/import_lib.py python testdata/pymod/pya_tests.py displayName: 'Test KLayout pymod' diff --git a/setup.py b/setup.py index df9715931..3faaa0b7f 100644 --- a/setup.py +++ b/setup.py @@ -407,8 +407,8 @@ _lib_sources = set(glob.glob(os.path.join(_lib_path, "*.cc"))) _lib = Library(config.root + '._lib', define_macros=config.macros() + [('MAKE_LIB_LIBRARY', 1)], - include_dirs=[_tl_path, _db_path, _lib_path], - extra_objects=[config.path_of('_tl', _tl_path), config.path_of('_db', _db_path)], + include_dirs=[_tl_path, _gsi_path, _db_path, _lib_path], + extra_objects=[config.path_of('_tl', _tl_path), config.path_of('_gsi', _gsi_path), config.path_of('_db', _db_path)], language='c++', extra_link_args=config.link_args('_lib'), extra_compile_args=config.compile_args('_lib'), @@ -492,8 +492,8 @@ lib_sources = set(glob.glob(os.path.join(lib_path, "*.cc"))) lib = Extension(config.root + '.libcore', define_macros=config.macros(), - include_dirs=[_lib_path, _tl_path, _db_path], - extra_objects=[config.path_of('_lib', _lib_path), config.path_of('_tl', _tl_path), config.path_of('_db', _db_path)], + include_dirs=[_lib_path, _tl_path, _gsi_path, _pya_path], + extra_objects=[config.path_of('_lib', _lib_path), config.path_of('_tl', _tl_path), config.path_of('_gsi', _gsi_path), config.path_of('_pya', _pya_path)], extra_link_args=config.link_args('libcore'), sources=list(lib_sources)) @@ -506,7 +506,7 @@ rdb_sources = set(glob.glob(os.path.join(rdb_path, "*.cc"))) rdb = Extension(config.root + '.rdbcore', define_macros=config.macros(), - include_dirs=[_rdb_path, _db_path, _tl_path, _gsi_path, _pya_path], + include_dirs=[_rdb_path, _tl_path, _gsi_path, _pya_path], extra_objects=[config.path_of('_rdb', _rdb_path), config.path_of('_tl', _tl_path), config.path_of('_gsi', _gsi_path), config.path_of('_pya', _pya_path)], extra_link_args=config.link_args('rdbcore'), sources=list(rdb_sources))