Bugfix: db_plugin modules were not loaded for python modules

* Added unit test for this
* Provided an option for easier debugging such issues:
  Setting env var KLAYOUT_VERBOSITY will enable debug levels on Python
  modules (and all other binaries). Plugin loading issues can
  be debugged by setting KLAYOUT_VERBOSITY=21.
This commit is contained in:
Matthias Koefferlein 2018-07-15 14:14:14 +02:00
parent c4351185b1
commit fc9783432b
4 changed files with 64 additions and 4 deletions

View File

@ -22,7 +22,15 @@
#include "../pymodHelper.h"
#include "../../db/db/dbInit.h"
// to force linking of the db module
#include "../../db/db/dbForceLink.h"
DEFINE_PYMOD(db, "db", "KLayout core module 'db'")
static PyObject *db_module_init (const char *mod_name, const char *mod_description)
{
db::init ();
return module_init (mod_name, mod_description);
}
DEFINE_PYMOD_WITH_INIT(db, "db", "KLayout core module 'db'", db_module_init)

View File

@ -70,6 +70,14 @@ module_init (const char *mod_name, const char *mod_description)
module_init (__name_str__, __description__); \
} \
#define DEFINE_PYMOD_WITH_INIT(__name__, __name_str__, __description__, __init__) \
extern "C" \
DEF_INSIDE_PUBLIC \
void init##__name__ () \
{ \
__init__ (__name_str__, __description__); \
} \
#else
#define DEFINE_PYMOD(__name__, __name_str__, __description__) \
@ -80,5 +88,13 @@ module_init (const char *mod_name, const char *mod_description)
return module_init (__name_str__, __description__); \
} \
#define DEFINE_PYMOD_WITH_INIT(__name__, __name_str__, __description__, __init__) \
extern "C" \
DEF_INSIDE_PUBLIC \
PyObject *PyInit_##__name__ () \
{ \
return __init__ (__name_str__, __description__); \
} \
#endif

View File

@ -21,19 +21,48 @@
*/
#include <stdio.h>
#include "tlLog.h"
#include "tlString.h"
#include <stdio.h>
#include <unistd.h>
#if defined(_WIN32)
# include <windows.h>
#endif
namespace tl
{
// ------------------------------------------------
// Verbosity implementation
static int m_verbosity_level = 0;
static int default_verbosity ()
{
const char *verbosity_str = 0;
#if defined(_WIN32)
const wchar_t *verbosity_wstr = _wgetenv (L"KLAYOUT_VERBOSITY"));
std::string vs;
if (verbosity_wstr) {
vs = tl::to_string (std::wstring (verbosity_wstr));
verbosity_str = vs.c_str ();
}
#else
verbosity_str = getenv ("KLAYOUT_VERBOSITY");
#endif
int verbosity = 0;
if (verbosity_str) {
try {
tl::from_string (verbosity_str, verbosity);
} catch (...) {
}
}
return verbosity;
}
static int m_verbosity_level = default_verbosity ();
void
verbosity (int level)

View File

@ -19,6 +19,7 @@
import klayout.db as db
import unittest
import sys
import os
# Tests the basic abilities of the module
@ -34,6 +35,12 @@ class BasicTest(unittest.TestCase):
v = db.Box(1, 2, 3, 4)
self.assertEqual(str(v), "(1,2;3,4)")
def test_3(self):
# db plugins loaded?
v = db.Layout()
v.read(os.path.join(os.path.dirname(__file__), "..", "gds", "t10.gds"))
self.assertEqual(v.top_cell().name, "RINGO")
# run unit tests
if __name__ == '__main__':
suite = unittest.TestSuite()