Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm almost all remainders of ctx_repository #1077

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 0 additions & 5 deletions cnudie/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def iter(
prune_unique: bool=True,
node_filter: collections.abc.Callable[[Node], bool]=None,
ocm_repo: ocm.OcmRepository | str=None,
ctx_repo: ocm.OcmRepository | str=None, # deprecated, use `ocm_repo` instead
component_filter: collections.abc.Callable[[ocm.Component], bool]=None,
reftype_filter: collections.abc.Callable[[NodeReferenceType], bool]=None,
) -> collections.abc.Generator[Node, None, None]:
Expand All @@ -113,16 +112,12 @@ def iter(
@param prune_unique: if true, redundant component-versions will only be traversed once
@param node_filter: use to filter emitted nodes (see Filter for predefined filters)
@param ocm_repo: optional OCM Repository to be used to override in the lookup
@param ctx_repo: deprecated, use `ocm_repo` instead
@param component_filter: use to exclude components (and their references) from the iterator;
thereby `True` means the component should be filtered out
@param reftype_filter: use to exclude components (and their references) from the iterator if
they are of a certain reference type; thereby `True` means the component
should be filtered out
'''
if not ocm_repo and ctx_repo:
ocm_repo = ctx_repo

if isinstance(component, ocm.ComponentDescriptor):
component = component.component

Expand Down
5 changes: 0 additions & 5 deletions cnudie/iter_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ async def iter(
prune_unique: bool=True,
node_filter: collections.abc.Callable[[cnudie.iter.Node], bool]=None,
ocm_repo: ocm.OcmRepository | str=None,
ctx_repo: ocm.OcmRepository | str=None, # deprecated, use `ocm_repo` instead
component_filter: collections.abc.Callable[[ocm.Component], bool]=None,
reftype_filter: collections.abc.Callable[[cnudie.iter.NodeReferenceType], bool]=None,
) -> collections.abc.AsyncGenerator[cnudie.iter.Node, None, None]:
Expand All @@ -32,16 +31,12 @@ async def iter(
@param prune_unique: if true, redundant component-versions will only be traversed once
@param node_filter: use to filter emitted nodes (see Filter for predefined filters)
@param ocm_repo: optional OCM Repository to be used to override in the lookup
@param ctx_repo: deprecated, use `ocm_repo` instead
@param component_filter: use to exclude components (and their references) from the iterator;
thereby `True` means the component should be filtered out
@param reftype_filter: use to exclude components (and their references) from the iterator if
they are of a certain reference type; thereby `True` means the component
should be filtered out
'''
if not ocm_repo and ctx_repo:
ocm_repo = ctx_repo

if isinstance(component, ocm.ComponentDescriptor):
component = component.component

Expand Down
101 changes: 34 additions & 67 deletions cnudie/retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,12 @@ def writeback(

def lookup(
component_id: ocm.ComponentIdentity,
ctx_repo: ocm.OcmRepository=None,
ccwienk marked this conversation as resolved.
Show resolved Hide resolved
ocm_repository_lookup=ocm_repository_lookup,
):
if ctx_repo:
ocm_repos = (ctx_repo,)

else:
ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)
ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)

for ocm_repo in ocm_repos:
if isinstance(ocm_repo, str):
Expand Down Expand Up @@ -246,16 +241,12 @@ def writeback(

def lookup(
component_id: cnudie.util.ComponentId,
ctx_repo: ocm.OcmRepository|str=None,
ocm_repository_lookup: OcmRepositoryLookup=ocm_repository_lookup,
):
if ctx_repo:
ocm_repos = (ctx_repo, )
else:
ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)
ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)

for ocm_repo in ocm_repos:
if not ocm_repo:
Expand Down Expand Up @@ -326,19 +317,15 @@ def delivery_service_component_descriptor_lookup(

def lookup(
component_id: ocm.ComponentIdentity,
ctx_repo: ocm.OcmRepository=None,
ocm_repository_lookup: OcmRepositoryLookup=ocm_repository_lookup,
absent_ok: bool=default_absent_ok,
ignore_errors: tuple[Exception]=default_ignore_errors,
):
component_id = cnudie.util.to_component_id(component_id)
if ctx_repo:
ocm_repos = (ctx_repo, )
else:
ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)
ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)

