Skip to content

Commit

Permalink
Merge pull request #1973 from KLayout/feature/issue-1971
Browse files Browse the repository at this point in the history
Feature/issue 1971
  • Loading branch information
klayoutmatthias authored Jan 17, 2025
2 parents b4dc9a6 + a75eca5 commit 253270a
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 28 deletions.
5 changes: 4 additions & 1 deletion src/gsi/gsi/gsiDeclTl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions src/gsi/gsi_test/gsiTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) +
Expand Down
4 changes: 4 additions & 0 deletions src/gsi/gsi_test/gsiTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/pya/pya/pyaCallables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
}
Expand Down
12 changes: 10 additions & 2 deletions src/pya/pya/pyaModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,23 @@ class PythonClassGenerator
doc += "\n\n";
}
doc += (*m)->doc ();
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a readable attribute '%s'. This is the getter")), name));
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) {
if (! doc.empty ()) {
doc += "\n\n";
}
doc += (*m)->doc ();
mp_module->add_python_doc (*m, tl::sprintf (tl::to_string (tr ("The object exposes a writable attribute '%s'. This is the setter")), name));
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;
Expand Down
64 changes: 40 additions & 24 deletions src/tl/tl/tlLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,34 +392,42 @@ WarningChannel::~WarningChannel ()
void
WarningChannel::puts (const char *s)
{
fputs (s, stdout);
if (verbosity () >= 0) {
fputs (s, stdout);
}
}

void
WarningChannel::endl ()
{
fputs ("\n", stdout);
m_new_line = true;
if (verbosity () >= 0) {
fputs ("\n", stdout);
m_new_line = true;
}
}

void
WarningChannel::end ()
{
if (m_colorized) {
fputs (ANSI_RESET, stdout);
if (verbosity () >= 0) {
if (m_colorized) {
fputs (ANSI_RESET, stdout);
}
fflush (stdout);
}
fflush (stdout);
}

void
WarningChannel::begin ()
{
if (m_colorized) {
fputs (ANSI_BLUE, stdout);
}
if (m_new_line) {
fputs ("Warning: ", stdout);
m_new_line = false;
if (verbosity () >= 0) {
if (m_colorized) {
fputs (ANSI_BLUE, stdout);
}
if (m_new_line) {
fputs ("Warning: ", stdout);
m_new_line = false;
}
}
}

Expand Down Expand Up @@ -463,34 +471,42 @@ ErrorChannel::~ErrorChannel ()
void
ErrorChannel::puts (const char *s)
{
fputs (s, stderr);
if (verbosity () >= -10) {
fputs (s, stderr);
}
}

void
ErrorChannel::endl ()
{
fputs ("\n", stderr);
m_new_line = true;
if (verbosity () >= -10) {
fputs ("\n", stderr);
m_new_line = true;
}
}

void
ErrorChannel::end ()
{
if (m_colorized) {
fputs (ANSI_RESET, stderr);
if (verbosity () >= -10) {
if (m_colorized) {
fputs (ANSI_RESET, stderr);
}
fflush (stderr);
}
fflush (stderr);
}

void
ErrorChannel::begin ()
{
if (m_colorized) {
fputs (ANSI_RED, stderr);
}
if (m_new_line) {
fputs ("ERROR: ", stderr);
m_new_line = false;
if (verbosity () >= -10) {
if (m_colorized) {
fputs (ANSI_RED, stderr);
}
if (m_new_line) {
fputs ("ERROR: ", stderr);
m_new_line = false;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions testdata/python/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 6 additions & 0 deletions testdata/ruby/basic_testcore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def test_FIRST
# 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:
Expand Down

0 comments on commit 253270a

Please sign in to comment.