format via black

This commit is contained in:
Raduan77 2024-12-18 10:45:05 +01:00
parent 60d2840656
commit 314c0dced8
3 changed files with 10 additions and 13 deletions

View file

@ -46,6 +46,7 @@ dependencies = [
dev-dependencies = [
"pytest>=7.0",
"pytest-asyncio>=0.23.0",
"black>=23.7.0",
]
[project.urls]

View file

@ -1,16 +1,18 @@
"""Async wrapper for MarkItDown."""
import asyncio
from functools import partial
from typing import Optional, Union
from ._markitdown import MarkItDown, DocumentConverterResult
class AsyncMarkItDown:
"""Async wrapper for MarkItDown that runs operations in a thread pool."""
def __init__(self, markitdown: Optional[MarkItDown] = None):
"""Initialize the async wrapper.
Args:
markitdown: Optional MarkItDown instance to wrap. If not provided,
a new instance will be created.
@ -28,14 +30,14 @@ class AsyncMarkItDown:
async def convert(self, file_path: str, **kwargs) -> DocumentConverterResult:
"""Convert a file to markdown asynchronously.
This runs the synchronous convert operation in a thread pool to avoid
blocking the event loop.
Args:
file_path: Path to the file to convert
**kwargs: Additional arguments to pass to the converter
Returns:
DocumentConverterResult containing the converted markdown
"""

View file

@ -207,15 +207,9 @@ async def test_async_markitdown_concurrent():
# Create a list of tasks
tasks = []
for _ in range(5):
tasks.append(
markitdown.convert(os.path.join(TEST_FILES_DIR, "test.docx"))
)
tasks.append(
markitdown.convert(os.path.join(TEST_FILES_DIR, "test.xlsx"))
)
tasks.append(
markitdown.convert(os.path.join(TEST_FILES_DIR, "test.pptx"))
)
tasks.append(markitdown.convert(os.path.join(TEST_FILES_DIR, "test.docx")))
tasks.append(markitdown.convert(os.path.join(TEST_FILES_DIR, "test.xlsx")))
tasks.append(markitdown.convert(os.path.join(TEST_FILES_DIR, "test.pptx")))
# Run all tasks concurrently
results = await asyncio.gather(*tasks)