Skip to content

Commit

Permalink
Refactor checkbin to use shutil.which (#1628)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Julian-O authored Jul 8, 2023
1 parent 98177c0 commit 0851a10
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 0851a10

Please sign in to comment.