Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added terasology module dependency visualizer #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions moduleDependencyGraphDrawer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
deps.png
44 changes: 44 additions & 0 deletions moduleDependencyGraphDrawer/githubScraper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import requests
import json

modules = []
dependencies = [] # list of tuples: (dependantPackage, dependency)


def getUrls():
nextPage = "https://api.github.com/orgs/Terasology/repos?per_page=100"
repos = []
while nextPage is not None:
r = requests.get(nextPage)
header_link: str = r.headers.get("Link")
if header_link is None:
nextPage = None
else:
nextPageLink = [x.split(";")[0] for x in header_link.split(",") if "next" in x.split(";")[1]]
if len(nextPageLink) == 0:
nextPage = None
else:
nextPage = nextPageLink[0][1:-1]
repos += json.loads(r.content)
return [(x["html_url"]+"/"+x["default_branch"]+"/module.txt").replace("github", "raw.githubusercontent", 1) for x in repos]


def init():
print("Fetching list of modules... ", end="")
urls = getUrls()
print("Done")
modules.clear()
dependencies.clear()
print("Fetching module files:")
modulesfetched = 0
for url in urls:
r = requests.get(url)
modulesfetched += 1
if r.status_code != 200:
print(f" Skipping non-module - [{modulesfetched}/{len(urls)}]")
continue
module = json.loads(r.content)
modules.append(module["id"])
for dependency in module["dependencies"]:
dependencies.append((module["id"], dependency["id"]))
print(f" Done {module['id']} - [{modulesfetched}/{len(urls)}]")
11 changes: 11 additions & 0 deletions moduleDependencyGraphDrawer/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import networkx as nx
import matplotlib.pyplot as plt
import githubScraper

githubScraper.init()
G = nx.DiGraph()
G.add_nodes_from(githubScraper.modules)
G.add_edges_from(githubScraper.dependencies)
plt.figure(1, figsize=(100, 60))
nx.draw_kamada_kawai(G, with_labels=True, node_size=60, font_size=8, font_color="b", font_weight="bold")
plt.savefig("deps.png", dpi=300)