Skip to content

Commit

Permalink
New options --evalfile, --delete-on-error
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Dec 6, 2016
1 parent 89beb89 commit cce8558
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
15 changes: 5 additions & 10 deletions smop/libscripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,22 @@ MFILES = $(shell find $(SCRIPTS) -name \*.m -type f)
CYTHON = cython
PYTHON = python
CAT = cat
XFILES = -x white.m,summer.m,spring.m,rainbow.m,prism.m,pink.m,ocean.m,lines.m,jet.m,__gnuplot_open_stream__.m
XFILES = -x fnmatch.m
FLAGS = -v
SMOP = $(PYTHON) ../main.py

V = 2.7

all: pyfiles
$(PYTHON) -m py_compile *.py
all:
$(SMOP) $(FLAGS) $(XFILES) $(MFILES)
rm -f libscripts.py
$(CAT) *.py > libscripts.py

regress:
$(SMOP) $(FLAGS) $(MFILES) | grep Error | wc

.PHONY: all pyfiles clean

pyfiles:
$(SMOP) $(FLAGS) $(MFILES)


wall: $(PYFILES)
$(CAT) *.py > libscripts.py

clean:
rm -f libscripts.py *.pyc *.py

Expand Down
9 changes: 7 additions & 2 deletions smop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ def main():
fp.write(s)
try:
py_compile.compile(f,doraise=True)
except py_compile.PyCompileError:
os.unlink(f)
if options.execfile:
execfile(f)
except:
if options.delete-on-error:
os.unlink(f)
if options.verbose:
print "Removed",f
raise
else:
fp.write(s)
Expand Down
28 changes: 28 additions & 0 deletions smop/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@

#parser.add_argument("--graphviz", action="store_true")

parser.add_argument("-D","--delete-on-error",
action="store_false",
help="""Borrowed from gnu make option of
the same name and functionality. After
translation to python, the resulting
py-files undergo two checks: (a) byte-
compilation using the standard py_compile
module. and (b) loading using the builtin
evalfile function. By default,
broken py-files are kept alive to allow
their examination and debugging.
$ smop -v --delete-on-error *.m
$ rm -f libscripts.py
$ cat *.py > libscripts.py
$ python
...
>>> from libscripts import *
>>> factorial(9)
362880.0
>>> primes(9)
Oops, wrong results.
""")

parser.add_argument("-H","--no-header",
action="store_true",
help="""use it if you plan to concatenate
Expand All @@ -130,6 +154,10 @@
action="store_true",
help="omit code generation")

parser.add_argument("-E","--execfile",
action="store_false",
help="""UNSAFE pass the py-file to execfile""")

parser.add_argument("-R","--no-resolve",
action="store_true",
help="omit name resolution")
Expand Down

0 comments on commit cce8558

Please sign in to comment.