Skip to content

Commit

Permalink
Streamline source prefix comparison in can_bundle script
Browse files Browse the repository at this point in the history
  • Loading branch information
nadove-ucsc committed Sep 11, 2024
1 parent 0c83d89 commit ba1dcde
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 63 deletions.
7 changes: 4 additions & 3 deletions scripts/can_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import uuid

import attr
from more_itertools import (
one,
)
Expand Down Expand Up @@ -89,9 +90,9 @@ def fetch_bundle(source: str, bundle_uuid: str, bundle_version: str) -> Bundle:
else:
log.debug('Searching for %r in catalog %r', source, catalog)
for plugin_source_spec in plugin.sources:
if source_ref.spec.contains(plugin_source_spec):
plugin_source_ref = plugin.resolve_source(str(plugin_source_spec))
fqid = SourcedBundleFQIDJSON(source=plugin_source_ref.to_json(),
if source_ref.spec == attr.evolve(plugin_source_spec,
prefix=source_ref.spec.prefix):
fqid = SourcedBundleFQIDJSON(source=source_ref.to_json(),
uuid=bundle_uuid,
version=bundle_version)
fqid = plugin.resolve_bundle(fqid)
Expand Down
38 changes: 0 additions & 38 deletions src/azul/indexer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,28 +225,6 @@ def _parse(cls, spec: str) -> tuple[str, Prefix]:
def __str__(self) -> str:
raise NotImplementedError

def contains(self, other: 'SourceSpec') -> bool:
"""
>>> p = SimpleSourceSpec.parse
>>> p('foo:4/0').contains(p('foo:42/0'))
True
>>> p('foo:42/0').contains(p('foo:4/0'))
False
>>> p('foo:42/0').contains(p('foo:42/0'))
True
>>> p('foo:42/0').contains(p('foo:42/1'))
True
>>> p('foo:1/0').contains(p('foo:2/0'))
False
"""
assert isinstance(other, SourceSpec), (self, other)
return other.prefix.common.startswith(self.prefix.common)


@attrs.frozen(kw_only=True)
class SimpleSourceSpec(SourceSpec['SimpleSourceSpec']):
Expand Down Expand Up @@ -299,22 +277,6 @@ def __str__(self) -> str:
"""
return f'{self.name}:{self.prefix}'

def contains(self, other: 'SourceSpec') -> bool:
"""
>>> p = SimpleSourceSpec.parse
>>> p('foo:/0').contains(p('foo:/0'))
True
>>> p('foo:/0').contains(p('bar:/0'))
False
"""
return (
isinstance(other, SimpleSourceSpec)
and super().contains(other)
and self.name == other.name
)


class SourceJSON(TypedDict):
id: str
Expand Down
22 changes: 0 additions & 22 deletions src/azul/terra.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,6 @@ def __str__(self) -> str:
def qualify_table(self, table_name: str) -> str:
return '.'.join((self.subdomain, self.name, table_name))

def contains(self, other: 'SourceSpec') -> bool:
"""
>>> p = TDRSourceSpec.parse
>>> p('tdr:bigquery:gcp:foo:bar:/0').contains(p('tdr:bigquery:gcp:foo:bar:/0'))
True
>>> p('tdr:bigquery:gcp:foo:bar:/0').contains(p('tdr:bigquery:gcp:bar:bar:/0'))
False
>>> p('tdr:bigquery:gcp:foo:bar:/0').contains(p('tdr:bigquery:gcp:foo:baz:/0'))
False
"""
return (
isinstance(other, TDRSourceSpec)
and super().contains(other)
and self.type == other.type
and self.domain == other.domain
and self.subdomain == other.subdomain
and self.name == other.name
)


class SourceRef(BaseSourceRef[TDRSourceSpec, 'TDRSourceRef']):
pass
Expand Down

0 comments on commit ba1dcde

Please sign in to comment.