format via black
This commit is contained in:
parent
60d2840656
commit
314c0dced8
3 changed files with 10 additions and 13 deletions
|
|
@ -46,6 +46,7 @@ dependencies = [
|
|||
dev-dependencies = [
|
||||
"pytest>=7.0",
|
||||
"pytest-asyncio>=0.23.0",
|
||||
"black>=23.7.0",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue