From f6403089bfeac9c03670282b24213956f57b6202 Mon Sep 17 00:00:00 2001 From: granawkins Date: Fri, 21 Jun 2024 11:02:40 +0700 Subject: [PATCH 1/2] build directory nodes from graph instead of filesys --- ragdaemon/annotators/hierarchy.py | 41 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/ragdaemon/annotators/hierarchy.py b/ragdaemon/annotators/hierarchy.py index 40efd56..0f464f8 100644 --- a/ragdaemon/annotators/hierarchy.py +++ b/ragdaemon/annotators/hierarchy.py @@ -66,37 +66,32 @@ async def annotate( for parent in path.parents: if len(parent.parts) == 0: parent = Path("ROOT") - directories.add(parent) + directories.add(parent.as_posix()) edges.add((parent.as_posix(), _last.as_posix())) _last = parent - for dir in directories: - dir_str = dir.as_posix() - dir_path = dir if dir != Path("ROOT") else Path(".") - document = get_document( - dir_str, cwd, type="directory", ignore_patterns=self.ignore_patterns - ) - checksum = hash_str( - "".join( - checksums.get(dir_path / subpath, "") - for subpath in document.split("\n")[1:] - ) - ) + for source, target in edges: + for id in (source, target): + if id not in graph and id not in directories: + raise RagdaemonError(f"Node {id} not found in graph") + graph.add_edge(source, target, type="hierarchy") + + # Fill-in directory data (same process as get_document for dirs, but more efficient) + for dir in sorted( + directories, key=lambda x: len(x) if x != "ROOT" else 0, reverse=True + ): + children = sorted(node for node in graph.successors(dir)) + document = f"{dir}\n" + "\n".join(children) + checksum = hash_str("".join(checksums[Path(child)] for child in children)) data = { - "id": dir_str, + "id": dir, "type": "directory", - "ref": dir_str, + "ref": dir, "document": document, "checksum": checksum, } - graph.add_node(dir_str, **data) - checksums[dir] = checksum - - for source, target in edges: - for id in (source, target): - if id not in graph: - raise RagdaemonError(f"Node {id} not found in graph") - graph.add_edge(source, target, type="hierarchy") + checksums[Path(dir)] = checksum + graph.nodes[dir].update(data) # Sync with remote DB ids = list(set(checksums.values())) From 27638c3a835c3c7544b4ce7a809bf73023dbd74d Mon Sep 17 00:00:00 2001 From: granawkins Date: Fri, 21 Jun 2024 11:03:15 +0700 Subject: [PATCH 2/2] version bump --- pyproject.toml | 4 ++-- ragdaemon/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d3e752a..6736684 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ packages=["ragdaemon"] [project] name = "ragdaemon" -version = "0.7.7" +version = "0.7.8" description = "Generate and render a call graph for a Python project." readme = "README.md" dependencies = [ @@ -47,4 +47,4 @@ dev = [ ] [tool.pyright] -ignore = ["tests/sample"] \ No newline at end of file +ignore = ["tests/sample"] diff --git a/ragdaemon/__init__.py b/ragdaemon/__init__.py index 4e27eed..894cebc 100644 --- a/ragdaemon/__init__.py +++ b/ragdaemon/__init__.py @@ -1 +1 @@ -__version__ = "0.7.7" +__version__ = "0.7.8"