• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kivy / python-for-android / 5976260269

25 Aug 2023 01:05PM UTC coverage: 58.986% (+0.3%) from 58.676%
5976260269

push

github

web-flow
Standardise `ensure_dir` and `rmdir` (#2871)

* Standardise ensure_dir and rmdir

* Standardise ensure_dir and rmdir

* Add libmysqlclient to broken list

* Libtorrent failing to be rebuilt

* Add boost to broken recipes list

940 of 2241 branches covered (0.0%)

Branch coverage included in aggregate %.

73 of 113 new or added lines in 21 files covered. (64.6%)

3 existing lines in 3 files now uncovered.

4715 of 7346 relevant lines covered (64.18%)

2.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pythonforandroid/bdistapk.py
NEW
1
from glob import glob
×
NEW
2
from os.path import realpath, join, dirname, curdir, basename, split
×
UNCOV
3
from setuptools import Command
×
NEW
4
from shutil import copyfile
×
5
import sys
×
6

NEW
7
from pythonforandroid.util import rmdir, ensure_dir
×
8

9

10
def argv_contains(t):
×
11
    for arg in sys.argv:
×
12
        if arg.startswith(t):
×
13
            return True
×
14
    return False
×
15

16

17
class Bdist(Command):
×
18

19
    user_options = []
×
20
    package_type = None
×
21

22
    def initialize_options(self):
×
23
        for option in self.user_options:
×
24
            setattr(self, option[0].strip('=').replace('-', '_'), None)
×
25

26
        option_dict = self.distribution.get_option_dict(self.package_type)
×
27

28
        # This is a hack, we probably aren't supposed to loop through
29
        # the option_dict so early because distutils does exactly the
30
        # same thing later to check that we support the
31
        # options. However, it works...
32
        for (option, (source, value)) in option_dict.items():
×
33
            setattr(self, option, str(value))
×
34

35
    def finalize_options(self):
×
36

37
        setup_options = self.distribution.get_option_dict(self.package_type)
×
38
        for (option, (source, value)) in setup_options.items():
×
39
            if source == 'command line':
×
40
                continue
×
41
            if not argv_contains('--' + option):
×
42
                # allow 'permissions': ['permission', 'permission] in apk
43
                if option == 'permissions':
×
44
                    for perm in value:
×
45
                        sys.argv.append('--permission={}'.format(perm))
×
46
                elif option == 'orientation':
×
47
                    for orient in value:
×
48
                        sys.argv.append('--orientation={}'.format(orient))
×
49
                elif value in (None, 'None'):
×
50
                    sys.argv.append('--{}'.format(option))
×
51
                else:
52
                    sys.argv.append('--{}={}'.format(option, value))
×
53

54
        # Inject some argv options from setup.py if the user did not
55
        # provide them
56
        if not argv_contains('--name'):
×
57
            name = self.distribution.get_name()
×
58
            sys.argv.append('--name="{}"'.format(name))
×
59
            self.name = name
×
60

61
        if not argv_contains('--package'):
×
62
            package = 'org.test.{}'.format(self.name.lower().replace(' ', ''))
×
63
            print('WARNING: You did not supply an Android package '
×
64
                  'identifier, trying {} instead.'.format(package))
65
            print('         This may fail if this is not a valid identifier')
×
66
            sys.argv.append('--package={}'.format(package))
×
67

68
        if not argv_contains('--version'):
×
69
            version = self.distribution.get_version()
×
70
            sys.argv.append('--version={}'.format(version))
×
71

72
        if not argv_contains('--arch'):
×
73
            arch = 'armeabi-v7a'
×
74
            self.arch = arch
×
75
            sys.argv.append('--arch={}'.format(arch))
×
76

77
    def run(self):
×
78
        self.prepare_build_dir()
×
79

80
        from pythonforandroid.entrypoints import main
×
81
        sys.argv[1] = self.package_type
×
82
        main()
×
83

84
    def prepare_build_dir(self):
×
85

86
        if argv_contains('--private') and not argv_contains('--launcher'):
×
87
            print('WARNING: Received --private argument when this would '
×
88
                  'normally be generated automatically.')
89
            print('         This is probably bad unless you meant to do '
×
90
                  'that.')
91

92
        bdist_dir = 'build/bdist.android-{}'.format(self.arch)
×
NEW
93
        rmdir(bdist_dir)
×
NEW
94
        ensure_dir(bdist_dir)
×
95

96
        globs = []
×
97
        for directory, patterns in self.distribution.package_data.items():
×
98
            for pattern in patterns:
×
99
                globs.append(join(directory, pattern))
×
100

101
        filens = []
×
102
        for pattern in globs:
×
103
            filens.extend(glob(pattern))
×
104

105
        main_py_dirs = []
×
106
        if not argv_contains('--launcher'):
×
107
            for filen in filens:
×
108
                new_dir = join(bdist_dir, dirname(filen))
×
NEW
109
                ensure_dir(new_dir)
×
110
                print('Including {}'.format(filen))
×
111
                copyfile(filen, join(bdist_dir, filen))
×
112
                if basename(filen) in ('main.py', 'main.pyc'):
×
113
                    main_py_dirs.append(filen)
×
114

115
        # This feels ridiculous, but how else to define the main.py dir?
116
        # Maybe should just fail?
117
        if not main_py_dirs and not argv_contains('--launcher'):
×
118
            print('ERROR: Could not find main.py, so no app build dir defined')
×
119
            print('You should name your app entry point main.py')
×
120
            exit(1)
×
121
        if len(main_py_dirs) > 1:
×
122
            print('WARNING: Multiple main.py dirs found, using the shortest path')
×
123
        main_py_dirs = sorted(main_py_dirs, key=lambda j: len(split(j)))
×
124

125
        if not argv_contains('--launcher'):
×
126
            sys.argv.append('--private={}'.format(
×
127
                join(realpath(curdir), bdist_dir, dirname(main_py_dirs[0])))
128
            )
129

130

131
class BdistAPK(Bdist):
×
132
    """distutil command handler for 'apk'."""
133
    description = 'Create an APK with python-for-android'
×
134
    package_type = 'apk'
×
135

136

137
class BdistAAR(Bdist):
×
138
    """distutil command handler for 'aar'."""
139
    description = 'Create an AAR with python-for-android'
×
140
    package_type = 'aar'
×
141

142

143
class BdistAAB(Bdist):
×
144
    """distutil command handler for 'aab'."""
145
    description = 'Create an AAB with python-for-android'
×
146
    package_type = 'aab'
×
147

148

149
def _set_user_options():
×
150
    # This seems like a silly way to do things, but not sure if there's a
151
    # better way to pass arbitrary options onwards to p4a
152
    user_options = [('requirements=', None, None), ]
×
153
    for i, arg in enumerate(sys.argv):
×
154
        if arg.startswith('--'):
×
155
            if ('=' in arg or
×
156
                    (i < (len(sys.argv) - 1) and not sys.argv[i+1].startswith('-'))):
157
                user_options.append((arg[2:].split('=')[0] + '=', None, None))
×
158
            else:
159
                user_options.append((arg[2:], None, None))
×
160

161
    BdistAPK.user_options = user_options
×
162
    BdistAAB.user_options = user_options
×
163
    BdistAAR.user_options = user_options
×
164

165

166
_set_user_options()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc