From a0e01f4223878e5895b270995eaa7bb468c4d0f5 Mon Sep 17 00:00:00 2001 From: Julian-o Date: Tue, 12 Sep 2023 01:35:56 +1000 Subject: [PATCH] Avoid hasattr pattern - define in __init__() instead --- buildozer/__init__.py | 12 +++++++----- buildozer/targets/android.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/buildozer/__init__.py b/buildozer/__init__.py index d82cce6df..635fa4c1c 100644 --- a/buildozer/__init__.py +++ b/buildozer/__init__.py @@ -40,6 +40,8 @@ def __init__(self, filename='buildozer.spec', target=None): self.build_id = None self.config = SpecParser() self._venv_created = False + self._build_prepared = False + self._build_done = False self.logger = Logger() @@ -77,7 +79,7 @@ def prepare_for_build(self): '''Prepare the build. ''' assert self.target is not None - if hasattr(self.target, '_build_prepared'): + if self._build_prepared: return self.logger.info('Preparing build') @@ -97,7 +99,7 @@ def prepare_for_build(self): self.target.compile_platform() # flag to prevent multiple build - self.target._build_prepared = True + self._build_prepared = True def build(self): '''Do the build. @@ -108,9 +110,9 @@ def build(self): (:meth:`prepare_for_build` must have been call before.) ''' assert self.target is not None - assert hasattr(self.target, '_build_prepared') + assert self._build_prepared - if hasattr(self.target, '_build_done'): + if self._build_done: return # increment the build number @@ -124,7 +126,7 @@ def build(self): self.target.build_package() # flag to prevent multiple build - self.target._build_done = True + self._build_done = True def check_configuration_tokens(self): '''Ensure the spec file is 'correct'. diff --git a/buildozer/targets/android.py b/buildozer/targets/android.py index f87c616ac..6b419527f 100644 --- a/buildozer/targets/android.py +++ b/buildozer/targets/android.py @@ -74,6 +74,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.artifact_format = 'apk' + self._serials = None if self.buildozer.config.has_option( "app", "android.arch" @@ -1405,7 +1406,7 @@ def _update_libraries_references(self, dist_dir): @property def serials(self): - if hasattr(self, '_serials'): + if self._serials is not None: return self._serials serial = environ.get('ANDROID_SERIAL') if serial: