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

Refactor checkbin to use shutil.which #1628

Merged
merged 1 commit into from
Jul 8, 2023
Merged
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
Refactor checkbin to use shutil.which
checkbin used custom code to find where a binary is on the path.
shutil.which is a built-in to do the same thing since Python 3.3.
Simpler and works across platforms.
Julian-O committed Jul 6, 2023
commit 9ac32808aa599b0e0635dd00da1467f13720a134
13 changes: 5 additions & 8 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
from subprocess import Popen, PIPE, TimeoutExpired
from os import environ, unlink, walk, sep, listdir, makedirs
from copy import copy
from shutil import copyfile, rmtree, copytree, move
from shutil import copyfile, rmtree, copytree, move, which
from fnmatch import fnmatch

from pprint import pformat
@@ -243,13 +243,10 @@ def error(self, msg):

def checkbin(self, msg, fn):
self.debug('Search for {0}'.format(msg))
if exists(fn):
return realpath(fn)
for dn in environ['PATH'].split(':'):
rfn = realpath(join(dn, fn))
if exists(rfn):
self.debug(' -> found at {0}'.format(rfn))
return rfn
executable_location = which(fn)
if executable_location:
self.debug(' -> found at {0}'.format(executable_location))
return realpath(executable_location)
self.error('{} not found, please install it.'.format(msg))
exit(1)