jankatins / knitpy

knitpy: Elegant, flexible and fast dynamic report generation with python
https://github.com/jankatins/knitpy
Other
368 stars 29 forks source link

Check for input file and error out with a clear error #19

Closed jankatins closed 3 years ago

jankatins commented 9 years ago

From #14 via @thatcher:

Patch to #12 probably fine for unix/osx but returns an error on windows

>>> report.render('test.pymd', output='all')
[u'C:\\work\\knitpy\\test.html']

Note this used to return an array of all types (pdf, html, docx) so I'm not sure if thats related to recent changes or if that is quietly failing on the pdf (see below). When I try to render just the pdf I get an error:

>>> report.render('test.pymd', output='pdf')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "knitpy\knitpy.py", line 730, in render
    outputfile=outfilename)
  File "build\bdist.win-amd64\egg\pypandoc.py", line 94, in convert
  File "build\bdist.win-amd64\egg\pypandoc.py", line 135, in _convert
  File "build\bdist.win-amd64\egg\pypandoc.py", line 204, in _process_file
RuntimeError: Pandoc died with exitcode "43" during conversation: ! Undefined control sequence.
l.52 C:\work

pandoc: Error producing PDF from TeX source

Unfortunately relative paths like './test.pymd' throw the same error. I can get around it via a full path:

>>> report.render('C:\\work\\test.pymd', output='pdf')
[u'C:\\work\\test.pdf']

Looks like pypandoc might not be liking how knitpy is passing the file paths on Windows so this could be considered a pypandoc issue. I'll gather a little more details to see if I can find a best solution.

jankatins commented 9 years ago

I think the first is because the pdf building failed. I suspect that the latex file gets the filepath included somewhere in the document and this results in pdflatex thinking that \work is a control sequence.

Not sure what is happening here, I don't get this error with the knitpy --to=pdf example\knitpy_overview.pymd :-(

In [4]: from knitpy.knitpy import Knitpy
In [5]: report = Knitpy()
In [6]: report.render("./examples/knitpy_overview.pymd", output="pdf")
Out[6]: [u'C:\\data\\external\\knitpy\\examples\\knitpy_overview.pdf']
In [7]: cd examples/
C:\data\external\knitpy\examples
In [8]: report.render("knitpy_overview.pymd", output="pdf")
Out[8]: [u'C:\\data\\external\\knitpy\\examples\\knitpy_overview.pdf']

As I've found no way to see the temporary latex document (do you have temporary 'input.tex' somewhere in your AppData\Local\Temp\ folder?), I added latex output to knitpy in #17. Can you try that and send me the pymd and latex document (either here or via email -> jasc@gmx.net)?

thatcher commented 9 years ago

Totally my bad, doh! I was trying to reproduce the issue to look for the .tex file and everything ran fine. Turns out I was originally not in the directory I thought I was... arg, sorry.

Maybe the thing to take away is, knitpy should check for the existence of the specified source pymd file and report a clear 'File not found' error instead of passing it all the way along to pypandoc.

Thoughts?

(PS I guess I should have started a new ticket instead of polluting your testing task)

jankatins commented 9 years ago

No problem, changed the bug title. If you want to do a PR, this would be a nice start! :-)

thatcher commented 9 years ago

Will do thanks!