<commit_before>'''
OSX target, based on kivy-sdk-packager
'''

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

#Global variables

#Global imports
import traceback
import os
import io
from pipes import quote
from sys import platform, executable
from buildozer import BuildozerException
from buildozer import IS_PY3
from buildozer.target import Target
from os import environ
from os.path import (exists, join, realpath, expanduser,
    basename, relpath, abspath, dirname)
from shutil import copyfile
from glob import glob
from subprocess import check_call, check_output

from buildozer.libs.version import parse


class TargetOSX(Target):

    def ensure_sdk(self):
        self.buildozer.info('Check if kivy-sdk-packager exists')
        if exists(
            join(self.buildozer.platform_dir, 'kivy-sdk-packager-master')):
            self.buildozer.info(
                    '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'),
            cwd=platdir)
        check_call(('unzip', 'master.zip'), cwd=platdir)
        check_call(('rm', 'master.zip'), cwd=platdir)

    def download_kivy(self, cwd, kivy='Kivy2'):
        self.buildozer.info('Downloading kivy...')
        if not exists(cwd+'/'+kivy+'.7z'):
            check_call(
                ('curl', '-O', '-L',
                'http://kivy.org/downloads/tests/{}.7z'.format(kivy)),
                cwd=cwd)
        if not exists(cwd+'/Keka.app'):
            if exists('/Applications/Keka.app'):
                check_call(
                    ('cp', '-a', '/Applications/Keka.app', './Keka.app'),
                     cwd=cwd)
            else:
                check_call(('curl', '-o',
                    'http://www.kekaosx.com/release/Keka-1.0.4-intel.dmg'),
                    cwd=cwd)
                check_call(
                    ('hdiutil', 'attach', 'Keka-1.0.4-intel.dmg'),
                    cwd=cwd)
                check_call(
                    ('cp', '-a','/Volumes/Keka/Keka.app',
                    './Keka.app'), cwd=cwd)
                check_call(('hdutil', 'detach', '/Volumes/Keka'))
        check_call(
            ('Keka.app/Contents/Resources/keka7z',
            'x', '{}.7z'.format(kivy)), cwd=cwd)
        check_call(('rm', '-rf', '{}.7z'.format('Kivy2')), cwd=cwd)
        check_call(('mv', '{}.app'.format(kivy), 'Kivy.app'),cwd=cwd)

    def ensure_kivyapp(self):
        self.buildozer.info('check if Kivy.app exists in local dir')
        kivy_app_dir = join(
            self.buildozer.platform_dir,
            'kivy-sdk-packager-master', 'osx')
        if exists(join(kivy_app_dir, 'Kivy.app')):
                self.buildozer.info('Kivy.app found at ' + kivy_app_dir)
                return
        # check if Kivy.app exists in /Applications
        if not exists('/Applications/Kivy.app'):
            self.download_kivy(kivy_app_dir)
            return
        else:
            self.buildozer.info('Kivy.app found at /Applications/Kivy.app')
            self.buildozer.info('copying it to platform dir')
            check_call(
                ('cp', '-a', '/Applications/Kivy.app',
                join(kivy_app_dir, 'Kivy.app')))
        return

    def check_requirements(self):
        self.ensure_sdk()
        self.ensure_kivyapp()

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

    def build_package(self):
        self.buildozer.info('Building package')
        kivy_app_dir = join(
            self.buildozer.platform_dir,
            'kivy-sdk-packager-master', 'osx', 'Kivy.app')

        bc = self.buildozer.config
        bcg = bc.get
        bcgl = bc.getlist
        package_name = bcg('app', 'package.name')
        domain = bcg('app', 'package.domain')
        title = bcg('app', 'title')
        app_deps = bcgl('app', 'requirements', '')
        garden_deps = bcgl('app', 'garden_requirements', '')<commit_msg>trying to fix Kivy install for OS X builds<commit_after>'''
OSX target, based on kivy-sdk-packager
'''

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

#Global variables

