Skip to content

Commit dc589c4

Browse files
committed
[crystax] Fix the dependencies resolution
1 parent aad2730 commit dc589c4

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

pythonforandroid/recipe.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

pythonforandroid/recipes/six/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class SixRecipe(PythonRecipe):
66
version = '1.10.0'
77
url = 'https://pypi.python.org/packages/source/s/six/six-{version}.tar.gz'
8+
depends = ['setuptools']
89

910

1011
recipe = SixRecipe()

tests/test_bootstrap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def test_expand_dependencies_with_pure_python_package(self):
178178
expanded_result = expand_dependencies(
179179
["python3", "kivy", "peewee"], self.ctx
180180
)
181-
self.assertEqual(len(expanded_result), 3)
181+
# we expect to have two results (one for python2 and one for python3)
182+
self.assertEqual(len(expanded_result), 2)
182183
self.assertIsInstance(expanded_result, list)
183184
for i in expanded_result:
184185
self.assertIsInstance(i, list)

0 commit comments

Comments
 (0)