Skip to content

Commit 30cbb96

Browse files
committed
Possibly-silly function composition for patching
1 parent 90f681b commit 30cbb96

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

pythonforandroid/patching.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
from os import uname
22

3+
class ComposableFunction(object):
4+
def __init__(self, function):
5+
self.func = function
6+
7+
def __call__(self, *args, **kwargs):
8+
return self.func(*args, **kwargs)
9+
10+
def __and__(self, f):
11+
return ComposableFunction(lambda *args, **kwargs: self(*args, **kwargs) and f(*args, **kwargs))
12+
13+
def __or__(self, f):
14+
return ComposableFunction(lambda *args, **kwargs: self(*args, **kwargs) or f(*args, **kwargs))
15+
316

417
def check_all(*callables):
518
def check(**kwargs):
619
return all(c(**kwargs) for c in callables)
7-
return check
20+
return ComposableFunction(check)
821

922

1023
def check_any(*callables):
1124
def check(**kwargs):
1225
return any(c(**kwargs) for c in callables)
13-
return check
26+
return ComposableFunction(check)
1427

1528

1629
def is_platform(platform):
1730
def is_x(**kwargs):
1831
return uname()[0] == platform
19-
return is_x
32+
return ComposableFunction(is_x)
2033

2134
is_linux = is_platform('Linux')
2235
is_darwin = is_platform('Darwin')
@@ -25,43 +38,43 @@ def is_x(**kwargs):
2538
def is_arch(xarch):
2639
def is_x(arch, **kwargs):
2740
return arch.arch == xarch
28-
return is_x
41+
return ComposableFunction(is_x)
2942

3043

3144
def is_api_gt(apiver):
3245
def is_x(recipe, **kwargs):
3346
return recipe.ctx.android_api > apiver
34-
return is_x
47+
return ComposableFunction(is_x)
3548

3649

3750
def is_api_gte(apiver):
3851
def is_x(recipe, **kwargs):
3952
return recipe.ctx.android_api >= apiver
40-
return is_x
53+
return ComposableFunction(is_x)
4154

4255

4356
def is_api_lt(apiver):
4457
def is_x(recipe, **kwargs):
4558
return recipe.ctx.android_api < apiver
46-
return is_x
59+
return ComposableFunction(is_x)
4760

4861

4962
def is_api_lte(apiver):
5063
def is_x(recipe, **kwargs):
5164
return recipe.ctx.android_api <= apiver
52-
return is_x
65+
return ComposableFunction(is_x)
5366

5467

5568
def is_api(apiver):
5669
def is_x(recipe, **kwargs):
5770
return recipe.ctx.android_api == apiver
58-
return is_x
71+
return ComposableFunction(is_x)
5972

6073

6174
def will_build(recipe_name):
6275
def will(recipe, **kwargs):
6376
return recipe_name in recipe.ctx.recipe_build_order
64-
return will
77+
return ComposableFunction(will)
6578

6679

6780
def is_ndk(ndk):

0 commit comments

Comments
 (0)