Ordering of resources when multiple libraries involved is not robust

Alberto Valverde González avatarAlberto Valverde González created an issue

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()

    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).


Comments (3)

  1. Anonymous

    Hi, Is there any planned release for this? We're currently doing a project called VoteIT (https://github.com/VoteIT/voteit.core) and would like to include Fanstatic, but we're using a lot of JS/CSS with interdependencies, and this very issue seems to be the problem.

    I'd be very grateful if it was possible to release a new version on PyPI :)

    Cheers, Robin robin@betahaus.net

  2. faassen

    Hi there, I didn't see this question appear on the issue, so I just ran into it by coincidence. Anyway, I just did a release.

    Next time please try mailing the fanstatic mailing list directly?

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.