# if component descriptor is not found in `ocm_repos`, fallback to default ocm repo mapping
# defined in delivery service (i.e. specify no ocm repository)
Expand Down Expand Up @@ -487,27 +474,23 @@ def oci_component_descriptor_lookup(

def lookup(
component_id: ocm.ComponentIdentity,
ctx_repo: ocm.OcmRepository=None,
ocm_repository_lookup: OcmRepositoryLookup=ocm_repository_lookup,
absent_ok=default_absent_ok,
):
if not ocm_repository_lookup:
raise ValueError('ocm_repository_lookup must be passed')

component_id = cnudie.util.to_component_id(component_id)

if isinstance(oci_client, collections.abc.Callable):
local_oci_client = oci_client()
else:
local_oci_client = oci_client

if ctx_repo:
ocm_repos = (ctx_repo,)
else:
if not ocm_repository_lookup:
raise ValueError('either ctx_repo, or ocm_repository_lookup must be passed')

ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)
ocm_repos = iter_ocm_repositories(
component_id,
ocm_repository_lookup,
)

raw = raw_component_descriptor_from_oci(
component_id=component_id,
Expand Down Expand Up @@ -566,18 +549,14 @@ def version_lookup(

def lookup(
component_id: ComponentName,
ctx_repo: ocm.OcmRepository=None,
ocm_repository_lookup: OcmRepositoryLookup=ocm_repository_lookup,
absent_ok: bool=default_absent_ok,
):
component_name = cnudie.util.to_component_name(component_id)
if ctx_repo:
ocm_repos = (ctx_repo, )
else:
ocm_repos = iter_ocm_repositories(
component_name,
ocm_repository_lookup,
)
ocm_repos = iter_ocm_repositories(
component_name,
ocm_repository_lookup,
)

versions = set()
for ocm_repo in ocm_repos:
Expand All @@ -592,7 +571,7 @@ def lookup(
try:
for version_tag in component_versions(
component_name=component_name,
ctx_repo=ocm_repo,
ocm_repo=ocm_repo,
oci_client=oci_client,
):
versions.add(version_tag)
Expand Down Expand Up @@ -635,7 +614,6 @@ def composite_component_descriptor_lookup(
def lookup(
component_id: ocm.ComponentIdentity,
/,
ctx_repo: ocm.OciOcmRepository|str=None,
ocm_repository_lookup=ocm_repository_lookup,
absent_ok=default_absent_ok,
):
Expand All @@ -644,13 +622,10 @@ def lookup(
for lookup in lookups:
res = None
try:
if ctx_repo:
res = lookup(
component_id,
ctx_repo=ctx_repo,
)
else:
res = lookup(component_id)
res = lookup(
component_id,
ocm_repository_lookup=ocm_repository_lookup,
)
except om.OciImageNotFoundException:
pass
except dacite.DaciteError as ce:
Expand All @@ -671,15 +646,7 @@ def lookup(
if absent_ok:
return

if isinstance(ctx_repo, str):
ctx_repo = ocm.OciOcmRepository(
type=ocm.OciAccess,
baseUrl=ctx_repo,
)

if ctx_repo:
error = ctx_repo.component_version_oci_ref(component_id)
elif ocm_repository_lookup:
if ocm_repository_lookup:
def to_repo_url(ocm_repo):
if isinstance(ocm_repo, str):
return ocm_repo
Expand Down Expand Up @@ -818,17 +785,17 @@ def component_diff(

def component_versions(
component_name: str,
ctx_repo: ocm.OcmRepository,
ocm_repo: ocm.OcmRepository,
oci_client: oc.Client=None,
) -> collections.abc.Sequence[str]:
if not isinstance(ctx_repo, ocm.OciOcmRepository):
raise NotImplementedError(ctx_repo)
if not isinstance(ocm_repo, ocm.OciOcmRepository):
raise NotImplementedError(ocm_repo)

if not oci_client:
import ccc.oci
oci_client = ccc.oci.oci_client()

ctx_repo: ocm.OciOcmRepository
oci_ref = ctx_repo.component_oci_ref(component_name)
ocm_repo: ocm.OciOcmRepository
oci_ref = ocm_repo.component_oci_ref(component_name)

return oci_client.tags(image_reference=oci_ref)
Loading