From a916e5494800cb4b9bd3377800bbeb780d2e65f7 Mon Sep 17 00:00:00 2001 From: Julian-o Date: Sun, 10 Sep 2023 03:15:07 +1000 Subject: [PATCH] Simplify check_requirements 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. --- buildozer/targets/android.py | 16 ++++++++-------- tests/targets/test_android.py | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/buildozer/targets/android.py b/buildozer/targets/android.py index b77cb279e..932bb2fbb 100644 --- a/buildozer/targets/android.py +++ b/buildozer/targets/android.py @@ -302,14 +302,14 @@ 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) diff --git a/tests/targets/test_android.py b/tests/targets/test_android.py index a3db75825..5b1546696 100644 --- a/tests/targets/test_android.py +++ b/tests/targets/test_android.py @@ -1,4 +1,5 @@ import os +import os.path import tempfile from io import StringIO from unittest import mock @@ -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 == [ @@ -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"].startswith( + os.path.join( + target_android.apache_ant_dir, "bin") + ) def test_check_configuration_tokens(self): """Basic tests for the check_configuration_tokens() method."""