Skip to content

Commit

Permalink
fix: dependency_graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Niraj-Kamdar committed Jul 30, 2023
1 parent a141200 commit 035f029
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 11 additions & 4 deletions scripts/dependency_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
from typing import Generator
import tomlkit
from pathlib import Path
from get_packages import extract_package_paths


def build_dependency_graph():
dependent_graph: defaultdict[str, set[str]] = defaultdict(set)
deps_counter: Counter[int] = Counter()

for package in Path(__file__).parent.parent.joinpath("packages").iterdir():
if package.is_dir():
name = package.name
for package in extract_package_paths():
package_path = Path(package)
if package_path.is_dir():
name = package_path.name
deps_counter[name] = 0
with open(package.joinpath("pyproject.toml"), "r") as f:
with open(package_path.joinpath("pyproject.toml"), "r") as f:
pyproject = tomlkit.load(f)
dependencies = pyproject["tool"]["poetry"]["dependencies"]
for dep in dependencies:
Expand All @@ -37,3 +39,8 @@ def topological_order(graph: dict[str, set[str]], counter: dict[str, int]) -> Ge
def package_build_order() -> Generator[str, None, None]:
graph, counter = build_dependency_graph()
return topological_order(graph, counter)


if __name__ == "__main__":
for package in package_build_order():
print(package)
10 changes: 5 additions & 5 deletions scripts/get_packages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os

def extract_package_paths(workspace_file):
def extract_package_paths(workspace_file = 'python-monorepo.code-workspace'):
with open(workspace_file, 'r') as file:
workspace_data = json.load(file)

Expand All @@ -12,8 +12,8 @@ def extract_package_paths(workspace_file):
and os.path.isfile(os.path.join(folder['path'], 'pyproject.toml'))
]

workspace_file = 'python-monorepo.code-workspace'
package_paths = extract_package_paths(workspace_file)
packages = { "package": package_paths }
if __name__ == '__main__':
package_paths = extract_package_paths()
packages = { "package": package_paths }

print(json.dumps(packages))
print(json.dumps(packages))

0 comments on commit 035f029

Please sign in to comment.