-
Notifications
You must be signed in to change notification settings - Fork 34
Create gen-pydoc.py #589
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
base: main
Are you sure you want to change the base?
Create gen-pydoc.py #589
Changes from 4 commits
37e8591
97b0c2d
2a2e560
21c4694
9a07975
570bbcc
c82c96e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import pydoc | ||
| import pkgutil | ||
| import importlib | ||
| import os | ||
| import sys | ||
| import click | ||
|
|
||
| def generate_docs(package_name, output_file=None, file_prefix=None): | ||
| package = importlib.import_module(package_name) | ||
|
|
||
| out_f = open(output_file, 'w') if output_file else sys.stdout | ||
|
|
||
| out_f.write(f"\n# pydoc documentation for package: {package_name}\n") | ||
| out_f.write("\n---\n") | ||
|
|
||
| for _, module_name, is_pkg in pkgutil.walk_packages(package.__path__, package.__name__ + "."): | ||
| out_f.write(f"\n## pydoc of module: {module_name}\n") | ||
| out_f.write("\n---\n") | ||
|
guysmoilov marked this conversation as resolved.
|
||
|
|
||
| try: | ||
| docstring = pydoc.plain(pydoc.render_doc(module_name)) | ||
| out_f.write(docstring) | ||
|
Comment on lines
+20
to
+
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will ignore all of the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably less important for LLMs
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In my opinion this is actually MUCH MORE important for LLMs, because if the docs show up there, LLM will just pick it up and regurgitate to the user, and then the user ends up writing code that mangles private things that shouldn't be mangled.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will try to find a possible solution, probably not easy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there's a point in worrying about it yet, and if we have users complaining about these functions/fields changing we can tell them that they're intended to be private.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm realizing that it might be even worse, because I have some files where I have docs that I didn't bother to hide with |
||
| except Exception as e: | ||
| out_f.write(f"Error documenting {module_name}: {e}\n") | ||
|
|
||
| out_f.write("\n---\n") | ||
| out_f.write(f"\nEnd of documentation for module: {module_name}\n") | ||
|
|
||
| if file_prefix: | ||
| module_filename = f"{file_prefix}_{module_name.replace('.', '_')}.txt" | ||
| with open(module_filename, 'w') as module_file: | ||
| module_file.write(docstring) | ||
|
|
||
| if output_file: | ||
| out_f.close() | ||
|
|
||
| @click.command() | ||
| @click.argument("package_name") | ||
| @click.option("--output-file", "-o", default=None, help="File to write full documentation output.") | ||
| @click.option("--file-prefix", "-p", default=None, help="Prefix for separate module documentation files.") | ||
| def main(package_name, output_file, file_prefix): | ||
| generate_docs(package_name, output_file, file_prefix) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Uh oh!
There was an error while loading. Please reload this page.