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 []
This commit is contained in:
Matthias Koefferlein 2019-04-03 01:07:22 +02:00
parent e26b57ca2f
commit 61a61a2a5a
10 changed files with 86 additions and 5 deletions

View File

@ -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])

View File

@ -1,5 +1,5 @@
# klayout library definition file
__all__ = [ "tl", "db", "lay", "rdb" ]
__all__ = [ "tl", "db", "lib", "lay", "rdb" ]

View File

@ -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" ]

View File

@ -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" ]

View File

@ -1,4 +1,4 @@
# klayout library definition file
__all__ = [ "tl", "db", "rdb" ]
__all__ = [ "tl", "db", "lib", "rdb" ]

View File

@ -0,0 +1,4 @@
import klayout.libcore
from klayout.libcore import *
__all__ = klayout.libcore.__all__

View File

@ -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

13
src/pymod/lib/lib.pro Normal file
View File

@ -0,0 +1,13 @@
TARGET = libcore
REALMODULE = lib
include($$PWD/../pymod.pri)
SOURCES = \
libMain.cc \
HEADERS += \
LIBS += -lklayout_lib

33
src/pymod/lib/libMain.cc Normal file
View File

@ -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)

View File

@ -4,6 +4,7 @@ SUBDIRS = \
db \
tl \
rdb \
lib \
!equals(HAVE_QT, "0") {