-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom attributes to HTML templates #335
Comments
Can you show a full example how you'd use it?
|
Thanks for that tip, (re: # test_results contains dict of test results collected from pytest junit xml
context = pdoc.Context()
module = pdoc.Module('test/my_tests.py')
pdoc.link_inheritance(context)
for c in module.classes():
for m in c.methods():
m.obj.test_results = {}
if m.refname in test_results:
m.obj.test_results = test_results[m.refname]
print(module.html()) This is working fine for me now. I wonder if this is the supported approach, and if so perhaps an example could be added to the documentation (I'm willing to submit a PR if so). Additionally, now that I'm using the programatic approach, filtering was no longer working. In the test suite I have a number of classes and methods set in context = pdoc.Context()
module = pdoc.Module('test/my_tests.py')
pdoc.link_inheritance(context)
def filter_objects(obj):
if obj.refname.replace('my_tests.', '') in module.__pdoc__:
return False
return True
for c in module.classes():
for m in c.methods():
m.obj.test_results = {}
if m.refname in test_results:
m.obj.test_results = test_results[m.refname]
print(pdoc.html(module, docfilter=filter_objects)) This works, however I get the warnings:
Both While currently I'm just working with one file, I wonder how well this implementation will scale as more test files are added. Any input welcome, and I'd be happy to help improve the documentation on this procedure once I'm confident in the approach. |
You need to pass the module = pdoc.Module(..., context=context) Other than that, I don't see why module's |
@kernc Ah, of course - I had this originally added but must have removed it without noticing during experimentation. Re-adding context solves the issue of filtering. I've created a small PR mentioning the availability of the |
I would like to append the documentation with auxiliary data which would be collected at the time of document generation. (eg. test results).
Expected Behavior
When using
pdoc3
programmatically, it would be nice if additional variables could be attached to the Class/Method objects, which could be accessed from within the templates.Actual Behavior
Currently I'm unable to find any way to add custom variables.
Additional info
0.9.2
The text was updated successfully, but these errors were encountered: