11import contextlib
2- import dataclasses
32import io
43import pathlib
54import tarfile
@@ -74,7 +73,7 @@ def __init__(
7473 volumes : Optional [list [tuple [str , str , str ]]] = None ,
7574 network : Optional [Network ] = None ,
7675 network_aliases : Optional [list [str ]] = None ,
77- transferrables : Optional [list [Transferable ]] = None ,
76+ transferables : Optional [list [Transferable ]] = None ,
7877 ** kwargs : Any ,
7978 ) -> None :
8079 self .env = env or {}
@@ -102,7 +101,7 @@ def __init__(
102101 self .with_network_aliases (* network_aliases )
103102
104103 self ._kwargs = kwargs
105- self ._transferables : list [Transferable ] = transferrables or []
104+ self ._transferables : list [Transferable ] = transferables or []
106105
107106 def with_env (self , key : str , value : str ) -> Self :
108107 self .env [key ] = value
@@ -285,20 +284,23 @@ def _configure(self) -> None:
285284 pass
286285
287286 def with_copy_into_container (
288- self , file_content : bytes | PathLike , destination_in_container : str , mode : int = 0o644
289- ):
287+ self , file_content : Union [ bytes , pathlib . Path ] , destination_in_container : str , mode : int = 0o644
288+ ) -> Self :
290289 self ._transferables .append (Transferable (file_content , destination_in_container , mode ))
291290 return self
292291
293- def copy_into_container (self , file_content : bytes | PathLike , destination_in_container : str , mode : int = 0o644 ):
292+ def copy_into_container (
293+ self , file_content : Union [bytes , pathlib .Path ], destination_in_container : str , mode : int = 0o644
294+ ) -> None :
294295 return self ._transfer_into_container (file_content , destination_in_container , mode )
295296
296- def _transfer_into_container (self , source : bytes | PathLike , destination_in_container : str , mode : int ):
297+ def _transfer_into_container (
298+ self , source : Union [bytes , pathlib .Path ], destination_in_container : str , mode : int
299+ ) -> None :
297300 if isinstance (source , bytes ):
298301 file_content = source
299- elif isinstance (source , PathLike ):
300- p = pathlib .Path (source )
301- file_content = p .read_bytes ()
302+ elif isinstance (source , pathlib .Path ):
303+ file_content = source .read_bytes ()
302304 else :
303305 raise TypeError ("source must be bytes or PathLike" )
304306
@@ -309,17 +311,21 @@ def _transfer_into_container(self, source: bytes | PathLike, destination_in_cont
309311 tarinfo .mode = mode
310312 tar .addfile (tarinfo , io .BytesIO (file_content ))
311313 fileobj .seek (0 )
314+ assert self ._container is not None
312315 rv = self ._container .put_archive (path = "/" , data = fileobj .getvalue ())
313316 assert rv is True
314317
315- def copy_from_container (self , source_in_container : str , destination_on_host : PathLike ):
318+ def copy_from_container (self , source_in_container : str , destination_on_host : pathlib .Path ) -> None :
319+ assert self ._container is not None
316320 tar_stream , _ = self ._container .get_archive (source_in_container )
317321
318322 for chunk in tar_stream :
319323 with tarfile .open (fileobj = io .BytesIO (chunk )) as tar :
320324 for member in tar .getmembers ():
321325 with open (destination_on_host , "wb" ) as f :
322- f .write (tar .extractfile (member ).read ())
326+ fileobj = tar .extractfile (member )
327+ assert fileobj is not None
328+ f .write (fileobj .read ())
323329
324330
325331class Reaper :
0 commit comments