|
| 1 | +# CodeRipple Import Guidelines |
| 2 | + |
| 3 | +This document establishes the standard import patterns for the CodeRipple project to ensure consistency across development environments and CI/CD pipelines. |
| 4 | + |
| 5 | +## Standard Import Patterns |
| 6 | + |
| 7 | +### ✅ Correct Import Patterns |
| 8 | + |
| 9 | +All CodeRipple modules should be imported using the package prefix: |
| 10 | + |
| 11 | +```python |
| 12 | +# Core agents |
| 13 | +from coderipple.orchestrator_agent import orchestrator_agent |
| 14 | +from coderipple.tourist_guide_agent import tourist_guide_agent |
| 15 | +from coderipple.building_inspector_agent import building_inspector_agent |
| 16 | +from coderipple.historian_agent import historian_agent |
| 17 | + |
| 18 | +# Core tools |
| 19 | +from coderipple.webhook_parser import GitHubWebhookParser, WebhookEvent |
| 20 | +from coderipple.git_analysis_tool import analyze_git_diff |
| 21 | +from coderipple.config import get_config |
| 22 | + |
| 23 | +# Content generation and validation |
| 24 | +from coderipple.content_generation_tools import generate_content |
| 25 | +from coderipple.bedrock_integration_tools import enhance_content_with_bedrock |
| 26 | +from coderipple.content_validation_tools import validate_content_quality |
| 27 | + |
| 28 | +# Analysis tools |
| 29 | +from coderipple.source_code_analysis_tool import analyze_source_code |
| 30 | +from coderipple.existing_content_discovery_tool import discover_existing_content |
| 31 | + |
| 32 | +# Advanced features |
| 33 | +from coderipple.agent_context_flow import coordinate_agents |
| 34 | +from coderipple.real_diff_integration_tools import integrate_diff_analysis |
| 35 | +``` |
| 36 | + |
| 37 | +### ❌ Incorrect Import Patterns |
| 38 | + |
| 39 | +**Do NOT use these patterns:** |
| 40 | + |
| 41 | +```python |
| 42 | +# ❌ Direct module imports (will fail in CI/CD) |
| 43 | +from webhook_parser import GitHubWebhookParser |
| 44 | +from git_analysis_tool import analyze_git_diff |
| 45 | +from tourist_guide_agent import tourist_guide_agent |
| 46 | + |
| 47 | +# ❌ src.module imports (legacy pattern) |
| 48 | +from src.webhook_parser import GitHubWebhookParser |
| 49 | +from src.git_analysis_tool import analyze_git_diff |
| 50 | + |
| 51 | +# ❌ sys.path manipulation (not needed with proper package structure) |
| 52 | +import sys |
| 53 | +import os |
| 54 | +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src')) |
| 55 | +``` |
| 56 | + |
| 57 | +## Package Structure |
| 58 | + |
| 59 | +CodeRipple follows standard Python package structure: |
| 60 | + |
| 61 | +``` |
| 62 | +coderipple/ |
| 63 | +├── src/ |
| 64 | +│ └── coderipple/ |
| 65 | +│ ├── __init__.py |
| 66 | +│ ├── orchestrator_agent.py |
| 67 | +│ ├── tourist_guide_agent.py |
| 68 | +│ ├── building_inspector_agent.py |
| 69 | +│ ├── historian_agent.py |
| 70 | +│ ├── webhook_parser.py |
| 71 | +│ ├── git_analysis_tool.py |
| 72 | +│ ├── config.py |
| 73 | +│ └── ... (other modules) |
| 74 | +├── tests/ |
| 75 | +│ ├── test_*.py (all test files) |
| 76 | +│ └── test_import_diagnostics.py (diagnostic framework) |
| 77 | +└── examples/ |
| 78 | + └── *.py (example files) |
| 79 | +``` |
| 80 | + |
| 81 | +## Environment Compatibility |
| 82 | + |
| 83 | +These import patterns work consistently across: |
| 84 | + |
| 85 | +- **Local Development**: macOS, Linux, Windows |
| 86 | +- **CI/CD Pipelines**: GitHub Actions, GitLab CI, etc. |
| 87 | +- **AWS Lambda**: Production deployment environment |
| 88 | +- **Docker Containers**: Containerized deployments |
| 89 | + |
| 90 | +## Diagnostic Tools |
| 91 | + |
| 92 | +### Import Diagnostics Test |
| 93 | + |
| 94 | +Run the comprehensive import diagnostic test to validate your environment: |
| 95 | + |
| 96 | +```bash |
| 97 | +cd coderipple |
| 98 | +python3 tests/test_import_diagnostics_standalone.py |
| 99 | +``` |
| 100 | + |
| 101 | +This test provides: |
| 102 | +- Environment analysis (Python version, paths, package installation) |
| 103 | +- Available modules discovery |
| 104 | +- Import validation with specific error reporting |
| 105 | +- Actionable recommendations for fixing issues |
| 106 | + |
| 107 | +### Pytest Integration |
| 108 | + |
| 109 | +For pytest-based testing: |
| 110 | + |
| 111 | +```bash |
| 112 | +cd coderipple |
| 113 | +pytest tests/test_import_diagnostics.py -v |
| 114 | +``` |
| 115 | + |
| 116 | +## Troubleshooting |
| 117 | + |
| 118 | +### Common Issues and Solutions |
| 119 | + |
| 120 | +**Issue**: `ModuleNotFoundError: No module named 'module_name'` |
| 121 | +**Solution**: Use `from coderipple.module_name import ...` instead of `from module_name import ...` |
| 122 | + |
| 123 | +**Issue**: `ModuleNotFoundError: No module named 'src.module_name'` |
| 124 | +**Solution**: Replace `from src.module_name import ...` with `from coderipple.module_name import ...` |
| 125 | + |
| 126 | +**Issue**: Imports work locally but fail in CI/CD |
| 127 | +**Solution**: Ensure you're using the `coderipple.` prefix for all CodeRipple modules |
| 128 | + |
| 129 | +**Issue**: `ModuleNotFoundError: No module named 'coderipple'` |
| 130 | +**Solution**: Install the CodeRipple package: `cd coderipple && pip install -e .` |
| 131 | + |
| 132 | +### Environment Validation |
| 133 | + |
| 134 | +Check your environment setup: |
| 135 | + |
| 136 | +```python |
| 137 | +import sys |
| 138 | +import coderipple |
| 139 | + |
| 140 | +print(f"Python version: {sys.version}") |
| 141 | +print(f"CodeRipple installed: {coderipple.__file__}") |
| 142 | +print(f"CodeRipple version: {coderipple.__version__}") |
| 143 | +``` |
| 144 | + |
| 145 | +## Development Workflow |
| 146 | + |
| 147 | +### Before Committing Code |
| 148 | + |
| 149 | +1. **Run import diagnostics**: `python3 tests/test_import_diagnostics_standalone.py` |
| 150 | +2. **Verify test imports**: `python3 -c "from tests.test_your_module import *"` |
| 151 | +3. **Check example imports**: `python3 -c "from examples.your_example import *"` |
| 152 | +4. **Run full test suite**: `pytest tests/ -v` |
| 153 | + |
| 154 | +### Code Review Checklist |
| 155 | + |
| 156 | +- [ ] All imports use `from coderipple.module_name import ...` pattern |
| 157 | +- [ ] No `sys.path.insert()` statements in test or example files |
| 158 | +- [ ] No `from src.module_name import ...` patterns |
| 159 | +- [ ] No direct module imports without `coderipple.` prefix |
| 160 | +- [ ] Import diagnostic test passes |
| 161 | + |
| 162 | +## CI/CD Integration |
| 163 | + |
| 164 | +The import diagnostic framework is integrated into the CI/CD pipeline to catch import issues before deployment: |
| 165 | + |
| 166 | +```yaml |
| 167 | +# GitHub Actions example |
| 168 | +- name: Run Import Diagnostics |
| 169 | + run: | |
| 170 | + cd coderipple |
| 171 | + python3 tests/test_import_diagnostics_standalone.py |
| 172 | +``` |
| 173 | +
|
| 174 | +## Future Enhancements |
| 175 | +
|
| 176 | +- **Import Linting**: Consider adding flake8 or pylint rules to enforce import patterns |
| 177 | +- **Pre-commit Hooks**: Automatically validate imports before commits |
| 178 | +- **IDE Integration**: Configure IDEs to suggest correct import patterns |
| 179 | +
|
| 180 | +--- |
| 181 | +
|
| 182 | +**Last Updated**: Unit 14.2 Implementation (June 2025) |
| 183 | +**Maintained By**: CodeRipple Development Team |
0 commit comments