ledoc-ui
ledoc-ui is a Python package that bundles static files for the 'livedoc' user interface. It acts as a convenient way to distribute the HTML, CSS, and JavaScript assets of the 'livedoc' UI, which is designed to display API documentation (often generated by frameworks like Spring). The package itself does not contain Python logic for UI generation or interaction but rather provides the front-end resources for a web application to serve. The current version is 0.1.0, and its release cadence appears irregular based on its minimal activity.
Common errors
-
ModuleNotFoundError: No module named 'ledoc_ui.SomeClass'
cause Attempting to import a Python class or module that does not exist within the `ledoc_ui` package. The package is designed to provide static assets, not Python-executable code for UI construction.fixDo not try to import Python classes or functions from `ledoc_ui`. Instead, use `pkg_resources.resource_filename` to locate its static files and serve them via a web framework. -
404 Not Found (for CSS/JS files after loading index.html)
cause The web server (e.g., Flask, Django) is not correctly configured to serve the additional static assets (CSS, JavaScript, images) from the `ledoc-ui` package, or the paths in `index.html` do not match how the files are being served.fixEnsure your web framework's static file serving routes are configured to cover all files within the `ledoc_ui/static` directory, not just `index.html`. Verify that the paths requested by the browser (seen in network tab) match the paths your server is exposing.
Warnings
- gotcha ledoc-ui is purely a bundle of static web assets. It does not provide Python APIs for UI generation, component interaction, or documentation processing within Python code itself. Its utility is in providing front-end files to be served by a web server.
- gotcha Locating the static files correctly within the installed Python package can sometimes be tricky due to varying installation paths in different environments (virtual environments, Docker, etc.).
Install
-
pip install ledoc-ui
Imports
- static_folder_path
import os; import pkg_resources; static_folder_path = pkg_resources.resource_filename('ledoc_ui', 'static')
Quickstart
import os
from flask import Flask, send_from_directory
import pkg_resources
app = Flask(__name__)
# Get the path to the static files bundled with ledoc-ui
try:
LEDOCO_UI_STATIC_PATH = pkg_resources.resource_filename('ledoc_ui', 'static')
except ImportError:
# Fallback if pkg_resources isn't ideal or if the structure changes
# This assumes 'ledoc_ui' is installed in site-packages and 'static' is a direct subdir.
# A more robust solution might involve __file__ and os.path.dirname logic if pkg_resources fails.
print("Warning: pkg_resources failed. Attempting fallback for ledoc-ui static path.")
LEDOCO_UI_STATIC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'env', 'lib', 'pythonX.Y', 'site-packages', 'ledoc_ui', 'static')
# Replace 'pythonX.Y' with your actual Python version or adjust path as needed
@app.route('/')
def index():
# Serve the main index.html from ledoc-ui's static folder
return send_from_directory(LEDOCO_UI_STATIC_PATH, 'index.html')
@app.route('/<path:filename>')
def serve_static(filename):
# Serve other static files (CSS, JS, images) from ledoc-ui's static folder
return send_from_directory(LEDOCO_UI_STATIC_PATH, filename)
if __name__ == '__main__':
print(f"Serving ledoc-ui static files from: {LEDOCO_UI_STATIC_PATH}")
app.run(debug=True)