Skip to content

Commit

Permalink
fix target osx
Browse files Browse the repository at this point in the history
  • Loading branch information
Furtif committed Jul 26, 2022
1 parent 25622a6 commit 66bfd2b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
3 changes: 3 additions & 0 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ def check_application_requirements(self):
self.state['cache.applibs'] = requirements

def _install_application_requirement(self, module):
if 'osx' in '{}'.format(self.target):
return

self._ensure_virtualenv()
self.debug('Install requirement {} in virtualenv'.format(module))
self.cmd(
Expand Down
59 changes: 38 additions & 21 deletions buildozer/targets/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'''

import sys

if sys.platform != 'darwin':
raise NotImplementedError('This will only work on osx')

Expand All @@ -19,15 +20,15 @@ def ensure_sdk(self):
if exists(
join(self.buildozer.platform_dir, 'kivy-sdk-packager-master')):
self.buildozer.info(
'kivy-sdk-packager found at '
'kivy-sdk-packager found at '
'{}'.format(self.buildozer.platform_dir))
return

self.buildozer.info('kivy-sdk-packager does not exist, clone it')
platdir = self.buildozer.platform_dir
check_call(
('curl', '-O', '-L',
'https://github.com/kivy/kivy-sdk-packager/archive/master.zip'),
'https://github.com/kivy/kivy-sdk-packager/archive/master.zip'),
cwd=platdir)
check_call(('unzip', 'master.zip'), cwd=platdir)
check_call(('rm', 'master.zip'), cwd=platdir)
Expand All @@ -39,15 +40,15 @@ def download_kivy(self, cwd, py_branch=2):
self.buildozer.info('Kivy found in Applications dir...')
check_call(
('cp', '-a', '/Applications/Kivy{}.app'.format(py_branch),
'Kivy.app'), cwd=cwd)
'Kivy.app'), cwd=cwd)

else:
if not exists(join(cwd, 'Kivy{}.dmg'.format(py_branch))):
self.buildozer.info('Downloading kivy...')
status_code = check_output(
('curl', '-L', '--write-out', '%{http_code}', '-o', 'Kivy{}.dmg'.format(py_branch),
'https://kivy.org/downloads/{}/Kivy-{}-osx-python{}.dmg'
.format(current_kivy_vers, current_kivy_vers, py_branch)),
'https://kivy.org/downloads/{}/Kivy.dmg' # -{}-osx-python{}.dmg'
.format(current_kivy_vers)), # , current_kivy_vers, py_branch)),
cwd=cwd)

if status_code == "404":
Expand Down Expand Up @@ -85,12 +86,25 @@ def check_configuration_tokens(self, errors=None):
self.buildozer.info('Check target configuration tokens')
self.buildozer.error(
'{0} error(s) found in the buildozer.spec'.format(
len(errors)))
len(errors)))
for error in errors:
print(error)
sys.exit(1)
# check

def _install_application_requirement(self, module):
self.buildozer._ensure_virtualenv()
if 'osx' in '{}'.format(self.buildozer.target):
if 'kivy' in '{}'.format(module) or 'buildozer' in '{}'.format(module):
self.buildozer.debug('Install requirement {} in virtualenv ignored for target: osx'.format(module))
return

self.buildozer.debug('Install requirement {} in virtualenv'.format(module))
cwd = join(self.buildozer.platform_dir, 'kivy-sdk-packager-master', 'osx')
self.buildozer.cmd(['Kivy.app/Contents/Resources/script', '-m', 'pip', 'install', '--upgrade', 'pip'], cwd=cwd)
self.buildozer.cmd(['Kivy.app/Contents/Resources/script', '-m', 'pip', 'install', '--upgrade', '--force-reinstall', '--target={}/_applibs'.format(self.buildozer.app_dir), '{}'.format(module)],
cwd=cwd)

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

Expand All @@ -99,31 +113,34 @@ def build_package(self):
package_name = bcg('app', 'package.name')
domain = bcg('app', 'package.domain')
title = bcg('app', 'title')
app_deps = open('requirements.txt').read()
source = bcg('app', 'source.dir')
app_deps = None
if exists('{}/requirements.txt'.format(source)):
app_deps = open('{}/requirements.txt'.format(self.buildozer.app_dir)).read()
# remove # from app_deps
app_deps = [a for a in app_deps.split('\n') if not a.startswith('#')]
icon = bc.getdefault('app', 'icon.filename', '')
if source in icon:
icon = '{}'.format(icon).replace('{}'.format(source), '{}'.format(self.buildozer.app_dir))
version = self.buildozer.get_version()
author = bc.getdefault('app', 'author', '')

self.buildozer.info('Create {}.app'.format(package_name))
self.buildozer.mkdir('{}/_applibs'.format(self.buildozer.app_dir))
cwd = join(self.buildozer.platform_dir, 'kivy-sdk-packager-master', 'osx')
# remove kivy from app_deps
app_deps = [a for a in app_deps.split('\n') if not a.startswith('#') and a not in ['kivy', '']]

cmd = [
'Kivy.app/Contents/Resources/script',
'-m', 'pip', 'install',
]
cmd.extend(app_deps)
check_output(cmd, cwd=cwd)
if app_deps is not None:
for dep in app_deps:
self._install_application_requirement(dep.replace('>', '='))

cmd = [
'python', 'package_app.py', self.buildozer.app_dir,
'--appname={}'.format(package_name),
'--bundlename={}'.format(title),
'--bundleid={}'.format(domain),
'--bundleversion={}'.format(version),
'--displayname={}'.format(title)
]
'--bundlename={}'.format(title),
'--bundleid={}'.format(domain),
'--bundleversion={}'.format(version),
'--displayname={}'.format(title)
]
if icon:
cmd.append('--icon={}'.format(icon))
if author:
Expand All @@ -134,7 +151,7 @@ def build_package(self):
self.buildozer.info('{}.app created.'.format(package_name))
self.buildozer.info('Creating {}.dmg'.format(package_name))
check_output(
('sh', '-x', 'create-osx-dmg.sh', package_name + '.app'),
('sh', '-x', 'create-osx-dmg.sh', package_name + '.app', package_name),
cwd=cwd)
self.buildozer.info('{}.dmg created'.format(package_name))
self.buildozer.info('moving {}.dmg to bin.'.format(package_name))
Expand Down

0 comments on commit 66bfd2b

Please sign in to comment.