function main_v10
Entry point function that initializes and serves the CDocs Panel web application with configurable port and debug mode options.
/tf/active/vicechatdev/cdocs_panel_app.py
135 - 156
moderate
Purpose
This function serves as the main entry point for the CDocs Panel application. It parses command-line arguments for port configuration and debug mode, instantiates the CDocsApp class, retrieves the Panel application object, and serves it either in debug mode (with auto-show) or production mode (as servable). It's designed to be called when running the application as a standalone script.
Source Code
def main():
"""Main entry point for the CDocs Panel application."""
# Parse command line arguments
parser = argparse.ArgumentParser(description='CDocs Panel Application')
parser.add_argument('--port', type=int, default=5006, help='Port to serve the application on')
parser.add_argument('--debug', action='store_true', help='Run in debug mode')
args = parser.parse_args()
# Create the application
app = CDocsApp()
# Set up the panel app
panel_app = app.get_app()
# Serve the application
if args.debug:
pn.serve(panel_app, port=args.port, show=True)
else:
panel_app.servable()
# Print serving information
logger.info(f"CDocs Panel App serving on port {args.port}")
Return Value
This function does not return any value (implicitly returns None). Its purpose is to start and serve the Panel application, which runs as a blocking operation in debug mode or sets up the application as servable in production mode.
Dependencies
panelparampandasargparseloggingossysdatetimeCDocs.ui.componentsCDocs.ui.authCDocs.initialize_systemCDocs
Required Imports
import panel as pn
import param
import pandas as pd
import os
import sys
import logging
from datetime import datetime
import argparse
from CDocs.ui.components import DocumentListView
from CDocs.ui.components import DocumentDetailView
from CDocs.ui.components import ReviewListView
from CDocs.ui.components import ApprovalListView
from CDocs.ui.auth import AuthManager
from CDocs.initialize_system import initialize_system
from CDocs import __version__
Usage Example
# Assuming this is in a file called app.py with CDocsApp defined
import panel as pn
import argparse
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
class CDocsApp:
def get_app(self):
return pn.Column('# CDocs Application', 'Welcome to CDocs')
def main():
parser = argparse.ArgumentParser(description='CDocs Panel Application')
parser.add_argument('--port', type=int, default=5006, help='Port to serve the application on')
parser.add_argument('--debug', action='store_true', help='Run in debug mode')
args = parser.parse_args()
app = CDocsApp()
panel_app = app.get_app()
if args.debug:
pn.serve(panel_app, port=args.port, show=True)
else:
panel_app.servable()
logger.info(f"CDocs Panel App serving on port {args.port}")
if __name__ == '__main__':
main()
# Run from command line:
# python app.py --port 5006 --debug
# or
# python app.py --port 8080
Best Practices
- This function should be called from a if __name__ == '__main__': block to ensure it only runs when the script is executed directly
- Ensure the logger is properly configured before calling this function to capture startup information
- The CDocsApp class must be defined or imported before calling main()
- In production environments, avoid using --debug flag as it opens a browser window automatically
- When using panel_app.servable(), ensure the script is run with 'panel serve' command rather than direct Python execution
- The port specified must not be in use by another application
- Consider adding exception handling around pn.serve() for production deployments
- Ensure all CDocs dependencies and modules are properly installed before running
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class CDocsApp 66.0% similar
-
function main_v7 64.2% similar
-
function main_v14 62.2% similar
-
function main_v9 60.5% similar
-
class ControlledDocApp 60.2% similar