Skip to content

[dnf/python_helper] Optimize dnf_command to reduce shell_outs#15718

Merged
jaymzh merged 1 commit into
chef:mainfrom
dafyddcrosby:python_dnf_command_helper
Mar 25, 2026
Merged

[dnf/python_helper] Optimize dnf_command to reduce shell_outs#15718
jaymzh merged 1 commit into
chef:mainfrom
dafyddcrosby:python_dnf_command_helper

Conversation

@dafyddcrosby
Copy link
Copy Markdown
Contributor

@dafyddcrosby dafyddcrosby commented Mar 18, 2026

Description

Replace which (with block) with where + find in dnf_command.

The old implementation passed a shell_out block to which, which internally calls where. The where method iterates ALL cmd/path combinations and runs the block for every executable found on disk, even after a match is found.

The new implementation calls where without a block to cheaply collect all valid executables via filesystem checks, then uses find to stop at the first one that can successfully import dnf.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • If Gemfile.lock has changed, I have used --conservative to do it and included the full output in the Description above.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

Replace `which` (with block) with `where` + `find` in dnf_command.

The old implementation passed a shell_out block to `which`, which
internally calls `where`. The `where` method iterates ALL cmd/path
combinations and runs the block for every executable found on disk,
even after a match is found.

The new implementation calls `where` without a block to cheaply
collect all valid executables via filesystem checks, then uses `find`
to stop at the first one that can successfully `import dnf`.

Signed-off-by: David Crosby <dcrosby@fb.com>
@sonarqubecloud
Copy link
Copy Markdown

@dafyddcrosby dafyddcrosby marked this pull request as ready for review March 24, 2026 20:30
@dafyddcrosby dafyddcrosby requested review from a team and jaymzh as code owners March 24, 2026 20:30
@jaymzh jaymzh merged commit 2d6d2c2 into chef:main Mar 25, 2026
73 of 76 checks passed
neha-p6 pushed a commit that referenced this pull request Apr 24, 2026
Replace `which` (with block) with `where` + `find` in dnf_command.

The old implementation passed a shell_out block to `which`, which
internally calls `where`. The `where` method iterates ALL cmd/path
combinations and runs the block for every executable found on disk,
even after a match is found.

The new implementation calls `where` without a block to cheaply
collect all valid executables via filesystem checks, then uses `find`
to stop at the first one that can successfully `import dnf`.

Signed-off-by: David Crosby <dcrosby@fb.com>
Signed-off-by: neha-p6 <neha.pansare@progress.com>
neha-p6 added a commit that referenced this pull request Apr 24, 2026
#15971)

Replace `which` (with block) with `where` + `find` in dnf_command.

The old implementation passed a shell_out block to `which`, which
internally calls `where`. The `where` method iterates ALL cmd/path
combinations and runs the block for every executable found on disk,
even after a match is found.

The new implementation calls `where` without a block to cheaply
collect all valid executables via filesystem checks, then uses `find`
to stop at the first one that can successfully `import dnf`.

Signed-off-by: David Crosby <dcrosby@fb.com>
Signed-off-by: neha-p6 <neha.pansare@progress.com>
Co-authored-by: David T. Crosby <dcrosby@meta.com>
cinc-bot pushed a commit to cinc-project/chef that referenced this pull request May 17, 2026
…5718) (chef#15971)

Replace `which` (with block) with `where` + `find` in dnf_command.

The old implementation passed a shell_out block to `which`, which
internally calls `where`. The `where` method iterates ALL cmd/path
combinations and runs the block for every executable found on disk,
even after a match is found.

The new implementation calls `where` without a block to cheaply
collect all valid executables via filesystem checks, then uses `find`
to stop at the first one that can successfully `import dnf`.

Signed-off-by: David Crosby <dcrosby@fb.com>
Signed-off-by: neha-p6 <neha.pansare@progress.com>
Co-authored-by: David T. Crosby <dcrosby@meta.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants