From 419288c3e6b7e947273c707e6c596fe35eaf2f22 Mon Sep 17 00:00:00 2001 From: Ryan Pessa Date: Tue, 12 Jan 2016 10:30:34 -0600 Subject: [PATCH] add basic env-based overrides for recipe version and url --- pythonforandroid/build.py | 7 ++++++- pythonforandroid/recipe.py | 29 +++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index cd4f8e42f6..d7a052f3c7 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -585,7 +585,12 @@ def run_pymodules_install(ctx, modules): info('Creating a requirements.txt file for the Python modules') with open('requirements.txt', 'w') as fileh: for module in modules: - fileh.write('{}\n'.format(module)) + key = 'VERSION_' + module + if key in environ: + line = '{}=={}\n'.format(module, environ[key]) + else: + line = '{}\n'.format(module) + fileh.write(line) info('Installing Python modules with pip') info('If this fails with a message about /bin/false, this ' diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py index 9b93d489f3..9723bf7fe3 100644 --- a/pythonforandroid/recipe.py +++ b/pythonforandroid/recipe.py @@ -2,7 +2,7 @@ import importlib import zipfile import glob -from six import PY2 +from six import PY2, with_metaclass import sh import shutil @@ -37,8 +37,19 @@ def import_recipe(module, filename): return SourceFileLoader(module, filename).load_module() -class Recipe(object): - url = None +class RecipeMeta(type): + def __new__(cls, name, bases, dct): + if name != 'Recipe': + if 'url' in dct: + dct['_url'] = dct.pop('url') + if 'version' in dct: + dct['_version'] = dct.pop('version') + + return super(RecipeMeta, cls).__new__(cls, name, bases, dct) + + +class Recipe(with_metaclass(RecipeMeta)): + _url = None '''The address from which the recipe may be downloaded. This is not essential, it may be omitted if the source is available some other way, such as via the :class:`IncludedFilesBehaviour` mixin. @@ -52,7 +63,7 @@ class Recipe(object): if you want. ''' - version = None + _version = None '''A string giving the version of the software the recipe describes, e.g. ``2.0.3`` or ``master``.''' @@ -88,6 +99,16 @@ class Recipe(object): archs = ['armeabi'] # Not currently implemented properly + @property + def version(self): + key = 'VERSION_' + self.name + return environ.get(key, self._version) + + @property + def url(self): + key = 'URL_' + self.name + return environ.get(key, self._url) + @property def versioned_url(self): '''A property returning the url of the recipe with ``{version}``