Skip to content

Commit

Permalink
ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
granawkins committed Aug 19, 2024
1 parent 0401f51 commit 8455f9b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 0 additions & 2 deletions dev-requirements.txt

This file was deleted.

7 changes: 4 additions & 3 deletions ragdaemon/annotators/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ragdaemon.database import Database, remove_add_to_db_duplicates
from ragdaemon.graph import KnowledgeGraph
from ragdaemon.errors import RagdaemonError
from ragdaemon.io import IO
from ragdaemon.utils import get_document, hash_str, truncate


Expand Down Expand Up @@ -34,10 +33,12 @@ async def annotate(
path_str = path.as_posix()
documents[path] = get_document(path_str, self.io)
checksums[path] = hash_str(documents[path])
files_checksum = hash_str("".join(f"{path.as_posix()}{checksums[path]}" for path in sorted(checksums)))
files_checksum = hash_str(
"".join(f"{path.as_posix()}{checksums[path]}" for path in sorted(checksums))
)
if not refresh and files_checksum == graph.graph.get("files_checksum"):
return graph

# Initialize a new graph from scratch with same cwd
cwd = Path(graph.graph["cwd"])
graph = KnowledgeGraph()
Expand Down
10 changes: 4 additions & 6 deletions ragdaemon/io/docker_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def read(self, size: int = -1) -> str:
def write(self, data: str) -> int:
if "w" not in self.mode:
raise IOError("File not opened in write mode")

with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(data.encode('utf-8'))
temp_file.write(data.encode("utf-8"))
temp_file_path = temp_file.name

# Create a tar archive of the temporary file
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
with tarfile.open(fileobj=tar_stream, mode="w") as tar:
tar.add(temp_file_path, arcname=os.path.basename(self.path))
tar_stream.seek(0)

Expand All @@ -58,8 +58,6 @@ def write(self, data: str) -> int:

return len(data)



def __enter__(self) -> "FileInDocker":
return self

Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@ def mock_openai_api_key():
because if Docker IS installed (i.e. local development on MacOS or Windows), it should
still work.
"""


def fail_silently_on_macos_and_windows(docker_function, *args, **kwargs):
try:
return docker_function(*args, **kwargs)
except DockerException as e:
if platform.system() in ["Darwin", "Windows"]:
pytest.skip(f"Skipping Docker tests on {platform.system()} due to Docker error: {e}")
pytest.skip(
f"Skipping Docker tests on {platform.system()} due to Docker error: {e}"
)
else:
raise e
raise e


@pytest.fixture(scope="session")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def test_daemon_refresh(cwd_git):
await daemon.update()
files3 = set(daemon.graph.nodes)
assert files2 != files3

# Delete
daemon.io.unlink(cwd_git / "main2.py")
await daemon.update()
Expand Down
1 change: 0 additions & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def all_io_methods(io: IO):

@pytest.mark.asyncio
async def test_local_io_methods(cwd_git):

io = LocalIO(Path(cwd_git))
all_io_methods(io)

Expand Down

0 comments on commit 8455f9b

Please sign in to comment.