From 50bac72278ff69c5c43f81a5e6632fb7239a5ab3 Mon Sep 17 00:00:00 2001 From: Sven on Sveinn Date: Fri, 2 May 2014 12:52:52 +0200 Subject: [PATCH 1/4] Correct escaping of filenames --- pyreport/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyreport/main.py b/pyreport/main.py index 65704bf..1df271f 100644 --- a/pyreport/main.py +++ b/pyreport/main.py @@ -511,10 +511,10 @@ def tex2pdf(filename, options): execute("dvips -E %s.dvi -o %s.eps" % (filename, filename)) elif options.outtype == "pdf": if HAVE_PDFLATEX: - execute( "pdflatex --interaction scrollmode %s.tex -output-directory=%s" %(filename, os.path.dirname(filename))) + execute( "pdflatex --interaction scrollmode '%s.tex' -output-directory='%s'" %(filename, os.path.dirname(filename))) else: - execute("latex --interaction scrollmode %s.tex -output-directory=%s" %(filename, os.path.dirname(filename))) - execute("dvips -E %s.dvi -o %s.eps" % (filename, filename)) + execute("latex --interaction scrollmode '%s.tex' -output-directory='%s'" %(filename, os.path.dirname(filename))) + execute("dvips -E '%s.dvi' -o '%s.eps'" % (filename, filename)) print "Doing pdf %s" % filename execute("epstopdf %s.eps" % filename) From 77c906fb84b757077b97d5c55e70d7c500cf5729 Mon Sep 17 00:00:00 2001 From: Sven on Sveinn Date: Fri, 2 May 2014 12:53:32 +0200 Subject: [PATCH 2/4] Perform latex integration multiple times. Actually, the return value of the latex evaluation should be checked in each go, or at least for the first run. --- pyreport/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyreport/main.py b/pyreport/main.py index 1df271f..6cd20aa 100644 --- a/pyreport/main.py +++ b/pyreport/main.py @@ -511,6 +511,8 @@ def tex2pdf(filename, options): execute("dvips -E %s.dvi -o %s.eps" % (filename, filename)) elif options.outtype == "pdf": if HAVE_PDFLATEX: + # Latex should be compiled multiple times for correct toc, links, tables, etc + execute( "pdflatex --interaction scrollmode '%s.tex' -output-directory='%s'" %(filename, os.path.dirname(filename))) execute( "pdflatex --interaction scrollmode '%s.tex' -output-directory='%s'" %(filename, os.path.dirname(filename))) else: execute("latex --interaction scrollmode '%s.tex' -output-directory='%s'" %(filename, os.path.dirname(filename))) From 06f20db6eeab874bc59488f19dff471652bc517e Mon Sep 17 00:00:00 2001 From: Sven on Sveinn Date: Mon, 26 May 2014 13:43:44 +0200 Subject: [PATCH 3/4] Bugfix: Pyreport crashes when the variable `token` is used anywhere in the python script for which the report has to be taken. I think this is a problem of the overall PyReport program, so basically all PyReport variables should have quite unique names, perhaps with an appropriate prefix. Relabeling the imported `token` module to `pytoken` solves it for my issue. --- pyreport/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyreport/main.py b/pyreport/main.py index 6cd20aa..be26df2 100644 --- a/pyreport/main.py +++ b/pyreport/main.py @@ -18,7 +18,7 @@ import __builtin__ # to override import ! :-> import platform import tokenize -import token +import token as pytoken # rename for when python target code uses "token" as variable # Local imports from options import allowed_types, default_options, HAVE_PDFLATEX, \ @@ -397,7 +397,7 @@ def py2commentblocks(string, firstlinenum, options): else: last_token = tokendesc[0] - tokentype = token.tok_name[tokendesc[0]] + tokentype = pytoken.tok_name[tokendesc[0]] startpos = tokendesc[2][1] tokencontent = tokendesc[1] if tokendesc[2][0] > linenum: From 8aba20f93b8e96b442f9cbd5088d36d4860c6ec2 Mon Sep 17 00:00:00 2001 From: Sven on Sveinn Date: Mon, 26 May 2014 15:26:21 +0200 Subject: [PATCH 4/4] Bugfix: Enable importing files in local directory. In Python, the directory of __FILE__, that is, the directory of the called python file, shall be in sys.path. This is fixed in this commit. --- pyreport/pyreport.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyreport/pyreport.py b/pyreport/pyreport.py index cd68ea8..9ed131a 100755 --- a/pyreport/pyreport.py +++ b/pyreport/pyreport.py @@ -51,6 +51,12 @@ def commandline_call(): else: pyfile = open(args[0],"r") + # fix include path + from os.path import dirname, abspath + path_of_pyfile = dirname(abspath(args[0])) + sys.path.insert(0, path_of_pyfile) + print sys.path + # Store the name of the input file for later use options.update({'infilename':args[0]})