chiark / gitweb /
moedebug: switch to another new api (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Nov 2017 16:45:50 +0000 (16:45 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Nov 2017 16:45:52 +0000 (16:45 +0000)
assigning to a module global from outside the module does not work

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
gensymbolic
moedebug.py
symbolic.py

index 0ab8269e419931b8111c83a46a19f1cecf414182..6506777536886e323eb316da02f7c5c33f2607c5 100755 (executable)
@@ -6,7 +6,7 @@ from optparse import OptionParser
 import sympy
 
 import symbolic
-from moedebug import dbg_file, dbg
+from moedebug import *
 
 opt_parser = OptionParser()
 opt_parser.add_option('-q',dest='quiet',action='store_true',
@@ -21,8 +21,8 @@ assert(not len(args))
 if (not options.ascii) and sys.stdout.encoding is None:
   sys.stdout = codecs.open("/dev/stdout", "w", 'utf-8')
 
-dbg_file = None if options.quiet else sys.stdout
-if dbg_file:
+if not options.quiet: dbg_file(sys.stdout)
+if dbg_enabled():
   sympy.init_printing(use_unicode=(not options.ascii),
                       num_columns=options.width)
 
index ac9caeb81c0385f79939017f7d6ea366139a6345..d4774f9044fcfb4676f32d7af8a2fd390a813fa5 100644 (file)
@@ -1,7 +1,14 @@
 
-dbg_file = None
 
-def dbg(*args):
-  if dbg_file:
-    print('D ', *args, file=dbg_file)
+_files = []
+
+def dbg_file(f):
+  _files.append(f)
 
+def dbg_enabled():
+  return not not _files
+
+def dbg(*args):
+  for f in _files:
+    print('// D ', *args, file=f)
+    f.flush()
index 0f2ff03ab162e65919511dd28fd1ae1db6eccbad..3d17dcbb67f9c2b581e867088ae6513a6e3351a1 100644 (file)
@@ -2,7 +2,7 @@
 from sympy import *
 import itertools
 
-from moedebug import dbg_file
+from moedebug import *
 
 from sympy.utilities.lambdify import lambdify, implemented_function
 
@@ -12,11 +12,11 @@ r, theta, s, la, mu, kappa = symbols('r theta s lambda mu kappa')
 # rightvars  replaces 
 
 def dprint(*args):
-  if not dbg_file: return
+  if not dbg_enabled(): return
   print(*args)
 
 def dbg(*args):
-  if not dbg_file: return
+  if not dbg_enabled(): return
   for vn in args:
     print('\n    ' + vn + '\n')
     pprint(eval(vn))