Skip to content

Commit 031eaf2

Browse files
authored
Replaces python-magic with built-in mimetypes (#105)
To avoid requirement to install another tool
1 parent 443b6c0 commit 031eaf2

File tree

4 files changed

+4
-27
lines changed

4 files changed

+4
-27
lines changed

assistants/prospector-assistant/uv.lock

-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/python/assistant-drive/assistant_drive/drive.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import io
22
import json
33
import logging
4+
import mimetypes
45
import os
56
import pathlib
67
from contextlib import contextmanager
78
from datetime import datetime
89
from shutil import rmtree
910
from typing import Any, BinaryIO, ContextManager, Iterator, TypeVar
1011

11-
import magic
1212
from context import Context
1313
from pydantic import BaseModel, Field
1414

1515
# from pydantic_settings import BaseSettings
1616

1717
logger = logging.getLogger(__name__)
18-
mime = magic.Magic(mime=True)
1918

2019

2120
class DriveConfig(BaseModel):
@@ -59,8 +58,8 @@ def __str__(self) -> str:
5958

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

libraries/python/assistant-drive/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = [
99
"context>=0.1.0",
1010
"pydantic>=2.6.1",
1111
"pydantic-settings>=2.5.2",
12-
"python-magic>=0.4.27",
12+
# "python-magic>=0.4.27",
1313
# "python-magic-bin>=0.4.14",
1414
]
1515

libraries/python/assistant-drive/uv.lock

-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)