🔍 Code Extractor

function main_v19

Maturity: 46

Entry point function that initializes and serves the CDocs Panel web application with configurable port and debug mode options.

File:
/tf/active/vicechatdev/cdocs_panel_app.py
Lines:
135 - 156
Complexity:
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

  • panel
  • param
  • pandas
  • argparse
  • logging
  • os
  • sys
  • datetime
  • CDocs.ui.components
  • CDocs.ui.auth
  • CDocs.initialize_system
  • CDocs

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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class CDocsApp 68.3% similar

    Panel-based web application class for the CDocs Controlled Document System that provides a complete UI with navigation, authentication, and document management features.

    From: /tf/active/vicechatdev/cdocs_panel_app.py
  • class ControlledDocumentApp 66.8% similar

    Main application class for the Controlled Document Management System. This class initializes all components and provides the main Panel interface for the application. It is designed to be served via `panel serve` command and integrates with the existing datacapture application.

    From: /tf/active/vicechatdev/CDocs/main.py
  • function main_v13 62.9% similar

    Main entry point for a Streamlit-based FileCloud Data Processor application that handles authentication, session state management, and navigation between multiple modules including document audit, controlled documents, settings, and reports.

    From: /tf/active/vicechatdev/datacapture_integrated.py
  • class ControlledDocApp 61.1% similar

    A standalone Panel web application class that provides a complete controlled document management system with user authentication, navigation, and document lifecycle management features.

    From: /tf/active/vicechatdev/panel_app.py
  • function main_v28 60.1% similar

    Entry point function that orchestrates the Project Victoria disclosure analysis by initializing the generator, running the complete analysis, and displaying results with next steps.

    From: /tf/active/vicechatdev/project_victoria_disclosure_generator.py
← Back to Browse