| Total Complexity | 3 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from pipdeptree._cli import get_options |
||
| 2 | from pipdeptree._discovery import get_installed_distributions |
||
| 3 | from pipdeptree._models import PackageDAG |
||
| 4 | |||
| 5 | import graphinate |
||
| 6 | |||
| 7 | |||
| 8 | def dependency_graph_model(): |
||
| 9 | """ |
||
| 10 | Generate a dependency graph model. |
||
| 11 | |||
| 12 | Returns: |
||
| 13 | GraphModel: A graph model representing the dependency graph. |
||
| 14 | """ |
||
| 15 | |||
| 16 | options = get_options(args=None) |
||
| 17 | |||
| 18 | pkgs = get_installed_distributions(local_only=options.local_only, user_only=options.user_only) |
||
| 19 | tree = PackageDAG.from_pkgs(pkgs) |
||
| 20 | |||
| 21 | graph_model = graphinate.model(name="Dependency Graph") |
||
| 22 | |||
| 23 | @graph_model.edge() |
||
| 24 | def dependency(): |
||
| 25 | for p, d in tree.items(): |
||
| 26 | for c in d: |
||
| 27 | yield {'source': p.project_name, 'target': c.project_name} |
||
| 28 | |||
| 29 | return graph_model |
||
| 30 | |||
| 31 | |||
| 32 | if __name__ == '__main__': |
||
| 33 | dependency_model = dependency_graph_model() |
||
| 34 | schema = graphinate.builders.GraphQLBuilder(dependency_model).build() |
||
| 35 | graphinate.graphql.server(schema) |
||
| 36 |