Changeset - c76638100ca0
[Not reviewed]
default
0 1 0
Mads Kiilerich (mads) - 5 years ago 2020-12-29 22:30:48
mads@kiilerich.com
deps: also report unseen known violations
1 file changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
scripts/deps.py
Show inline comments
 
@@ -144,38 +144,38 @@ kallithea.lib.utils
 
kallithea.lib.utils2
 
kallithea.lib.vcs
 
kallithea.lib.webutils
 
kallithea.model
 
kallithea.model.async_tasks
 
kallithea.model.scm
 
kallithea.templates.py
 
'''.split())
 

	
 
shown_modules = normal_modules | top_modules
 

	
 
# break the chains somehow - this is a cleanup TODO list
 
known_violations = [
 
known_violations = set([
 
('kallithea.lib.auth_modules', 'kallithea.lib.auth'),  # needs base&facade
 
('kallithea.lib.utils', 'kallithea.model'),  # clean up utils
 
('kallithea.lib.utils', 'kallithea.model.db'),
 
('kallithea.lib.utils', 'kallithea.model.scm'),
 
('kallithea.model.async_tasks', 'kallithea.lib.hooks'),
 
('kallithea.model.async_tasks', 'kallithea.lib.indexers'),
 
('kallithea.model.async_tasks', 'kallithea.model'),
 
('kallithea.model', 'kallithea.lib.auth'),  # auth.HasXXX
 
('kallithea.model', 'kallithea.lib.auth_modules'),  # validators
 
('kallithea.model', 'kallithea.lib.hooks'),  # clean up hooks
 
('kallithea.model', 'kallithea.model.scm'),
 
('kallithea.model.scm', 'kallithea.lib.hooks'),
 
]
 
])
 

	
 
extra_edges = [
 
('kallithea.config', 'kallithea.controllers'),  # through TG
 
('kallithea.lib.auth', 'kallithea.lib.auth_modules'),  # custom loader
 
]
 

	
 

	
 
def normalize(s):
 
    """Given a string with dot path, return the string it should be shown as."""
 
    parts = s.replace('.__init__', '').split('.')
 
    short_2 = '.'.join(parts[:2])
 
    short_3 = '.'.join(parts[:3])
 
@@ -262,24 +262,26 @@ Usage:
 
    assert not unseen_shown_modules, unseen_shown_modules
 

	
 
    with open('deps.dot', 'w') as f:
 
        f.write('digraph {\n')
 
        f.write('subgraph { rank = same; %s}\n' % ''.join('"%s"; ' % s for s in sorted(top_modules)))
 
        f.write('subgraph { rank = same; %s}\n' % ''.join('"%s"; ' % s for s in sorted(only_imported)))
 
        for a, b in sorted(normalized_dep_edges):
 
            f.write('  "%s" -> "%s"%s\n' % (a, b, ' [color=red]' if (a, b) in known_violations else ' [color=green]' if (a, b) in extra_edges else ''))
 
        f.write('}\n')
 

	
 
    # verify dependencies by untangling dependency chain bottom-up:
 
    todo = set(normalized_dep_edges)
 
    unseen_violations = known_violations.difference(todo)
 
    assert not unseen_violations, unseen_violations
 
    for x in known_violations:
 
        todo.remove(x)
 

	
 
    while todo:
 
        depending = set(a for a, b in todo)
 
        depended = set(b for a, b in todo)
 
        drop = depended - depending
 
        if not drop:
 
            print('ERROR: cycles:', len(todo))
 
            for x in sorted(todo):
 
                print('%s,' % (x,))
 
            raise SystemExit(1)
0 comments (0 inline, 0 general)