Skip to content

Commit

Permalink
Avoid hasattr pattern - define in __init__() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian-O committed Sep 11, 2023
1 parent 40fbf38 commit a0e01f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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')
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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'.
Expand Down
3 changes: 2 additions & 1 deletion buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a0e01f4

Please sign in to comment.