Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pip install docbuddy
docbuddy
```

This starts a local server on port **8008** and opens your browser to [http://localhost:8008/docs/index.html](http://localhost:8008/docs/index.html).
This starts a local server on port **8008** and opens your browser to `http://localhost:8008/standalone.html`.

#### Custom Host/Port

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ <h3>🚀 Run Locally with CLI</h3>
<span class="copy-hint">Click to copy</span>
</div>
<p style="font-size: 12px; color: var(--theme-text-secondary); margin-top: 8px;">
Opens at <code>http://localhost:8008/docs/index.html</code>
Opens at the address shown in the terminal (default port <code>8008</code>)
</p>

<h3>Python Plugin</h3>
Expand Down
39 changes: 17 additions & 22 deletions src/docbuddy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"""CLI entry point for launching DocBuddy standalone webpage."""

import argparse
import functools
import http.server
import os
import sys
import threading
import time
import webbrowser

from importlib.resources import files


Expand All @@ -33,36 +34,30 @@ def main():

args = parser.parse_args()

# Use importlib.resources to find the docs directory
docbuddy_pkg = files("docbuddy")

# The docs directory is at the project root, one level up from src/docbuddy
# When installed, it's in site-packages/docbuddy/../..
docs_path = docbuddy_pkg.parent.parent / "docs"
# Locate packaged assets via importlib.resources (works for both editable
# and normal pip installs; no os.chdir() needed).
pkg_ref = files("docbuddy")
standalone_ref = pkg_ref.joinpath("standalone.html")

if not docs_path.exists():
print(f"Error: Could not find 'docs' directory at {docs_path}", file=sys.stderr)
if not standalone_ref.is_file():
print(
f"Error: Could not find 'standalone.html' in the docbuddy package ({pkg_ref})",
file=sys.stderr,
)
sys.exit(1)

# Serve from the project root (parent of docs) so static files are accessible
# The index.html uses paths like /src/docbuddy/static/core.js which need the parent
os.chdir(docs_path.parent)
# Serve only the package directory – not the whole repo/site-packages root.
pkg_dir = str(pkg_ref)
handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=pkg_dir)

url = f"http://{args.host}:{args.port}/docs/index.html"
url = f"http://{args.host}:{args.port}/standalone.html"

print(f"Serving DocBuddy at {url}")
print("Press Ctrl+C to stop the server")

# Start HTTP server
with http.server.HTTPServer(
(args.host, args.port), http.server.SimpleHTTPRequestHandler
) as httpd:
# Give it a moment for server to fully start before opening browser
import threading
with http.server.HTTPServer((args.host, args.port), handler) as httpd:

def open_browser():
import time

time.sleep(0.5)
webbrowser.open(url)

Expand Down
Loading