-
Notifications
You must be signed in to change notification settings - Fork 1
S.M.I.B. v2.0 #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S.M.I.B. v2.0 #320
Conversation
Initialized the project with Poetry, including virtual environment and dependency management. Added configuration for Slack tokens and created the `.gitignore` to exclude common project-specific files.
Implemented `asyncio`-based Slack app and FastAPI integration in `__main__.py`. Added custom FastAPI testing with decorators and a new `AsyncSchedulerEventHandler` for scheduled jobs. Updated `poetry.lock` with necessary async dependencies.
Modified the state endpoint to include default method argument and refactored context creation to use a dictionary directly. This improves code readability and maintains consistency in argument handling and context population.
Introduced logging functionality and a query parameter in FastAPI routes. Set FastAPI application to run in debug mode and configured server log level to trace for more detailed logs.
Fastapi not quite getting correct signature - will continue working on it later. Also need to create .pyi file for it Introduced `SMIBHttp` class to dynamically create and modify HTTP endpoints in a FastAPI app, leveraging `makefun`. Updated `fastapi_handler.py` to enhance request handling and incorporated the `makefun` package into the project dependencies.
Enhanced SMIBHttp class to integrate Slack event matching with FastAPI endpoints by modifying signatures and adding route decorators. Updated FastAPI event handler methods to pass request context for better request handling with Slack. Need to work on the response model validation
Inserted a TODO comment to utilize FastAPI's `serialize_response` for generating responses. This will help improve response handling in future updates.
Modified the Slack AsyncArgs retrieval to use class annotations and updated response handling to check for the presence of response body before parsing JSON. Additionally, replaced the `status` endpoint logic to set the response status code directly.
Refactor to remove unused methods and streamline Slack HTTP handler integration. Added response encoding for bolt responses and ensured consistent response handling. Removed print statements and improved method signature handling.
Refactored response handling to utilize CustomBoltResponse for better integration with FastAPI. Introduced new endpoints for a dashboard (HTMLResponse) and file download (FileResponse). Added a sample downloadable text file for testing purposes.
Refactored response handling to utilize CustomBoltResponse for better integration with FastAPI. Introduced new endpoints for a dashboard (HTMLResponse) and file download (FileResponse). Added a sample downloadable text file for testing purposes.
Renamed `StatusReturn` to `AppStatus` and updated its fields to reflect different components' status. Moved scheduler instantiation and job setup closer to the startup logic, improving code organization and readability.
Introduce `SMIBScheduler` class for job scheduling and integrate it into the main application. Also, add missing HTTP methods (`post`, `delete`, `patch`) to the `SMIBHttp` class for handling routes.
Introduce `scheduler_job_count` to track active jobs and enhance job-tracking functionality. Modify interval job to include scheduler context and update request initialization accordingly.
Reorder the shutdown sequence to ensure the scheduler shuts down before the server, providing a more graceful exit. This helps in managing tasks and connections more effectively during the application termination process.
Commented out print and async say statements in 10-second and 2-second interval jobs. This prevents unnecessary log outputs during execution.
This change updates the CSS to add a red color hover effect to buttons. Additionally, some TODO comments were introduced for future features like FastAPI Websocket Support, MQTT Support, Plugin Functionality, and Pytests.
Introduced a new TODO item for adding MongoDB (with Beanie) support in the codebase. This step is a part of expanding the planned features to incorporate database functionality.
Streamlined SMIB setup by simplifying slack app initialization and introducing plugin loading functionality. The extensive refactor removes unused code, archives old functionality, and improves modularity with the addition of a new plugins module.
The Slack setup logic has been moved to a new SMIB class, which implements lazy initialization for properties such as the Slack app and socket mode handler. This refactor improves modularity and makes the setup easier to unit test.
Introduce `EventServiceManager` for handling multiple event services with async capabilities. Implement `SlackEventService` and `HttpEventService` following a common protocol. Update dependencies and adjust project structure to support these changes.
Added a catch for unexpected exceptions in the main event loop for better error handling and logging. Removed EventServiceProtocol inheritance from SlackEventService and HttpEventService to simplify class structures.
Introduced plugin loading mechanism with new `plugins.py` file and integrated it into the main event loop. Refactored `SlackEventService` to replace `service` with `handler` for consistency. Updated logging configuration and minor adjustments in `config.py`.
Deleted the space_state plugin and enhanced the main script's logging format. Introduced a lazy_property decorator for lazy-loading properties and updated event services to use it. Added utility functions for package root retrieval and adjusted config to use the new utility.
Reorganized plugin management by replacing the old `plugins.py` with a new modular structure. Introduced `PluginLifecycleManager` to load plugins and added a `default_error_handler` to handle errors within the Slack app. Modified event services to include type hints for better clarity.
Moved event services to a new directory structure for clarity. Enhanced plugin lifecycle management by consolidating validation and registration logic into `PluginLifecycleManager`. Added better error handling and logging to ensure robust plugin loading and unloading processes.
- Refactored `EventServiceManager` to remove positional args, improve logging, and handle unregistered services gracefully. - Updated `get_package_root` to dynamically accept package names, improving reusability. - Enhanced `config.py` to include default webserver parameters (`WEBSERVER_HOST`, `WEBSERVER_PORT`). Other changes: added new event handler modules, updated dependencies in Poetry configurations, and bumped project version to `2.0.dev1`.
Reorganized plugin registration and lifecycle management for improved modularity and robustness. Enhanced dependency structure by transitioning to optional dependencies and aligning with Python 3.12+ syntax. Removed unused code and improved documentation for better maintainability.
Added `.venv/` to `.dockerignore` to prevent committing virtual environments. This helps keep the repository clean and avoid unnecessary file uploads in Docker builds.
Updated the `should_log_request` method to exclude logging for requests whose paths start with `/static` or the application's root `/static` path. This prevents unnecessary logging of static file access, improving log relevance.
Added the "no-guess-dev" option under Hatch's versioning to enforce a specific version scheme. This ensures consistent version management during builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR represents a complete rewrite of S.M.I.B. v2.0, restructuring the codebase from a legacy websocket-based architecture to a modern async framework. The major changes include:
- Transition from websocket-based communication to direct async event handling
- Complete rewrite of the plugin system with better integration and lifecycle management
- Migration from mogo to beanie for MongoDB ODM
- Environment variable renaming with
SMIB_prefix for better organization
Reviewed Changes
Copilot reviewed 111 out of 126 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| template.env | Updates environment variable naming to use SMIB_ prefix |
| src/smib/utilities/* | New utility modules for package management, lazy properties, and environment detection |
| src/smib/events/* | New async event handling architecture replacing websocket system |
| src/smib/plugins/* | Complete rewrite of plugin system with better lifecycle management |
| src/smib/config/* | New configuration system using pydantic settings |
| src/plugins/* | Updated plugin implementations using new architecture |
| smib/* (removed) | Legacy websocket and old plugin system files removed |
Comments suppressed due to low confidence (1)
src/smib/events/interfaces/http_event_interface.py:76
- The CopyableStarletteRequest wrapper has a TODO comment indicating it needs proper testing. This is critical functionality that should be thoroughly tested.
# TODO - This needs proper testing
…IBHID should just work
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
might remove lazy properties later Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Refactored `uses_deprecated_route` to utilize `lru_cache` for caching route matching logic. Improved request scope handling by adding JSON-based serialization.
- Introduce `module` property in `Plugin` for encapsulation. - Replace direct `_module` references with `module` property across integrations.
|
@sjefferson99 - I've tweaked and resolved all Copilot suggestions I deemed valid. |
- Add `.env` to `.dockerignore` for security and consistency. - Adjust Traefik settings: reorganize flags, enforce network constraints, and enable insecure server transport option.
sjefferson99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on smib-sj working with latest smibhid code.
Review code general structure and is logical and less framework dependent.
Complete re-write
Backwards compatible with SMIBHID current version
Note:
Environment variables have been renamed
closes #13
closes #14
closes #15
closes #20
closes #79
fixes #216
resolves #222
closes #227
closes #235
closes #316
closes #319
closes #321