Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/docs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ jobs:
# name: docs
# path: docs/build

# For LLM consumption
- name: Pydoc plaintext
run: |
python gen-pydoc.py -o build/html/dagshub-pydoc.txt -p build/html/dagshub-pydoc dagshub
python gen-pydoc.py -o build/html/dagshub-annotation-converter-pydoc.txt -p build/html/dagshub-annotation-converter-pydoc dagshub-annotation-converter


- name: Authenticate with Google
uses: "google-github-actions/auth@v2"
with:
Expand Down
45 changes: 45 additions & 0 deletions gen-pydoc.py
Comment thread
guysmoilov marked this conversation as resolved.
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")
Comment thread
guysmoilov marked this conversation as resolved.

try:
docstring = pydoc.plain(pydoc.render_doc(module_name))
out_f.write(docstring)
Comment on lines +20 to +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will ignore all of the :meta private tags I have on private functions that users aren't supposed to be using
Don't care about it that much, but I am concerned of LLMs abusing private things in the library.
Remains to be seen i guess

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably less important for LLMs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably less important for LLMs

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try to find a possible solution, probably not easy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

@kbolashev kbolashev Feb 5, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 :meta private, but are still very internal and just not showing up in the sphinx docs because I didn't add them.
Example: https://github.com/DagsHub/client/blob/master/dagshub/data_engine/client/data_client.py
this is the GraphQL data layer, which is not intended to be used directly

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()