22import importlib
33import zipfile
44import glob
5- from six import PY2
5+ from six import PY2 , with_metaclass
66
77import sh
88import shutil
@@ -37,8 +37,19 @@ def import_recipe(module, filename):
3737 return SourceFileLoader (module , filename ).load_module ()
3838
3939
40- class Recipe (object ):
41- url = None
40+ class RecipeMeta (type ):
41+ def __new__ (cls , name , bases , dct ):
42+ if name != 'Recipe' :
43+ if 'url' in dct :
44+ dct ['_url' ] = dct .pop ('url' )
45+ if 'version' in dct :
46+ dct ['_version' ] = dct .pop ('version' )
47+
48+ return super (RecipeMeta , cls ).__new__ (cls , name , bases , dct )
49+
50+
51+ class Recipe (with_metaclass (RecipeMeta )):
52+ _url = None
4253 '''The address from which the recipe may be downloaded. This is not
4354 essential, it may be omitted if the source is available some other
4455 way, such as via the :class:`IncludedFilesBehaviour` mixin.
@@ -52,7 +63,7 @@ class Recipe(object):
5263 if you want.
5364 '''
5465
55- version = None
66+ _version = None
5667 '''A string giving the version of the software the recipe describes,
5768 e.g. ``2.0.3`` or ``master``.'''
5869
@@ -88,6 +99,16 @@ class Recipe(object):
8899
89100 archs = ['armeabi' ] # Not currently implemented properly
90101
102+ @property
103+ def version (self ):
104+ key = 'VERSION_' + self .name
105+ return environ .get (key , self ._version )
106+
107+ @property
108+ def url (self ):
109+ key = 'URL_' + self .name
110+ return environ .get (key , self ._url )
111+
91112 @property
92113 def versioned_url (self ):
93114 '''A property returning the url of the recipe with ``{version}``
0 commit comments