Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize get_executable func with list compr #2083

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Optimize get_executable func with list compr
  • Loading branch information
NinoRisteski committed Mar 18, 2025
commit fde9509c37068ab2f4d3362f28e98bda8bf54bdc
13 changes: 5 additions & 8 deletions unsloth/save.py
Original file line number Diff line number Diff line change
@@ -933,14 +933,11 @@ def get_executable(executables):
# Get system locations (System Path).split(system separator)
system_directories = os.environ.get("PATH").split(os.pathsep)

for directory in system_directories:
for executable in executables:
path = os.path.join(directory, executable)
# Check if the executable exists and is executable
if os.path.exists(path) and os.access(path, os.X_OK): return path
pass
pass
return None
found_executables = [os.path.join(path, executable)
for path in system_directories
for executable in executables
if os.path.exists(os.path.join(path, executable)) and os.access(os.path.join(path, executable), os.X_OK)]
return found_executables[0] if found_executables else None
pass