Skip to content

Commit

Permalink
Clean up inheritance of targets (#1690)
Browse files Browse the repository at this point in the history
1) Target class contained Android-only attribute "artifact_format". Moved that code into TargetAndroid class.

2) TargetIos had a `check_build_prepared()` method that was ineffective.

`prepare_for_build()` sets `target._build_prepared` to True.
Then `check_build_prepared()` inexplicably set it to False.
Then `build()` checks for its existence, rather than its value [this is code smell that is on my list for later], so the fact that it had been changed made no difference.

So, I removed the method, and the call to it.

2) TargetOSX had lots of methods that were identical to its base class implementations (three more, once the above steps were done). They don't need to be specified; they are inherited. I removed them. `osx.py` is now 20% smaller.
  • Loading branch information
Julian-O authored Sep 10, 2023
1 parent 7dbfeae commit f633b15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 57 deletions.
3 changes: 0 additions & 3 deletions buildozer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Target:
def __init__(self, buildozer):
self.buildozer = buildozer
self.build_mode = 'debug'
self.artifact_format = 'apk'
self.platform_update = False
self.logger = Logger()

Expand Down Expand Up @@ -106,7 +105,6 @@ def cmd_update(self, *args):
def cmd_debug(self, *args):
self.buildozer.prepare_for_build()
self.build_mode = 'debug'
self.artifact_format = self.buildozer.config.getdefault('app', 'android.debug_artifact', 'apk')
self.buildozer.build()

def cmd_release(self, *args):
Expand Down Expand Up @@ -143,7 +141,6 @@ def cmd_release(self, *args):
exit(1)

self.build_mode = 'release'
self.artifact_format = self.buildozer.config.getdefault('app', 'android.release_artifact', 'aab')
self.buildozer.build()

def cmd_deploy(self, *args):
Expand Down
11 changes: 11 additions & 0 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class TargetAndroid(Target):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.artifact_format = 'apk'

if self.buildozer.config.has_option(
"app", "android.arch"
) and not self.buildozer.config.has_option("app", "android.archs"):
Expand Down Expand Up @@ -989,6 +992,14 @@ def check_p4a_sign_env(self, error=False):
check = False
return check

def cmd_debug(self, *args):
self.artifact_format = self.buildozer.config.getdefault('app', 'android.debug_artifact', 'apk')
super().cmd_debug(*args)

def cmd_release(self, *args):
self.artifact_format = self.buildozer.config.getdefault('app', 'android.release_artifact', 'aab')
super().cmd_release(*args)

def cmd_run(self, *args):
entrypoint = self.buildozer.config.getdefault(
'app', 'android.entrypoint')
Expand Down
54 changes: 0 additions & 54 deletions buildozer/targets/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ def check_requirements(self):
self.ensure_sdk()
self.ensure_kivyapp()

def check_configuration_tokens(self, errors=None):
if errors:
self.logger.info('Check target configuration tokens')
self.logger.error(
'{0} error(s) found in the buildozer.spec'.format(
len(errors)))
for error in errors:
print(error)
sys.exit(1)
# check

def build_package(self):
self.logger.info('Building package')

Expand Down Expand Up @@ -147,9 +136,6 @@ def build_package(self):
binpath)
self.logger.info('All Done!')

def compile_platform(self):
pass

def install_platform(self):
# ultimate configuration check.
# some of our configuration cannot be checked without platform.
Expand All @@ -159,16 +145,6 @@ def install_platform(self):
'PACKAGES_PATH': self.buildozer.global_packages_dir,
})

def get_custom_commands(self):
result = []
for x in dir(self):
if not x.startswith('cmd_'):
continue
if x[4:] in self.buildozer.standard_cmds:
continue
result.append((x[4:], getattr(self, x).__doc__))
return result

def get_available_packages(self):
return ['kivy', 'python3']

Expand Down Expand Up @@ -212,36 +188,6 @@ def run_commands(self, args):

func(args)

def check_build_prepared(self):
self._build_prepared = False

def cmd_clean(self, *args):
self.buildozer.clean_platform()

def cmd_update(self, *args):
self.platform_update = True
self.buildozer.prepare_for_build()

def cmd_debug(self, *args):
self.buildozer.prepare_for_build()
self.build_mode = 'debug'
self.check_build_prepared()
self.buildozer.build()

def cmd_release(self, *args):
self.buildozer.prepare_for_build()
self.build_mode = 'release'
self.buildozer.build()

def cmd_deploy(self, *args):
self.buildozer.prepare_for_build()

def cmd_run(self, *args):
self.buildozer.prepare_for_build()

def cmd_serve(self, *args):
self.buildozer.cmd_serve()


def get_target(buildozer):
return TargetOSX(buildozer)

0 comments on commit f633b15

Please sign in to comment.