The ordering algorithm of resources implemented in fanstatic.core.sort_resources does not handle well cases when resources of different types from different libraries depend on each other. The following test demonstrates it (can be pasted into test_core.py to run):
def test_inter_library_dependencies_ordering(): lib1 = Library('lib1', '') lib2 = Library('lib2', '') lib3 = Library('lib3', '') lib4 = Library('lib4', '')
js1 = Resource(lib1, 'js1.js') js2 = Resource(lib2, 'js2.js', depends=[js1]) js3 = Resource(lib3, 'js3.js', depends=[js2]) style1 = Resource(lib3, 'style1.css') style2 = Resource(lib4, 'style2.css', depends=[style1]) needed = NeededResources() needed.need(js3) needed.need(style2) resources = needed.resources() assert resources.index(style1) < resources.index(style2)
The problem seems to be that inside sort_resources a sort key is computed for each library in relation to each other regardless of the kind of resource. Taking the kind of resource (indirectly via the "order" attribute) into account seems to solve it for this case (see attached patch).