Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x)
- 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)
- add Layout `copy` for pull_from_registry capability (0.2.42)
- 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)
- fix preemptive exit in non-empty `auths` lookup when `credsStore` or `credHelpers` is used (0.2.40)
Expand Down
6 changes: 5 additions & 1 deletion oras/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ def push(
subject: Optional[str] = None,
do_chunked: bool = False,
chunk_size: int = oras.defaults.default_chunksize,
quiet: bool = False,
) -> requests.Response:
"""
Push a set of files to a target
Expand All @@ -748,6 +749,8 @@ def push(
:type chunk_size: int
:param subject: optional subject reference
:type subject: oras.oci.Subject
:param quiet: suppress the completion message
:type quiet: bool
"""
container = self.get_container(target)
files = files or []
Expand Down Expand Up @@ -863,7 +866,8 @@ def push(
manifest, container
) # make the returned response from this method, the one pertaining to the uploaded Manifest
self._check_200_response(response)
print(f"Successfully pushed {container}")
if not quiet:
logger.info(f"Successfully pushed {container}")
return response

def pull(
Expand Down
56 changes: 56 additions & 0 deletions oras/tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import subprocess
from pathlib import Path
from unittest.mock import Mock

import pytest

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


def test_push_quiet_output_does_not_write_stdout(tmp_path, monkeypatch, capsys):
client = oras.provider.Registry(hostname="registry.example", insecure=True)
artifact = tmp_path / "artifact.txt"
artifact.write_text("content")

class Response:
status_code = 201

container = client.get_container("registry.example/repository:tag")
monkeypatch.setattr(client, "get_container", lambda target: container)
monkeypatch.setattr(client.auth, "load_configs", lambda *args, **kwargs: None)
monkeypatch.setattr(client, "upload_blob", lambda *args, **kwargs: Response())
monkeypatch.setattr(client, "upload_manifest", lambda *args, **kwargs: Response())
monkeypatch.setattr(client, "_check_200_response", lambda response: None)
info = Mock()
monkeypatch.setattr(oras.provider.logger, "info", info)

client.push(
files=[artifact],
target="registry.example/repository:tag",
disable_path_validation=True,
quiet=False,
)

assert capsys.readouterr().out == ""
info.assert_called_once_with(f"Successfully pushed {container}")


def test_push_quiet_suppresses_completion_message(tmp_path, monkeypatch):
client = oras.provider.Registry(hostname="registry.example", insecure=True)
artifact = tmp_path / "artifact.txt"
artifact.write_text("content")

class Response:
status_code = 201

container = client.get_container("registry.example/repository:tag")
monkeypatch.setattr(client, "get_container", lambda target: container)
monkeypatch.setattr(client.auth, "load_configs", lambda *args, **kwargs: None)
monkeypatch.setattr(client, "upload_blob", lambda *args, **kwargs: Response())
monkeypatch.setattr(client, "upload_manifest", lambda *args, **kwargs: Response())
monkeypatch.setattr(client, "_check_200_response", lambda response: None)
info = Mock()
monkeypatch.setattr(oras.provider.logger, "info", info)

client.push(
files=[artifact],
target="registry.example/repository:tag",
disable_path_validation=True,
quiet=True,
)

info.assert_not_called()


@pytest.mark.with_auth(False)
def test_annotated_registry_push(tmp_path, registry, credentials, target):
"""
Expand Down
2 changes: 1 addition & 1 deletion oras/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright The ORAS Authors."
__license__ = "Apache-2.0"

__version__ = "0.2.42"
__version__ = "0.2.43"
AUTHOR = "Vanessa Sochat"
EMAIL = "vsoch@users.noreply.github.com"
NAME = "oras"
Expand Down
Loading