Skip to content

Commit

Permalink
Simplify check_requirements
Browse files Browse the repository at this point in the history
Assume env var has a path.
Use os.pathsep (not to be confused with os.path.sep) instead of magic string.

Update test to ensure assumption is correct, and check ANT path has been prepended to the path var.
  • Loading branch information
Julian-O committed Sep 9, 2023
1 parent ca206d5 commit e763617
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 7 additions & 8 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,13 @@ def check_requirements(self):
"app", "android.adb_args", "")
self.adb_args = shlex.split(adb_args)

# Need to add internally installed ant to path for external tools
# like adb to use
path = [join(self.apache_ant_dir, 'bin')]
if 'PATH' in self.buildozer.environ:
path.append(self.buildozer.environ['PATH'])
else:
path.append(os.environ['PATH'])
self.buildozer.environ['PATH'] = ':'.join(path)
# Need to add internally-installed ant to path for external tools
# (like adb) to use
self.buildozer.environ['PATH'] = os.pathsep.join(
join(self.apache_ant_dir, 'bin'),
self.buildozer.environ['PATH'],
)

buildops.checkbin('Git (git)', 'git')
buildops.checkbin('Cython (cython)', 'cython')
buildops.checkbin('Java compiler (javac)', self.javac_cmd)
Expand Down
8 changes: 6 additions & 2 deletions tests/targets/test_android.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import os.path
import tempfile
from io import StringIO
from unittest import mock
Expand Down Expand Up @@ -153,7 +154,7 @@ def test_check_requirements(self):
assert not hasattr(target_android, "adb_executable")
assert not hasattr(target_android, "adb_args")
assert not hasattr(target_android, "javac_cmd")
del buildozer.environ["PATH"]
assert "PATH" in buildozer.environ
with patch_buildops_checkbin() as m_checkbin:
target_android.check_requirements()
assert m_checkbin.call_args_list == [
Expand All @@ -166,7 +167,10 @@ def test_check_requirements(self):
assert target_android.adb_args == []
assert target_android.javac_cmd == "javac"
assert target_android.keytool_cmd == "keytool"
assert "PATH" in buildozer.environ
assert buildozer.environ["PATH"].starts_with(
os.path.join(
target_android.apache_ant_dir, "bin")
)

def test_check_configuration_tokens(self):
"""Basic tests for the check_configuration_tokens() method."""
Expand Down

0 comments on commit e763617

Please sign in to comment.