]> hydra-www.ietfng.org Git - dyna2/commitdiff
Each Interpreters now has a workspace `~/.dyna/tmp/$PID`. This directory is for
authorTim Vieira <tim.f.vieira@gmail.com>
Sat, 29 Jun 2013 05:00:59 +0000 (01:00 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Sat, 29 Jun 2013 05:00:59 +0000 (01:00 -0400)
any files used by the code generator, REPL, etc.

README.md
src/Dyna/Backend/Python/errors.py
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/utils.py

index b5014eeed2a3ee0d4e790237058c78537fc30a08..1cbbeb06d0947b044eaea8a238320478bbafed33 100644 (file)
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ The python modules required
 
 Optionally, installing the following will enable certain extension
 
-    $ easy_install pygments matplotlib numpy ipython
+    $ easy_install pygments matplotlib numpy
     $ apt-get install graphviz
 
 Now you're ready to build.
index 973f3bd042162f15bee0a6a889b1e23bb2d04281..d7ac76d5814e8dfb616eb4129a999db2e1da75ff 100644 (file)
@@ -12,17 +12,13 @@ class DynaInitializerException(Exception):
     def __init__(self, exception, init):
         rule = parse_attrs(init)['rule']
         span = parse_attrs(init)['Span']
-
         if span.startswith(dotdynadir / 'tmp'):
             # don't show users tmp files create by the repl.
             msg = '%r in ininitializer for rule\n    %s' % \
                 (exception, rule)
-
         else:
             msg = '%r in ininitializer for rule\n  %s\n        %s' % \
-                (exception,
-                 span,
-                 rule)
+                (exception, span, rule)
         super(DynaInitializerException, self).__init__(msg)
 
 
index b268de31e08135830d9fb4cfed263f4e9011b948..f5fc997c6173fbcec49640884aeebb83c38a0dd1 100644 (file)
@@ -174,6 +174,8 @@ def none():
     return None
 
 
+import os
+
 class Interpreter(object):
 
     def __init__(self):
@@ -192,6 +194,12 @@ class Interpreter(object):
 
         self.files = []
 
+        # interpretor needs a place for it's temporary files.
+        self.tmp = tmp = (dotdynadir / 'tmp' / str(os.getpid()))
+        if tmp.exists():
+            tmp.rmtree()
+        tmp.makedirs_p()
+
     def __getstate__(self):
         return ((self.chart,
                  self.agenda,
@@ -488,13 +496,6 @@ class Interpreter(object):
             raise DynaInitializerException(e, init)
 
         else:
-
-            # TODO: how do I make this transactional? what if the user hits ^C
-            # in the middle of the following blocK?
-            #
-            #  - maybe transaction isn't want I mean. Maybe all I want (for now
-            #    is to avoid ^C.
-
             for fn, r, h in env.updaters:
                 self.new_updater(fn, r, h)
             for r, h in env.initializers:
@@ -514,10 +515,15 @@ class Interpreter(object):
 
         return self.go()
 
-    def dynac(self, filename, out=None):
+    def dynac(self, filename):
+        filename = path(filename)
         self.files.append(filename)
-        out = dynac(filename, out)
+
+        out = self.tmp / filename.read_hexhash('sha1') + '.plan.py'
+
+        dynac(filename, out)
         self.files.append(out)
+        return out
 
     def dynac_code(self, code):
         """
@@ -529,18 +535,13 @@ class Interpreter(object):
         x.update(self.parser_state)
         x.update(code)
 
-        dyna = dotdynadir / 'tmp' / ('%s.dyna' % x.hexdigest())
-        dyna.dirname().mkdir_p()  # make necessary directories
-
-        out = '%s.plan.py' % dyna
+        dyna = self.tmp / ('%s.dyna' % x.hexdigest())
 
         with file(dyna, 'wb') as f:
             f.write(self.parser_state)  # include parser state if any.
             f.write(code)
 
-        self.dynac(dyna, out)   # might raise compiler error
-
-        return out
+        return self.dynac(dyna)
 
 
 def peel(fn, item):
@@ -590,16 +591,7 @@ def main():
 
 #    def pickle_interp():
 #        import subprocess
-#
-#        crash = dotdynadir / 'crash'
-#        crash.rmtree(ignore_errors=False)
-#        crash.mkdir_p()
-#
-#        for f in [dotdynadir / 'crash.log'] + interp.files:
-#            path(f).copy(crash)
-#
-#        subprocess.Popen(['tar', 'czf', dotdynadir / 'crash.tar.gz', crash])
-#
+#        subprocess.Popen(['tar', 'czf', dotdynadir / 'crash.tar.gz', dotdynadir])
 #    crash_handler.interp = pickle_interp
 
 
@@ -610,10 +602,14 @@ def main():
             return
 
         if args.plan:
-            plan = args.source
+            # copy plan to tmp directory
+            plan = tmp / args.source.read_hexhash('sha1') + '.plan.py'
+            args.source.copy(plan)
+
         else:
-            plan = args.source + '.plan.py'
-            interp.dynac(args.source, plan)
+            #plan = args.source + '.plan.py'
+            #interp.dynac(args.source, plan)
+            plan = interp.dynac(args.source)
 
         if args.profile:
             # When profiling, its common practice to disable the garbage collector.
index 4f6586274e61b1179802a3ded9ddc94f5b129158..958f4abd942ae93eca8eb9b59ead0f8d9ddf9393 100644 (file)
@@ -46,7 +46,7 @@ def strip_comments(src):
     return _comments.sub('', src).strip()
 
 
-def dynac(f, out=None, anf=None, compiler_args=()):
+def dynac(f, out, anf=None, compiler_args=()):
     """
     Run compiler on file, ``f``, write results to ``out``. Raises
     ``DynaCompilerError`` on failure.
@@ -57,9 +57,6 @@ def dynac(f, out=None, anf=None, compiler_args=()):
     if not f.exists():
         raise DynaCompilerError("File '%s' does not exist." % f)
 
-    if out is None:
-        out = dotdynadir / 'tmp' / f.read_hexhash('sha1') + '.plan.py'
-
     cmd = ['%s/dist/build/dyna/dyna' % dynahome,
            '-B', 'python', '-o', out, f]
 
@@ -77,7 +74,6 @@ def dynac(f, out=None, anf=None, compiler_args=()):
         assert not stdout.strip(), [stdout, stderr]
         raise DynaCompilerError(stderr)
 
-    return out
 
 
 def lexer(term):