@@ -727,12 +727,42 @@ class PythonRecipe(Recipe):
727727 setup_extra_args = []
728728 '''List of extra arguments to pass to setup.py'''
729729
730+ depends = [('python2' , 'python3' )]
731+ '''
732+ .. note:: it's important to keep this depends as a class attribute, outside
733+ `__init__` because, sometimes, we only initialize the object, so
734+ the `__init__` call it won't be called, which will lead to not
735+ have the python versions as a dependencies and it will cause a
736+ tremendous `test_graph` error (difficult to track) and also, the
737+ build order for dependencies will not be computed as expected (if
738+ computed...). So be very careful with this line!!
739+
740+ .. warning:: this `depends` may be overwrote in inherited classes of
741+ `PythonRecipe`, so we make sure that any sub class will
742+ contain python as a dependency. We do this by checking the
743+ dependencies in meth:`PythonRecipe.__init__` method and adding
744+ them again in case that is necessary, so don't forget to call
745+ `super` in any inherited class of this class.
746+ '''
747+
730748 def __init__ (self , * args , ** kwargs ):
731749 super (PythonRecipe , self ).__init__ (* args , ** kwargs )
732- depends = self .depends
733- depends .append (('python2' , 'python3' ))
734- depends = list (set (depends ))
735- self .depends = depends
750+ if not any (
751+ [
752+ d
753+ for d in {'python2' , 'python3' , ('python2' , 'python3' )}
754+ if d in self .depends
755+ ]
756+ ):
757+ # we overwrote `depends` in inherited recipe, so we must add it
758+ # again the python versions as dependencies, but we only do this in
759+ # case that the sub classes recipe does not contain any python
760+ # version as dependency because it may be some recipes only
761+ # compatible with a single version of python
762+ depends = self .depends
763+ depends .append (('python2' , 'python3' ))
764+ depends = list (set (depends ))
765+ self .depends = depends
736766
737767 def clean_build (self , arch = None ):
738768 super (PythonRecipe , self ).clean_build (arch = arch )
@@ -938,13 +968,6 @@ class CythonRecipe(PythonRecipe):
938968 cython_args = []
939969 call_hostpython_via_targetpython = False
940970
941- def __init__ (self , * args , ** kwargs ):
942- super (CythonRecipe , self ).__init__ (* args , ** kwargs )
943- depends = self .depends
944- depends .append (('python2' , 'python3' ))
945- depends = list (set (depends ))
946- self .depends = depends
947-
948971 def build_arch (self , arch ):
949972 '''Build any cython components, then install the Python module by
950973 calling setup.py install with the target Python dir.
0 commit comments