DCsunset / pandoc-include

A pandoc filter to allow file and header inclusion
MIT License
63 stars 14 forks source link

Use python's default tempfile module #10

Closed austinjp closed 4 years ago

austinjp commented 4 years ago

which automatically removes its temporary files.

DCsunset commented 4 years ago

Thanks for your contributions. But the temp file is used to share config between multiple executions of pandoc_include.py.

It couldn't be achieved by using the tempfile module because it generates a random filename that can't be found in subsequent executions of pandoc_include.py.

austinjp commented 4 years ago

Ah apologies I misunderstood its purpose. I was getting error messages from the line os.remove(temp_filename), for some reason:

Traceback (most recent call last):
  File "/home/austinjp/whatever/venv/bin/pandoc-include", line 11, in <module>
    sys.exit(main())
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/pandoc_include.py", line 164, in main
    return pf.run_filter(action, doc=doc)
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/panflute/io.py", line 260, in run_filter
    return run_filters([action], *args, **kwargs)
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/panflute/io.py", line 241, in run_filters
    doc = doc.walk(action, doc)
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/panflute/base.py", line 273, in walk
    ans = list(chain.from_iterable(ans))
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/panflute/base.py", line 271, in <genexpr>
    ans = ((item,) if type(item) != list else item for item in ans)
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/panflute/base.py", line 268, in <genexpr>
    ans = (item.walk(action, doc) for item in obj)
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/panflute/base.py", line 284, in walk
    altered = action(self, doc)
  File "/home/austinjp/whatever/venv/local/lib/python3.6/site-packages/pandoc_include.py", line 152, in action
    os.remove(temp_filename)
FileNotFoundError: [Errno 2] No such file or directory: '.temp.pandoc-include'
Error running filter pandoc-include:
Filter returned error status 1

Would it be reasonable to wrap that line in a try...except that displays an error but carries on?

DCsunset commented 4 years ago

Oh, that was a bug in v0.7.0. I released v0.7.2 yesterday to fix this bug. You might update pandoc-include and try it again.