Skip to content

Commit 38cb05b

Browse files
committed
chore: address comments and improve test coverage(6)
Signed-off-by: jiwangCHEN <hyper1char@gmail.com>
1 parent 7321ce8 commit 38cb05b

5 files changed

Lines changed: 21 additions & 13 deletions

File tree

oras/content/registry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def push(self, desc: Descriptor, content: BinaryIO) -> None:
154154
self._registry._check_200_response(response)
155155
finally:
156156
if tmp is not None:
157+
try:
158+
tmp.close()
159+
except Exception:
160+
pass
157161
try:
158162
os.unlink(tmp.name)
159163
except OSError:

oras/content/storage.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727

2828
import io
2929
import threading
30-
from typing import BinaryIO, Callable, Protocol, Tuple, runtime_checkable
30+
from typing import BinaryIO, Callable, Tuple
31+
32+
try:
33+
from typing import Protocol, runtime_checkable # Python 3.8+
34+
except ImportError: # Python 3.7
35+
from typing_extensions import Protocol, runtime_checkable
3136

3237
from oras.types import Descriptor
3338

oras/copy/copy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def _resolve_root(
119119
The fetched content is fed through ``successors`` to ensure
120120
it gets cached in the proxy for later use during graph traversal.
121121
122+
Currently referenceFetcher is not implemented for registry targets.
123+
122124
Matches oras-go's resolveRoot.
123125
"""
124126
if isinstance(src, storage.ReferenceFetcher):
@@ -137,8 +139,6 @@ def _resolve_root(
137139
if hasattr(rc, "close"):
138140
rc.close()
139141

140-
# Cache the root content by feeding it through successors
141-
# This ensures the proxy has the manifest/index cached
142142
def fetch_root(desc):
143143
if descriptors_equal(desc, root):
144144
return io.BytesIO(data)

oras/layout/layout.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import json
88
import pathlib
9-
from typing import TYPE_CHECKING, Optional
9+
from typing import TYPE_CHECKING, List, Optional
1010

1111
import jsonschema
1212
import requests
@@ -147,7 +147,7 @@ def is_oci_layout(path: str) -> bool:
147147
except (FileNotFoundError, ValueError, OSError):
148148
return False
149149

150-
def get_ordered_blobs(self, tag: str = "latest") -> list[str]:
150+
def get_ordered_blobs(self, tag: str = "latest") -> List[str]:
151151
"""
152152
Traverse an OCI layout and collect blob digests in dependency order for pushing.
153153
@@ -170,7 +170,7 @@ def get_ordered_blobs(self, tag: str = "latest") -> list[str]:
170170
raise ValueError(f"Tag '{tag}' not found in index")
171171

172172
# Collect blobs in dependency order
173-
collected: list[str] = []
173+
collected: List[str] = []
174174
self._process_manifest(manifest_entry["digest"], collected)
175175
return collected
176176

@@ -196,7 +196,7 @@ def find_index_entry(self, reference: str) -> Optional[dict]:
196196
return manifest_entry
197197
return None
198198

199-
def _process_manifest(self, digest: str, collected: list[str]) -> None:
199+
def _process_manifest(self, digest: str, collected: List[str]) -> None:
200200
"""
201201
Recursively process a manifest blob and collect dependencies.
202202

oras/provider.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,10 @@ def chunked_upload(
632632
# Important to update with auth token if acquired
633633
# TODO call to auth here
634634
start = end + 1
635-
self._check_200_response(
636-
r := self.do_request(
637-
session_url, "PATCH", data=chunk, headers=headers
638-
)
635+
r = self.do_request(
636+
session_url, "PATCH", data=chunk, headers=headers
639637
)
638+
self._check_200_response(r)
640639
session_url = self._get_location(r, container)
641640
if not session_url:
642641
raise ValueError(f"Issue retrieving session url: {r.json()}")
@@ -732,8 +731,8 @@ def copy(
732731
self.auth.load_configs(src_container, configs=configs)
733732
self.auth.load_configs(dst_container, configs=configs)
734733

735-
src_target = RegistryTarget(self, src_container)
736-
dst_target = RegistryTarget(self, dst_container)
734+
src_target = RegistryTarget(self, src_container, opts)
735+
dst_target = RegistryTarget(self, dst_container, opts)
737736

738737
src_ref = src_container.digest or src_container.tag
739738
dst_ref = dst_container.digest or dst_container.tag

0 commit comments

Comments
 (0)