Skip to content

Commit 1634cdc

Browse files
committed
fix: route push completion through logger
Signed-off-by: ahmad <ahmadalgaidy@hotmail.com>
1 parent a209c6c commit 1634cdc

4 files changed

Lines changed: 63 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x)
17+
- route push completion output through the logger and support the documented `quiet` option, closes issue [229](https://github.com/oras-project/oras-py/issues/229) (0.2.43)
1718
- add Layout `copy` for pull_from_registry capability (0.2.42)
1819
- make `get_manifest()` validation optional, fix `Accept` header join, and expand default `Accept` header types to cover all supported response types for the `/v2/<name>/manifests/<reference>` endpoint (0.2.41)
1920
- fix preemptive exit in non-empty `auths` lookup when `credsStore` or `credHelpers` is used (0.2.40)

oras/provider.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ def push(
724724
subject: Optional[str] = None,
725725
do_chunked: bool = False,
726726
chunk_size: int = oras.defaults.default_chunksize,
727+
quiet: bool = False,
727728
) -> requests.Response:
728729
"""
729730
Push a set of files to a target
@@ -748,6 +749,8 @@ def push(
748749
:type chunk_size: int
749750
:param subject: optional subject reference
750751
:type subject: oras.oci.Subject
752+
:param quiet: suppress the completion message
753+
:type quiet: bool
751754
"""
752755
container = self.get_container(target)
753756
files = files or []
@@ -863,7 +866,8 @@ def push(
863866
manifest, container
864867
) # make the returned response from this method, the one pertaining to the uploaded Manifest
865868
self._check_200_response(response)
866-
print(f"Successfully pushed {container}")
869+
if not quiet:
870+
logger.info(f"Successfully pushed {container}")
867871
return response
868872

869873
def pull(

oras/tests/test_provider.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import subprocess
77
from pathlib import Path
8+
from unittest.mock import Mock
89

910
import pytest
1011

@@ -17,6 +18,61 @@
1718
here = Path(__file__).resolve().parent
1819

1920

21+
def test_push_quiet_output_does_not_write_stdout(tmp_path, monkeypatch, capsys):
22+
client = oras.provider.Registry(hostname="registry.example", insecure=True)
23+
artifact = tmp_path / "artifact.txt"
24+
artifact.write_text("content")
25+
26+
class Response:
27+
status_code = 201
28+
29+
container = client.get_container("registry.example/repository:tag")
30+
monkeypatch.setattr(client, "get_container", lambda target: container)
31+
monkeypatch.setattr(client.auth, "load_configs", lambda *args, **kwargs: None)
32+
monkeypatch.setattr(client, "upload_blob", lambda *args, **kwargs: Response())
33+
monkeypatch.setattr(client, "upload_manifest", lambda *args, **kwargs: Response())
34+
monkeypatch.setattr(client, "_check_200_response", lambda response: None)
35+
info = Mock()
36+
monkeypatch.setattr(oras.provider.logger, "info", info)
37+
38+
client.push(
39+
files=[artifact],
40+
target="registry.example/repository:tag",
41+
disable_path_validation=True,
42+
quiet=False,
43+
)
44+
45+
assert capsys.readouterr().out == ""
46+
info.assert_called_once_with(f"Successfully pushed {container}")
47+
48+
49+
def test_push_quiet_suppresses_completion_message(tmp_path, monkeypatch):
50+
client = oras.provider.Registry(hostname="registry.example", insecure=True)
51+
artifact = tmp_path / "artifact.txt"
52+
artifact.write_text("content")
53+
54+
class Response:
55+
status_code = 201
56+
57+
container = client.get_container("registry.example/repository:tag")
58+
monkeypatch.setattr(client, "get_container", lambda target: container)
59+
monkeypatch.setattr(client.auth, "load_configs", lambda *args, **kwargs: None)
60+
monkeypatch.setattr(client, "upload_blob", lambda *args, **kwargs: Response())
61+
monkeypatch.setattr(client, "upload_manifest", lambda *args, **kwargs: Response())
62+
monkeypatch.setattr(client, "_check_200_response", lambda response: None)
63+
info = Mock()
64+
monkeypatch.setattr(oras.provider.logger, "info", info)
65+
66+
client.push(
67+
files=[artifact],
68+
target="registry.example/repository:tag",
69+
disable_path_validation=True,
70+
quiet=True,
71+
)
72+
73+
info.assert_not_called()
74+
75+
2076
@pytest.mark.with_auth(False)
2177
def test_annotated_registry_push(tmp_path, registry, credentials, target):
2278
"""

oras/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright The ORAS Authors."
33
__license__ = "Apache-2.0"
44

5-
__version__ = "0.2.42"
5+
__version__ = "0.2.43"
66
AUTHOR = "Vanessa Sochat"
77
EMAIL = "vsoch@users.noreply.github.com"
88
NAME = "oras"

0 commit comments

Comments
 (0)