33from __future__ import annotations
44
55import asyncio
6- from typing import Dict , Mapping , Optional , Sequence
6+ from typing import Dict , Mapping , Optional
77from pathlib import Path
88from datetime import timedelta
99from typing_extensions import Unpack
2424from .._types import Timeout , NotGiven , not_given
2525from .._client import DEFAULT_MAX_RETRIES , AsyncRunloop
2626from ._helpers import detect_content_type
27- from ..lib ._ignore import IgnoreMatcher , TarFilterMatcher , FilePatternMatcher
2827from .async_devbox import AsyncDevbox
2928from .async_snapshot import AsyncSnapshot
3029from .async_blueprint import AsyncBlueprint
31- from ..lib .context_loader import build_directory_tar
30+ from ..lib .context_loader import TarFilter , build_directory_tar
3231from .async_storage_object import AsyncStorageObject
3332from ..types .object_create_params import ContentType
3433
@@ -376,7 +375,7 @@ async def upload_from_dir(
376375 name : Optional [str ] = None ,
377376 metadata : Optional [Dict [str , str ]] = None ,
378377 ttl : Optional [timedelta ] = None ,
379- ignore : IgnoreMatcher | Sequence [ str ] | str | None = None ,
378+ ignore : TarFilter | None = None ,
380379 ** options : Unpack [LongRequestOptions ],
381380 ) -> AsyncStorageObject :
382381 """Create and upload an object from a local directory.
@@ -391,17 +390,10 @@ async def upload_from_dir(
391390 :type metadata: Optional[Dict[str, str]]
392391 :param ttl: Optional Time-To-Live, after which the object is automatically deleted
393392 :type ttl: Optional[timedelta]
394- :param ignore: Optional ignore configuration controlling which files from
395- ``dir_path`` are included in the uploaded tarball. This may be:
396-
397- - An :class:`~runloop_api_client.lib._ignore.IgnoreMatcher`
398- implementation such as :class:`~runloop_api_client.lib._ignore.DockerIgnoreMatcher`
399- or :class:`~runloop_api_client.lib._ignore.FilePatternMatcher`.
400- - A single pattern string.
401- - A sequence of pattern strings.
402-
403- Patterns follow Docker-style semantics (``!`` negation, ``**`` support).
404- :type ignore: Optional[IgnoreMatcher | Sequence[str] | str]
393+ :param ignore: Optional tar filter function compatible with
394+ :meth:`tarfile.TarFile.add`. If provided, it will be called for each
395+ member to allow modification or exclusion (by returning ``None``).
396+ :type ignore: Optional[TarFilter]
405397 :param options: See :typeddict:`~runloop_api_client.sdk._types.LongRequestOptions`
406398 for available options
407399 :return: Wrapper for the uploaded object
@@ -416,17 +408,7 @@ async def upload_from_dir(
416408 ttl_ms = int (ttl .total_seconds ()) * 1000 if ttl else None
417409
418410 def synchronous_io () -> bytes :
419- matcher : IgnoreMatcher | None
420- if ignore is None :
421- matcher = None
422- elif isinstance (ignore , IgnoreMatcher ):
423- matcher = ignore
424- else :
425- matcher = FilePatternMatcher (ignore ) # type: ignore[arg-type]
426-
427- if matcher is None :
428- return build_directory_tar (path )
429- return build_directory_tar (path , tar_filter = TarFilterMatcher (path , matcher ))
411+ return build_directory_tar (path , tar_filter = ignore )
430412
431413 tar_bytes = await asyncio .to_thread (synchronous_io )
432414
0 commit comments