Merge pull request #1973 from KLayout/feature/issue-1971

Feature/issue 1971
This commit is contained in:
Matthias Köfferlein 2025-01-17 10:10:19 +01:00 committed by GitHub
commit 253270aaa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 95 additions and 28 deletions

View File

@ -105,11 +105,14 @@ Class<Logger> decl_Logger ("tl", "Logger",
"Level 0 is silent, levels 10, 20, 30 etc. denote levels with increasing verbosity. "
"11, 21, 31 .. are sublevels which also enable timing logs in addition to messages."
) +
gsi::method ("verbosity=", &Logger::set_verbosity, gsi::arg ("v"),
gsi::method ("verbosity=|set_verbosity", &Logger::set_verbosity, gsi::arg ("v"),
"@brief Sets the verbosity level for the application\n"
"\n"
"See \\verbosity for a definition of the verbosity levels. Please note that this method "
"changes the verbosity level for the whole application.\n"
"\n"
"The 'set_verbosity' alias has been introduced in version 0.29.11 as class attributes "
"are not always available in Python."
),
"@brief A logger\n"
"\n"

View File

@ -375,6 +375,18 @@ A *A::a20_get ()
return a_inst.get ();
}
static int s_sp = 0;
int A::sp_i_get ()
{
return s_sp;
}
void A::sp_i_set (int v)
{
s_sp = v + 1;
}
// ----------------------------------------------------------------
// Implementation of B
@ -1253,6 +1265,8 @@ static gsi::Class<A> decl_a ("", "A",
gsi::method ("a9b", &A::a9b) +
gsi::method ("a20", &A::a20) +
gsi::method ("a20_get", &A::a20_get) +
gsi::method ("sp_i", &A::sp_i_get) +
gsi::method ("sp_i=", &A::sp_i_set) +
gsi::method ("to_s", &A::to_s) +
gsi::iterator ("a6", &A::a6b, &A::a6e) +
gsi::iterator ("a7", &A::a7b, &A::a7e) +

View File

@ -415,6 +415,10 @@ struct A
std::string to_s () const;
// static (class) properties
static int sp_i_get ();
static void sp_i_set (int v);
// members
std::vector<double> m_d;
int n;

View File

@ -1285,7 +1285,14 @@ property_setter_impl (int mid, PyObject *self, PyObject *value)
meth->call (obj, arglist, retlist);
return get_return_value (p, retlist, meth, heap);
PyObject *ret = get_return_value (p, retlist, meth, heap);
if (ret == NULL) {
Py_INCREF (Py_None);
ret = Py_None;
}
return ret;
}
}

View File

@ -426,7 +426,11 @@ public:
doc += "\n\n";
}
doc += (*m)->doc ();
if (! is_static) {
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a readable attribute '%s'. This is the getter")), name));
} else {
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The class exposes a readable attribute '%s'. This is the getter")), name));
}
}
for (MethodTableEntry::method_iterator m = begin_setters; m != end_setters; ++m) {
@ -434,7 +438,11 @@ public:
doc += "\n\n";
}
doc += (*m)->doc ();
if (! is_static) {
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a writable attribute '%s'. This is the setter")), name));
} else {
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The class exposes a writable attribute '%s'. This setter may not be available in Python")), name));
}
}
PythonRef attr;

View File

@ -392,28 +392,35 @@ WarningChannel::~WarningChannel ()
void
WarningChannel::puts (const char *s)
{
if (verbosity () >= 0) {
fputs (s, stdout);
}
}
void
WarningChannel::endl ()
{
if (verbosity () >= 0) {
fputs ("\n", stdout);
m_new_line = true;
}
}
void
WarningChannel::end ()
{
if (verbosity () >= 0) {
if (m_colorized) {
fputs (ANSI_RESET, stdout);
}
fflush (stdout);
}
}
void
WarningChannel::begin ()
{
if (verbosity () >= 0) {
if (m_colorized) {
fputs (ANSI_BLUE, stdout);
}
@ -422,6 +429,7 @@ WarningChannel::begin ()
m_new_line = false;
}
}
}
// ------------------------------------------------
@ -463,28 +471,35 @@ ErrorChannel::~ErrorChannel ()
void
ErrorChannel::puts (const char *s)
{
if (verbosity () >= -10) {
fputs (s, stderr);
}
}
void
ErrorChannel::endl ()
{
if (verbosity () >= -10) {
fputs ("\n", stderr);
m_new_line = true;
}
}
void
ErrorChannel::end ()
{
if (verbosity () >= -10) {
if (m_colorized) {
fputs (ANSI_RESET, stderr);
}
fflush (stderr);
}
}
void
ErrorChannel::begin ()
{
if (verbosity () >= -10) {
if (m_colorized) {
fputs (ANSI_RED, stderr);
}
@ -493,6 +508,7 @@ ErrorChannel::begin ()
m_new_line = false;
}
}
}
// ------------------------------------------------
// The instances of the log channels

View File

@ -149,6 +149,15 @@ class BasicTest(unittest.TestCase):
def test_00(self):
# does not work with all Python versions
# (debugging shows that Python calls the setter on the metaclass,
# not on the class itself at least on 3.12)
# # static (class) properties
# pya.A.sp_i = 17
# self.assertEqual(pya.A.sp_i, 18)
# pya.A.sp_i = -1
# self.assertEqual(pya.A.sp_i, 0)
# all references of PA are released now:
ic0 = pya.A.instance_count()

View File

@ -24,6 +24,12 @@ class Basic_TestClass < TestBase
# for testing the ut logger:
puts "Special chars: <&>"
# static (class) properties
RBA::A.sp_i = 17
assert_equal( RBA::A.sp_i, 18 )
RBA::A.sp_i = -1
assert_equal( RBA::A.sp_i, 0 )
GC.start
# all references of A are released now: