Skip to content

Refactor get_cpus() function into single-responsibility functions - #210

Open
elfosardo wants to merge 1 commit into
redhat-cip:masterfrom
elfosardo:refactor-get-cpu
Open

Refactor get_cpus() function into single-responsibility functions#210
elfosardo wants to merge 1 commit into
redhat-cip:masterfrom
elfosardo:refactor-get-cpu

Conversation

@elfosardo

@elfosardo elfosardo commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Break down the 143-line monolithic get_cpus() function into 6 smaller,
focused functions to improve maintainability and testability.

Changes:

  • Extract _parse_lscpu_output() for lscpu command parsing
  • Extract _detect_physical_cpus() for socket and CPU properties detection
  • Extract _detect_logical_cpus() for logical CPU and governor detection
  • Extract _detect_numa_nodes() for NUMA topology parsing
  • Move _maybe_int() and _get_governor() to module level as utilities
  • Add comprehensive docstrings for all new functions
  • Fix PEP8 line length violations

Benefits:

  • Improved code readability and maintainability
  • Better testability with focused, single-responsibility functions
  • Easier debugging by isolating CPU detection aspects
  • Reduced cyclomatic complexity from one large function

All existing tests pass (24/24) and PEP8 compliance maintained.

CPU detection output is identical to previous implementation.

Assisted-By: Claude Opus 4.6

Break down the 143-line monolithic get_cpus() function into 6 smaller,
focused functions to improve maintainability and testability.

Changes:
- Extract _parse_lscpu_output() for lscpu command parsing
- Extract _detect_physical_cpus() for socket and CPU properties detection
- Extract _detect_logical_cpus() for logical CPU and governor detection
- Extract _detect_numa_nodes() for NUMA topology parsing
- Move _maybe_int() and _get_governor() to module level as utilities
- Add comprehensive docstrings for all new functions
- Fix PEP8 line length violations

Benefits:
- Improved code readability and maintainability
- Better testability with focused, single-responsibility functions
- Easier debugging by isolating CPU detection aspects
- Reduced cyclomatic complexity from one large function

All existing tests pass (24/24) and PEP8 compliance maintained.

CPU detection output is identical to previous implementation.

Assisted-By: Claude Opus 4.6
@elfosardo elfosardo changed the title Refactor get_cpus() function into focused single-responsibility funct… Refactor get_cpus() function into single-responsibility functions Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant