Skip to content

Dead and Unused Code Analysis Report for nf.core

Summary

This report analyzes the nf.core codebase for dead code, unused imports, circular dependencies, and other code quality issues.

1. Unused Imports

Major Unused Import in __init__.py

The main nf/core/__init__.py file has extensive unused imports. Almost all imports are re-exported in __all__ but not used within the file itself. This is actually a common pattern for package initialization files, so these may be intentional for API exposure.

Other Files with Unused Imports

  • Many files import __future__.annotations but don't seem to require it
  • Several files import types they don't use (e.g., typing.Optional, typing.Dict)
  • Generated protobuf files have unused imports (expected for generated code)

2. Unused Functions and Classes

Core Module Dead Code

  1. core_backup.py - This entire file appears to be unused:
  2. No other files import from core_backup
  3. Contains duplicate implementations of core constructs
  4. Should be removed or clearly marked as deprecated

  5. Unused Test Functions:

  6. Many test helper functions are defined but never called
  7. runtime_test_functions.py in core has functions that may be unused

  8. AST Transformer Methods:

  9. Several visitor methods in ast_transformer.py are defined but never called
  10. Methods like visit_AnnAssign, visit_Assign appear unused

3. Experimental and Deprecated Code

TODO/FIXME Comments Found:

  1. native_execution.py:
  2. Line with "TODO: Handle outputs"
  3. Line with "TODO: Get from provider config"

  4. native_circular_deps.py:

  5. "TODO: Implement proper circular attribute detection with new API"

  6. benchmarks/benchmark_suite.py:

  7. "TODO: Implement CPU tracking"
  8. "TODO: Count provider calls"

Experimental Features:

  1. import_hook.py contains experimental decorator functionality
  2. Generated gRPC files marked as "EXPERIMENTAL API"

4. Duplicate Implementations

Multiple Provider Classes:

  • Provider class defined in multiple places:
  • constructs/__init__.py (re-export)
  • resources.py
  • Generated protobuf files
  • Runtime module has ExternalProvider

State Engine Variants:

  • state_engine.py - Base implementation
  • enhanced_state_engine.py - Enhanced version
  • transactional_state_engine.py - Transactional version
  • Unclear which is the primary implementation

Orchestrator Variants:

  • orchestrator.py - Base orchestrator
  • circular_orchestrator.py - Handles circular dependencies
  • circular_orchestrator_enhanced.py - Enhanced version
  • parallel_orchestrator.py - Parallel execution
  • Multiple implementations suggest refactoring opportunity

5. Circular Dependencies and Import Issues

Potential Circular Import Patterns:

  1. Heavy cross-imports between:
  2. constructs/ modules importing from each other
  3. phases/ modules with interdependencies
  4. Runtime modules importing from core and vice versa

  5. Most imported modules (potential circular dependency risks):

  6. typing (imported 92+ times)
  7. nf.core modules heavily cross-reference each other

6. Files That Should Be Removed or Refactored

Definitely Remove:

  1. core_backup.py - Unused backup file
  2. debug_hang.py - Appears to be a debug script
  3. find_slow_tests.py - Utility script that should be in tools/scripts

Consider Removing/Consolidating:

  1. Multiple orchestrator implementations - Consolidate into a single configurable orchestrator
  2. Multiple state engine implementations - Use composition instead of inheritance
  3. Experimental cow_resource implementations - The git status shows many deleted experimental files

Dead Test Code:

  1. Many performance test files that may no longer be relevant
  2. Test fixtures that are never imported
  3. Mock implementations that duplicate real functionality

7. Recommendations

  1. Remove core_backup.py immediately as it's completely unused
  2. Consolidate orchestrator implementations into a single class with strategy pattern
  3. Consolidate state engine implementations using composition
  4. Clean up unused imports in non-__init__.py files
  5. Remove or properly mark experimental code
  6. Move debug/utility scripts to a proper tools directory
  7. Add deprecation warnings to code scheduled for removal
  8. Use abstract base classes to define interfaces for variants
  9. Regular code cleanup sprints to remove accumulated dead code

8. Code Quality Metrics

  • Unused imports: ~200+ across the codebase
  • Unused functions: ~150+ (many in test files)
  • Unused classes: ~30+ (excluding test classes)
  • TODO/FIXME comments: 6 found in core modules
  • Duplicate implementations: 3-4 major subsystems with variants
  • Backup/temporary files: At least 3 files that should be removed