MCPcopy Index your code
hub / github.com/kivy/python-for-android / binary_is_usable

Function binary_is_usable

pythonforandroid/pythonpackage.py:144–167  ·  view source on GitHub ↗

Helper function to see if a given binary name refers to a usable python interpreter binary

(python_bin)

Source from the content-addressed store, hash-verified

142
143 def python_binary_from_folder(path):
144 def binary_is_usable(python_bin):
145 """ Helper function to see if a given binary name refers
146 to a usable python interpreter binary
147 """
148
149 # Abort if path isn't present at all or a directory:
150 if not os.path.exists(
151 os.path.join(path, python_bin)
152 ) or os.path.isdir(os.path.join(path, python_bin)):
153 return
154 # We should check file not found anyway trying to run it,
155 # since it might be a dead symlink:
156 try:
157 filenotfounderror = FileNotFoundError
158 except NameError: # Python 2
159 filenotfounderror = OSError
160 try:
161 # Run it and see if version output works with no error:
162 subprocess.check_output([
163 os.path.join(path, python_bin), "--version"
164 ], stderr=subprocess.STDOUT)
165 return True
166 except (subprocess.CalledProcessError, filenotfounderror):
167 return False
168
169 python_name = "python" + sys.version
170 while (not binary_is_usable(python_name) and

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected