Skip to content

Commit

Permalink
reformatted with black
Browse files Browse the repository at this point in the history
Signed-off-by: Yuriy Novostavskiy <[email protected]>
  • Loading branch information
yurnov committed Apr 5, 2024
1 parent fdb66a1 commit 51b4377
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ oras.egg-info/
.env
env
__pycache__
.python-version
39 changes: 30 additions & 9 deletions oras/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def upload_blob(
container: container_type,
layer: dict,
do_chunked: bool = False,
refresh_headers: bool = True
refresh_headers: bool = True,
) -> requests.Response:
"""
Prepare and upload a blob.
Expand All @@ -253,9 +253,13 @@ def upload_blob(
# This is currently disabled unless the user asks for it, as
# it doesn't seem to work for all registries
if not do_chunked:
response = self.put_upload(blob, container, layer, refresh_headers=refresh_headers)
response = self.put_upload(
blob, container, layer, refresh_headers=refresh_headers
)
else:
response = self.chunked_upload(blob, container, layer, refresh_headers=refresh_headers)
response = self.chunked_upload(
blob, container, layer, refresh_headers=refresh_headers
)

# If we have an empty layer digest and the registry didn't accept, just return dummy successful response
if (
Expand Down Expand Up @@ -477,7 +481,11 @@ def download_blob(
return outfile

def put_upload(
self, blob: str, container: oras.container.Container, layer: dict, refresh_headers: bool = True
self,
blob: str,
container: oras.container.Container,
layer: dict,
refresh_headers: bool = True,
) -> requests.Response:
"""
Upload to a registry via put.
Expand Down Expand Up @@ -550,7 +558,11 @@ def _get_location(
return session_url

def chunked_upload(
self, blob: str, container: oras.container.Container, layer: dict, refresh_headers: bool = True
self,
blob: str,
container: oras.container.Container,
layer: dict,
refresh_headers: bool = True,
) -> requests.Response:
"""
Upload via a chunked upload.
Expand Down Expand Up @@ -632,7 +644,10 @@ def _parse_response_errors(self, response: requests.Response):
pass

def upload_manifest(
self, manifest: dict, container: oras.container.Container, refresh_headers: bool = True
self,
manifest: dict,
container: oras.container.Container,
refresh_headers: bool = True,
) -> requests.Response:
"""
Read a manifest file and upload it.
Expand Down Expand Up @@ -746,7 +761,9 @@ def push(self, *args, **kwargs) -> requests.Response:
logger.debug(f"Preparing layer {layer}")

# Upload the blob layer
response = self.upload_blob(blob, container, layer, refresh_headers=refresh_headers)
response = self.upload_blob(
blob, container, layer, refresh_headers=refresh_headers
)
self._check_200_response(response)

# Do we need to cleanup a temporary targz?
Expand Down Expand Up @@ -788,13 +805,17 @@ def push(self, *args, **kwargs) -> requests.Response:
if config_file is None
else nullcontext(config_file)
) as config_file:
response = self.upload_blob(config_file, container, conf, refresh_headers=refresh_headers)
response = self.upload_blob(
config_file, container, conf, refresh_headers=refresh_headers
)

self._check_200_response(response)

# Final upload of the manifest
manifest["config"] = conf
self._check_200_response(self.upload_manifest(manifest, container, refresh_headers=refresh_headers))
self._check_200_response(
self.upload_manifest(manifest, container, refresh_headers=refresh_headers)
)
print(f"Successfully pushed {container}")
return response

Expand Down

0 comments on commit 51b4377

Please sign in to comment.