#Global imports
import traceback
import os
import io
from pipes import quote
from sys import platform, executable
from buildozer import BuildozerException
from buildozer import IS_PY3
from buildozer.target import Target
from os import environ
from os.path import (exists, join, realpath, expanduser,
    basename, relpath, abspath, dirname)
from shutil import copyfile
from glob import glob
from subprocess import check_call, check_output

from buildozer.libs.version import parse


class TargetOSX(Target):

    def ensure_sdk(self):
        self.buildozer.info('Check if kivy-sdk-packager exists')
        if exists(
            join(self.buildozer.platform_dir, 'kivy-sdk-packager-master')):
            self.buildozer.info(
                    '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'),
            cwd=platdir)
        check_call(('unzip', 'master.zip'), cwd=platdir)
        check_call(('rm', 'master.zip'), cwd=platdir)

    def download_kivy(self, cwd, py_branch=2):
        current_kivy_vers = '1.9.1'

        if exists('/Applications/Kivy{}.app'.format(py_branch)):
            self.buildozer.info('Kivy found in Applications dir...')
            check_call(('cp', '-a', '/Applications/Kivy{}.app'.format(py_branch), 'Kivy.app'), cwd=cwd)

        else:

            if not exists(cwd+'/Kivy{}.7z'.format(py_branch)):
                self.buildozer.info('Downloading kivy...')
                check_call(('curl', '-L', '-o', 'Kivy{}.7z'.format(py_branch),
                    'http://kivy.org/downloads/{}/Kivy-{}-osx-python{}.7z'.format(current_kivy_vers, current_kivy_vers, py_branch)), cwd=cwd)

            if not  exists('/Applications/Keka.app'):
                self.buildozer.info('Downloading Keka as dependency (to install Kivy)')
                check_call(('curl', '-O', 'http://www.kekaosx.com/release/Keka-1.0.4-intel.dmg'), cwd=cwd)
                check_call( ('hdiutil', 'attach', 'Keka-1.0.4-intel.dmg'), cwd=cwd)
                check_call( ('cp', '-a','/Volumes/Keka/Keka.app', './Keka.app'), cwd=cwd)
                check_call(('hdiutil', 'detach', '/Volumes/Keka'))

            self.buildozer.info('Extracting and installing Kivy...')
            check_call(('/Applications/Keka.app/Contents/MacOS/Keka', cwd+'/Kivy{}.7z'.format(py_branch)), cwd=cwd)
            #check_call(('rm', '-rf', 'Kivy{}.7z'.format(py_branch)), cwd=cwd)
            check_call(('mv', 'Kivy{}.app'.format(py_branch), 'Kivy.app'),cwd=cwd)

    def ensure_kivyapp(self):
        self.buildozer.info('check if Kivy.app exists in local dir')
        kivy_app_dir = join(self.buildozer.platform_dir, 'kivy-sdk-packager-master', 'osx')

        py_branch = sys.version_info[0]

        if not py_branch in (2, 3):
            self.buildozer.error('incompatible python version... aborting')
            sys.exit(1)

        if exists(join(kivy_app_dir, 'Kivy.app')):
            self.buildozer.info('Kivy.app found at ' + kivy_app_dir)
        else:
            self.download_kivy(kivy_app_dir, py_branch)

        return

    def check_requirements(self):
        self.ensure_sdk()
        self.ensure_kivyapp()

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

    def build_package(self):
        self.buildozer.info('Building package')
        kivy_app_dir = join(
            self.buildozer.platform_dir,
            'kivy-sdk-packager-master', 'osx', 'Kivy.app')

        bc = self.buildozer.config
        bcg = bc.get
        bcgl = bc.getlist
        package_name = bcg('app', 'package.name')
        domain = bcg('app', 'package.domain')
        title = bcg('app', 'title')
        app_deps = bcgl('app', 'requirements', '')
        garden_deps = bcgl('app', 'garden_requirements', '')
{'fraction_non_alphanumeric': 0.14056136488717666, 'fraction_numerical': 0.004182718767198679, 'mean_word_length': 2.228855721393035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6477136', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2998, 'n_words': 580}