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

Fix circular import #40

Merged
merged 2 commits into from
May 13, 2024
Merged
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: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages=["ragdaemon"]

[project]
name = "ragdaemon"
version = "0.4.6"
version = "0.4.7"
Comment on lines 9 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "ragdaemon"
version = "0.4.6"
version = "0.4.7"
version = "0.4.7"

It's good to update the project version to reflect new changes or fixes such as the fix for the circular dependency issue.

description = "Generate and render a call graph for a Python project."
readme = "README.md"
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion ragdaemon/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.6"
__version__ = "0.4.7"
17 changes: 7 additions & 10 deletions ragdaemon/annotators/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from ragdaemon.get_paths import get_git_root_for_path
from ragdaemon.graph import KnowledgeGraph
from ragdaemon.errors import RagdaemonError
from ragdaemon.utils import get_document, hash_str, parse_path_ref, truncate
from ragdaemon.utils import (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring to move parse_diff_id from diff.py to utils.py to resolve circular imports is a good approach. It's essential to ensure that all files that used the old import are updated accordingly.

get_document,
hash_str,
parse_diff_id,
parse_path_ref,
truncate,
)


def get_chunks_from_diff(id: str, diff: str) -> dict[str, str]:
Expand Down Expand Up @@ -53,15 +59,6 @@ def get_chunks_from_diff(id: str, diff: str) -> dict[str, str]:
return chunks


def parse_diff_id(id: str) -> tuple[str, Path | None, set[int] | None]:
if ":" in id:
diff_ref, path_ref = id.split(":", 1)
path, lines = parse_path_ref(path_ref)
else:
diff_ref, path, lines = id, None, None
return diff_ref, path, lines


class Diff(Annotator):
name: str = "diff"

Expand Down
3 changes: 1 addition & 2 deletions ragdaemon/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from typing import Any, Dict, Optional, Union

from dict2xml import dict2xml
from ragdaemon.annotators.diff import parse_diff_id
from ragdaemon.database import Database
from ragdaemon.errors import RagdaemonError
from ragdaemon.graph import KnowledgeGraph
from ragdaemon.utils import get_document, hash_str, parse_path_ref
from ragdaemon.utils import get_document, hash_str, parse_diff_id, parse_path_ref

NestedStrDict = Union[str, Dict[str, "NestedStrDict"]]

Expand Down
9 changes: 9 additions & 0 deletions ragdaemon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def parse_path_ref(ref: str) -> tuple[Path, set[int] | None]:
return Path(path_str), lines


def parse_diff_id(id: str) -> tuple[str, Path | None, set[int] | None]:
if ":" in id:
diff_ref, path_ref = id.split(":", 1)
path, lines = parse_path_ref(path_ref)
else:
diff_ref, path, lines = id, None, None
return diff_ref, path, lines


def get_document(ref: str, cwd: Path, type: str = "file") -> str:
if type == "diff":
if ":" in ref:
Expand Down
Loading