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 = [ dev-dependencies = [
"pytest>=7.0", "pytest>=7.0",
"pytest-asyncio>=0.23.0", "pytest-asyncio>=0.23.0",
"black>=23.7.0",
] ]
[project.urls] [project.urls]

View file

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

View file

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