This guide provides a comprehensive plan for adding new package manager detectors to the energy-dependency-inspector system.
The energy-dependency-inspector uses a modular detector architecture where each package manager has its own detector class that implements the PackageManagerDetector interface. This design allows for easy extensibility while maintaining consistent behavior across all detectors.
Before adding a new detector, ensure you understand:
- Architecture Decision Records (ADRs): Review
/docs/technical/architecture/adr/for design principles - Existing Detectors: Study
/energy_dependency_inspector/detectors/implementations - Interface Contracts: Understand
PackageManagerDetectorin/energy_dependency_inspector/core/interfaces.py - Testing Patterns: Review
/tests/detectors/structure
Create /energy_dependency_inspector/detectors/{package_manager}_detector.py implementing the PackageManagerDetector interface with these required methods:
__init__(self, debug: bool = False): Initialize detector with debug flagis_usable(): Check if package manager is available in the environmentget_dependencies(): Extract package dependencies with versions and metadatais_os_package_manager(): Determine if detector manages OS-level packagesget_name(): Return the detector name (inherited from base class)
Scope Determination:
system: System-wide packages (dpkg, apk, yum, etc.)project: Project-specific packages (npm, pip with venv, etc.)
Working Directory Handling:
- Always respect the
working_dirparameter - Use it for package manager commands when appropriate
- For project-scoped detectors, check for project files in
working_dir
Hash Implementation (see ADR-0005):
- Tier 1: Use authentic hashes from package managers when available
- Tier 2: Generate location-based hashes for project scope
- Tier 3: Skip hashes when not feasible
Error Handling:
- Always handle command execution failures gracefully
- Return empty dependencies dict on errors, not exceptions
- Log debug information when
self.debugis True
Read-Only Constraint (see ADR-0003):
- No downloads, installations, or system modifications
- Use only existing tools and metadata
- Work with current environment state as-is
Add your detector to the detectors list in /energy_dependency_inspector/core/orchestrator.py following the priority order:
Priority Ordering:
- Container information (docker-info)
- System packages (dpkg, apk, yum, etc.)
- Language-specific packages (pip, npm, composer, pecl, etc.)
Reference existing detectors like DpkgDetector, ApkDetector, PipDetector, NpmDetector, ComposerDetector, and PeclDetector for import and initialization patterns.
Add to /energy_dependency_inspector/detectors/__init__.py if needed.
Create /docs/technical/detectors/{package_manager}_detector.md with the following structure:
Required Sections:
- Overview: Brief description of the package manager and detector purpose
- Scope: Document system/project scope and target environments
- Detection Logic: Explain usability checks and dependency extraction
- Hash Strategy: Document which tier is implemented (Tier 1/Authentic, Tier 2/Location-based, or Tier 3/None)
- Limitations: Known limitations or edge cases
- Example Output: JSON sample showing expected output format
Expected JSON Output Format:
Standard output includes scope, dependencies dict with package names and versions, and optional hash and location fields. Reference existing detector documentation for specific examples.
Create /tests/detectors/{package_manager}/ with:
__init__.pyREADME.mdtest_{package_manager}_docker_detection.py
Create a test class inheriting from DockerTestBase in /tests/common/docker_test_base.py. Key components:
- Choose appropriate Docker image containing your package manager
- Use
DockerExecutorto run tests in containerized environment - Test via
Orchestratorto ensure integration works correctly - Validate expected output format and required fields
- Include proper cleanup and error handling
Reference existing detector tests in /tests/detectors/ for implementation patterns.
Create /tests/detectors/{package_manager}/README.md documenting:
Content Structure:
- Docker Test: Description of Docker-based testing approach
- Image Used: Document the Docker image used for testing
- Test Commands: List the commands tested
- Running Tests: Instructions for executing the tests
Test Execution Patterns:
Reference pytest command patterns from existing detector test READMEs for running individual tests, verbose output, and full test suites.
Basic Testing Steps:
- Activate environment: Use virtual environment activation
- Test detector directly: Import and run your detector with
debug=True - Test via CLI: Use debug mode to see detailed output
- Test in target environment: Use appropriate executor (host/docker) for your use case
Run detector-specific tests, full test suite, and linting checks. Reference CLAUDE.md for specific commands and patterns.
- Add your detector to
/README.mdin the supported package managers section
If a performance-analysis/ directory exists, add a benchmark script following the existing patterns in that directory. This is typically added later if performance analysis is needed.
Reference DpkgDetector and ApkDetector implementations:
- Always return
Trueforis_os_package_manager() - Extract from system package database
- Usually ignore
working_dirfor system packages - Return
{"scope": "system", "dependencies": {}}
Reference PipDetector, NpmDetector, ComposerDetector, and PeclDetector implementations:
- Check for project files in
working_dirto determine scope - Extract project dependencies when project files found
- Fall back to system scope when no project context
- Return appropriate scope with location for project dependencies
- Use Debug Mode: Always test with
debug=Trueduring development - Check Command Output: Verify package manager commands work in target environment
- Test Edge Cases: Empty environments, permission issues, missing tools
- Validate JSON Output: Ensure output follows expected schema
- Test Both Scopes: If supporting both project and system scope
Use python3 -m energy_dependency_inspector --debug to see detailed execution flow.
Before submitting your detector:
- Implements all required interface methods
- Handles errors gracefully (no exceptions in normal operation)
- Respects read-only constraint (ADR-0003)
- Implements appropriate hash strategy (ADR-0005)
- Has comprehensive tests with Docker environment
- Follows existing code style and patterns
- Has complete documentation
- Added to orchestrator registration
- Passes all linting checks
- Manual testing in target environments
- Performance considerations documented
Key Reference Files:
/energy_dependency_inspector/detectors/- Existing detector implementations/energy_dependency_inspector/core/interfaces.py- PackageManagerDetector interface/energy_dependency_inspector/core/orchestrator.py- Detector registration/docs/technical/architecture/adr/- Architecture decision records/tests/detectors/- Test patterns and examples/tests/common/docker_test_base.py- Docker testing base class
Debug Commands:
python3 -m energy_dependency_inspector --debug- Full debug outputsource venv/bin/activate- Activate development environmentpre-commit run --files $(git diff --name-only --diff-filter=ACMR HEAD)- Run linting