Skip to content

Commit

Permalink
Replaces python-magic with built-in mimetypes (#105)
Browse files Browse the repository at this point in the history
To avoid requirement to install another tool
  • Loading branch information
markwaddle authored Oct 9, 2024
1 parent 443b6c0 commit 031eaf2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 27 deletions.
11 changes: 0 additions & 11 deletions assistants/prospector-assistant/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions libraries/python/assistant-drive/assistant_drive/drive.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import io
import json
import logging
import mimetypes
import os
import pathlib
from contextlib import contextmanager
from datetime import datetime
from shutil import rmtree
from typing import Any, BinaryIO, ContextManager, Iterator, TypeVar

import magic
from context import Context
from pydantic import BaseModel, Field

# from pydantic_settings import BaseSettings

logger = logging.getLogger(__name__)
mime = magic.Magic(mime=True)


class DriveConfig(BaseModel):
Expand Down Expand Up @@ -59,8 +58,8 @@ def __str__(self) -> str:

@staticmethod
def from_bytes(content: BinaryIO, filename: str, dir: str | None = None) -> "FileMetadata":
content_type = mime.from_buffer(content.read())
content.seek(0)
mime_type, _ = mimetypes.guess_type(filename)
content_type = mime_type or "application/octet-stream"
size = len(content.read())
return FileMetadata(filename=filename, dir=dir, content_type=content_type, size=size)

Expand Down
2 changes: 1 addition & 1 deletion libraries/python/assistant-drive/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"context>=0.1.0",
"pydantic>=2.6.1",
"pydantic-settings>=2.5.2",
"python-magic>=0.4.27",
# "python-magic>=0.4.27",
# "python-magic-bin>=0.4.14",
]

Expand Down
11 changes: 0 additions & 11 deletions libraries/python/assistant-drive/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 031eaf2

Please sign in to comment.