-
Notifications
You must be signed in to change notification settings - Fork 46
reStructuredText rendering errors don't show filename, just "string" #144
Comments
Thanks for the issue report! I think adding the @mythmon thoughts on that solution? |
This doesn't seem invasive to the API to me. I like the idea of adding the @matt-garman, if you'd like to file a PR for those changes, that would be awesome 🎆. Otherwise, I'm sure someone will get to it at some point. |
Thank you for the quick feedback! I should be able to come up with a PR fairly soon. Another idea: the render() function could be changed to take an object; and that object would initially contain the to-be-rendered text plus the source filename. If ever more metadata is to be passed to the underlying renderers, this might be a little cleaner (or maybe messier, depending on your perspective ;)). Sorry, I accidentally closed this, re-opening. |
This is in theory easy to implement, but I'm getting hung up on something that doesn't make sense to me. In renderers.py, I simply added a "source_path=None" argument to all render() definitions. And then in page.py, for the from_file() function, I modified the content rendering line like this: page.meta['content'] = page.renderer.render(page.original, source_path=page.path) It works as expected for everything in the test_site, except the html_renderer.html page, where it blows up with this:
So just before the render() call I added some prints: print "DEBUG: page.path=\"" + str(page.path) + "\""
print "DEBUG: page.renderer=\"" + str(page.renderer) + "\""
print "DEBUG: page.renderer.render=\"" + str(page.renderer.render) + "\"" For the stuff that works, the output of these prints is predictable:
But for the html file, it shows this:
I don't really understand where this "function render at 0x15917d0" actually lives in the source. Any thoughts? Thanks! |
Needing to add I'm not quite sure what could cause the errors you talk about though. I think it would be better to post a PR with your code in it, even if the code is unfinished. Talking about this error will be easier when we can all see the code. Thanks for the work on this! |
render() definitions so it can be passed through to the actual RST docutils renderer. This code fails on the test site, and has some debug print statements added. It is intended as an illustration only, definitely not production quality.
I agree, but I don't see how this is possible without more dramatic changes to the code. The Renderer class (and all sub-classes) defines the render() function as static (@classmethod). Every page object has a renderer member defined by its extension. When the page.renderer.render() function is actually called, it's not known if source_path is needed or not. IOW, to use the source_path parameter at this point, the filename extension check would have to be re-done which to me also seems wrong. Here's another idea, though it's much more substantial in scope: change render() to be non-static. Create something like a factory that will produce a Renderer object based on filename extension, on a per-page basis (i.e. each page has its own Renderer instance). The ReStructuredText Renderer class can have a source_path member which will be set when instantiated (i.e. by the factory).
Done! Hopefully some of what I wrote above will make more sense in light of the PR code.
You are welcome, though I feel like I'm creating more work for you! :) |
Issue mythmon#144: reStructuredText rendering errors don't show filename, just "string". The actual ReST renderer, docutils.core.publish_parts(), supports a "source_path" parameter, which can be used to set the filename of the rendered file. With this paramter set, in case of error, the filename will be shown instead of just "<string>". This fix fundamentally modifies the structure of the wok/renderers.py module. Previously, all render() functions were defined as classmethods. This change makes them instance methods. Each page object gets assigned its own Renderer instance. For the ReStructuredText renderer, an optional source_path parameter is allowed by the constructor. If set, this will be stored with the instance, and passed on to the docutils function. A new function is introduced in wok/renderers.py: factory(). This is called in wok/engine.py when the renderer is assigned to the page. This does the work of looking at all available renderers, and matching the filename extention to the appropriate renderer, and returning a valid object instance.
- Add file "test_site/wok_expected_output-test_site" which is the output of "wok -v" when run with current upstream master. - Introduce new environment variable "CMP_OUTPUT" in .travis.yml. - Enhance bin/site-tests such that if CMP_OUTPUT==true, it will run cmp on the wok_expected_output-$TEST_SITE file versus the output of the "wok -v" run. - Goal of this enhancement is to support more robust testing of fixes for issues mythmon#144 and mythmon#145.
This was a known-bad commit just to illustrate a problem. A bad way to fix issue mythmon#144 (add source_path param to all render() methods in wok/renderers.py). Removing to clean up. This reverts commit 7cf34e2.
- Add file "test_site/wok_expected_output-test_site" which is the output of "wok -v" when run with current upstream master. - Introduce new environment variable "CMP_OUTPUT" in .travis.yml. - Enhance bin/site-tests such that if CMP_OUTPUT==true, it will run cmp on the wok_expected_output-$TEST_SITE file versus the output of the "wok -v" run. - Goal of this enhancement is to support more robust testing of fixes for issues mythmon#144 and mythmon#145.
This was a known-bad commit just to illustrate a problem. A bad way to fix issue mythmon#144 (add source_path param to all render() methods in wok/renderers.py). Removing to clean up. This reverts commit 7cf34e2.
The reStructuredText render will pass use this metadata if availbe, and pass through to the source_path parameter in publich_parts. This is to fix issue mythmon#144.
docutils.core.publish_parts() source_path parameter. This is to fix issue mythmon#144.
If my reStructuredText source document has an error, the filename is not printed, only "string". For example:
I'm not sure if this happens with other renderers too, I currently only use RST.
In renderers.py, for the ReStructuredText implementation, there is a call to docutils.core.publish_parts() (line 92). This function takes an optional parameter, "source_path", which is currently not used by Wok. Whatever this is set to will be displayed when there is an error, instead of the ambiguous "string" (as shown above). Both the documentation and my experimentation suggest this variable is for display purposes only, i.e. it doesn't actually try to reference that variable as a file.
I think this is a relatively easy fix: to the generic Renderer.render() function, I could add an additional optional variable that defaults to None. This variable would be "source_path" (or "source_filename" or even "slug"), and if set, would be passed through to the the underlying renderer if supported.
Maybe there's a better/cleaner way to do this that is less "invasive" to the API? I'm happy to work on this, but would like a little guidance on the best route to take. Thanks!
The text was updated successfully, but these errors were encountered: