[dnf/python_helper] Optimize dnf_command to reduce shell_outs#15718
Merged
Conversation
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>
|
jaymzh
approved these changes
Mar 24, 2026
11 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Replace
which(with block) withwhere+findin dnf_command.The old implementation passed a shell_out block to
which, which internally callswhere. Thewheremethod 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
wherewithout a block to cheaply collect all valid executables via filesystem checks, then usesfindto stop at the first one that can successfullyimport dnf.Types of changes
Checklist:
Gemfile.lockhas changed, I have used--conservativeto do it and included the full output in the Description above.