Certainly! Below is a comprehensive prompt you can use to instruct your agents to create a more modular version of code.py. This prompt emphasizes the use of a separate config.yaml for configuration, enhancing usability, and supporting different scenarios through an updated_code.py.
Task: Refactor code.py into a more modular updated_code.py using config.yaml for configuration settings.
Objectives:
- Modularity: Break down the existing
code.py into smaller, reusable components or modules to improve readability and maintainability.
- Configuration Management: Utilize the provided
config.yaml file to handle all configurable parameters, allowing easy adjustments without modifying the codebase.
- Scenario Handling: Enable
updated_code.py to support different execution scenarios as defined in config.yaml.
- Usability Enhancements: Improve the overall usability of the code by implementing best practices, adding documentation, and ensuring a clear and logical structure.
Instructions:
-
Analyze Existing Code:
- Thoroughly review the provided
code.py to understand its functionality, workflows, and dependencies.
- Identify sections of the code that can be modularized or require improvement.
-
Design Modular Structure:
- Functions & Classes: Break down large functions into smaller, more manageable ones. Consider creating classes if object-oriented design benefits the project.
- Modules: Separate different functionalities into distinct modules or files as appropriate.
- Imports: Ensure that dependencies are well-organized and imported correctly across modules.
-
Integrate config.yaml:
- Identify Configurable Parameters: Locate all parameters in
code.py that can be externalized (e.g., paths, thresholds, API keys).
- Configuration Loader: Implement a configuration loader in
updated_code.py that reads settings from config.yaml.
- Default Values: Provide sensible default values in
config.yaml for ease of use.
- Validation: Add validation to ensure that configuration values meet expected formats and ranges.
-
Handle Different Scenarios:
- Define Scenarios: Clearly specify different scenarios or environments (e.g., development, testing, production) within
config.yaml.
- Conditional Logic: Modify
updated_code.py to execute different code paths based on the active scenario defined in the configuration.
- Flexibility: Ensure that adding new scenarios in the future requires minimal changes to the codebase.
-
Enhance Usability:
- Documentation: Add comprehensive docstrings to modules, classes, and functions explaining their purpose and usage.
- Logging: Implement logging to track the application's behavior and facilitate debugging.
- Error Handling: Improve error handling to provide meaningful messages and prevent unexpected crashes.
- User Interface: If applicable, enhance the user interface (CLI, GUI, etc.) to make interactions more intuitive.
-
Testing:
- Unit Tests: Write unit tests for individual modules and functions to ensure they work as intended.
- Integration Tests: Test how different modules interact within
updated_code.py.
- Configuration Tests: Verify that different configurations in
config.yaml correctly influence the behavior of updated_code.py.
- Regression Tests: Ensure that refactoring has not introduced any regressions or broken existing functionality.
-
Review & Optimize:
- Code Review: Conduct a thorough code review to identify and rectify potential issues or areas for improvement.
- Performance Optimization: Optimize the code for performance where necessary without sacrificing readability and maintainability.
- Clean Up: Remove any redundant code, comments, or unused variables.
-
Deliverables:
updated_code.py: The refactored, modular version of the original code.py that leverages config.yaml for configuration.
- Documentation: Any additional documentation or guides that help in understanding and using
updated_code.py.
- Test Scripts: All test scripts written to verify the functionality and reliability of
updated_code.py.
Constraints:
- Do Not Modify: The original
code.py and config.yaml should remain unchanged. The focus is solely on creating updated_code.py.
- Maintain Functionality: Ensure that
updated_code.py preserves all functionalities of the original code.py while enhancing its structure and usability.
- Best Practices: Adhere to coding best practices, including following a consistent coding style, writing readable code, and maintaining proper documentation.
Outcome:
By following this prompt, the agents will produce an updated_code.py that is more modular, easier to maintain, and more flexible due to the separation of configuration. This refactored code will better support different scenarios and provide an improved user experience.
Feel free to adjust any sections of this prompt to better fit the specific requirements or context of your project.