Giter Club home page Giter Club logo

modules's People

Contributors

ahundt avatar bkainz avatar ghisvail avatar gitter-badger avatar schuhschuh avatar wittenbe avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

modules's Issues

topological_sort should throw on cycle error

# https://github.com/cmake-basis/modules/blob/master/TopologicalSort.cmake
include(TopologicalSort.cmake)

set(target_names a b c)

# c -> b -> a -> c
set(target_dependencies_a b)
set(target_dependencies_b c)
set(target_dependencies_c a)

message("before toposort: target_names = ${target_names}")
topological_sort(target_names target_dependencies_ "")
message("after  toposort: target_names = ${target_names}")

output

before toposort: target_names = a;b;c
after  toposort: target_names = c;b;a

ideally, the cycle error should also print the cycle

in python im using

import networkx
debug = True

scope_installs = ["a", "b", "c"]

# c -> b -> a -> c
target_depends_map = {
  "a": ["b"],
  "b": ["c"],
  "c": ["a"],
}

# build dependency graph
depgraph = networkx.DiGraph()
depgraph_roots = set()
for target_name in scope_installs:
    target_depends = target_depends_map.get(target_name, [])
    for dep in target_depends:
        depgraph.add_edge(dep, target_name)

# find roots of graph
depgraph_roots = []
for component in networkx.weakly_connected_components(depgraph):
    subgraph = depgraph.subgraph(component)
    depgraph_roots.extend([n for n,d in subgraph.in_degree() if d==0])

# check for cycles
# toposort throws exception, but does not print cycles
depgraph_cycles = list(networkx.simple_cycles(depgraph))
if depgraph_cycles:
    raise Exception(f"found cycles in depgraph: {depgraph_cycles}")

targets_sorted = list(networkx.topological_sort(depgraph))

debug and print(f"targets_sorted = {' '.join(targets_sorted)}")

output

Exception: found cycles in depgraph: [['a', 'c', 'b']]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.