Skip to content

Commit 1b5495c

Browse files
committed
Improved Distribution.get_distribution api
1 parent c49f5f3 commit 1b5495c

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

pythonforandroid/distribution.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ def __repr__(self):
4242
return str(self)
4343

4444
@classmethod
45-
def get_distribution(cls, ctx, name=None, recipes=[],
46-
ndk_api=None,
47-
arch_name=None,
48-
force_build=False,
49-
extra_dist_dirs=[],
50-
require_perfect_match=False,
51-
allow_replace_dist=True):
45+
def get_distribution(
46+
cls,
47+
ctx,
48+
*,
49+
arch_name, # required keyword argument: there is no sensible default
50+
name=None,
51+
recipes=[],
52+
ndk_api=None,
53+
force_build=False,
54+
extra_dist_dirs=[],
55+
require_perfect_match=False,
56+
allow_replace_dist=True
57+
):
5258
'''Takes information about the distribution, and decides what kind of
5359
distribution it will be.
5460
@@ -67,6 +73,7 @@ def get_distribution(cls, ctx, name=None, recipes=[],
6773
arch_name : str
6874
The target architecture name to compile against, included in the dist because
6975
it cannot be changed later during APK packaging.
76+
This is a required, keyword-only argument.
7077
recipes : list
7178
The recipes that the distribution must contain.
7279
force_download: bool
@@ -97,12 +104,13 @@ def get_distribution(cls, ctx, name=None, recipes=[],
97104
d for d in possible_dists if
98105
(d.name == name) and (arch_name in d.archs)]
99106

100-
# There should only be one folder with a given dist name *and* arch.
101-
# We could check that here, but for compatibility let's let it slide
102-
# and just record the details of one of them. We only use this data to
103-
# possibly fail the build later, so it doesn't really matter if there
104-
# was more than one clash.
105-
folder_match_dist = possible_dists[0]
107+
if possible_dists:
108+
# There should only be one folder with a given dist name *and* arch.
109+
# We could check that here, but for compatibility let's let it slide
110+
# and just record the details of one of them. We only use this data to
111+
# possibly fail the build later, so it doesn't really matter if there
112+
# was more than one clash.
113+
folder_match_dist = possible_dists[0]
106114

107115
# 1) Check if any existing dists meet the requirements
108116
_possible_dists = []
@@ -155,7 +163,7 @@ def get_distribution(cls, ctx, name=None, recipes=[],
155163
req_recipes=', '.join(recipes),
156164
dist_recipes=', '.join(folder_match_dist.recipes)))
157165

158-
assert len(folder_match_dist) < 2
166+
assert len(possible_dists) < 2
159167

160168
# If we got this far, we need to build a new dist
161169
dist = Distribution(ctx)
@@ -171,7 +179,10 @@ def get_distribution(cls, ctx, name=None, recipes=[],
171179
dist.name = name
172180
dist.dist_dir = join(
173181
ctx.dist_dir,
174-
generate_dist_folder_name(name, [arch_name])
182+
generate_dist_folder_name(
183+
name,
184+
[arch_name] if arch_name is not None else None,
185+
)
175186
)
176187
dist.recipes = recipes
177188
dist.ndk_api = ctx.ndk_api
@@ -258,6 +269,7 @@ def pretty_log_dists(dists, log_func=info):
258269
for line in infos:
259270
log_func('\t' + line)
260271

272+
261273
def generate_dist_folder_name(base_dist_name, arch_names=None):
262274
"""Generate the distribution folder name to use, based on a
263275
combination of the input arguments.

0 commit comments

Comments
 (0)