function main_v19
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 launching 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 script or from a command-line interface.
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
# Typically called as the main entry point in a script
# File: app.py
import panel as pn
import argparse
import logging
# Set up logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
# Assume CDocsApp is defined elsewhere in the module
class CDocsApp:
def get_app(self):
return pn.Column('CDocs Application')
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()
# Command-line usage:
# python app.py --port 8080 --debug
# python app.py --port 5006
Best Practices
- Ensure the logger object is properly configured before calling this function
- The CDocsApp class must be defined and implement a get_app() method that returns a Panel-compatible object
- In production environments, avoid using --debug flag as it opens a browser window automatically
- The function should be called within an 'if __name__ == "__main__":' block when used as a script entry point
- Port conflicts should be handled at the system level; ensure the specified port is available
- The servable() method in production mode requires the script to be run with 'panel serve' command
- Consider adding error handling around app initialization and serving operations for production use
- The function blocks execution when running in debug mode with pn.serve()
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class CDocsApp 68.3% similar
-
class ControlledDocumentApp 66.8% similar
-
function main_v13 62.9% similar
-
class ControlledDocApp 61.1% similar
-
function main_v28 60.1% similar