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
17 changes: 16 additions & 1 deletion commodore/component/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def class_file(self) -> P:
def defaults_file(self) -> P:
return self.alias_defaults_file(self.name)

def alias_directory(self, alias: str) -> P:
def _alias_path(self, alias: str) -> P:
if alias not in self._aliases:
raise ValueError(
f"alias {alias} for component {self.name} has not been registered"
Expand All @@ -154,6 +154,10 @@ def alias_directory(self, alias: str) -> P:
# alias's multi-dependency. The assert makes mypy happy. We disable bandit's
# "assert_used" lint, since we don't rely on this assertion for correctness.
assert apath # nosec B101
return apath

def alias_directory(self, alias: str) -> P:
apath = self._alias_path(alias)
return apath / self._aliases[alias][1]

def alias_class_file(self, alias: str) -> P:
Expand All @@ -165,6 +169,17 @@ def alias_defaults_file(self, alias: str) -> P:
def has_alias(self, alias: str):
return alias in self._aliases

def alias_info(self, alias: str) -> tuple[str, str, MultiDependency]:
if alias not in self._aliases:
raise ValueError(
f"alias {alias} for component {self.name} has not been registered"
)
return self._aliases[alias]

def alias_repo(self, alias: str) -> GitRepo:
apath = self._alias_path(alias)
return GitRepo(None, apath)

@property
def lib_files(self) -> Iterable[P]:
# NOTE(sg): Usage of yield makes the whole function return a generator.
Expand Down
16 changes: 9 additions & 7 deletions commodore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ def pretty_print(self, name: str) -> str:


class InstanceVersionInfo(VersionInfo):
def __init__(self, component: Component):
def __init__(self, name: str, component: Component):
version, path, dep = component.alias_info(name)
arepo = component.alias_repo(name)
super().__init__(
component.repo_url,
component.version or component.repo.default_version,
component.repo.head_sha,
component.repo.head_short_sha,
path=component.sub_path,
dep.url,
version,
arepo.head_sha,
arepo.head_short_sha,
path=path,
)
self.component = component.name

Expand Down Expand Up @@ -406,7 +408,7 @@ def verify_component_aliases(

def get_component_alias_versioninfos(self) -> dict[str, InstanceVersionInfo]:
return {
a: InstanceVersionInfo(self._components[cn])
a: InstanceVersionInfo(a, self._components[cn])
for a, cn in self._component_aliases.items()
}

Expand Down
45 changes: 31 additions & 14 deletions tests/test_compile_meta.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import os

from datetime import datetime, timedelta
Expand All @@ -14,7 +15,7 @@
from commodore.dependency_mgmt import fetch_components, fetch_packages
from commodore.gitrepo import GitRepo

from test_dependency_mgmt import setup_components_upstream, _setup_packages
from test_dependency_mgmt import setup_aliases_upstream, _setup_packages

from commodore.catalog import CompileMeta
from commodore.cluster import report_compile_metadata
Expand Down Expand Up @@ -81,18 +82,34 @@ def test_compile_meta_creation(
components = ["foo", "bar", "baz", "qux"]
packages = ["foo", "bar"]

# setup mock components
patch_discover_components.return_value = (components, {})
# setup_components_upstream sets version=None for all components
cdeps = setup_components_upstream(tmp_path, components)
# foo,bar,baz are setup as "standard" upstreams
aliases = {cn: cn for cn in components if cn != "qux"}
# the actual aliases and qux need to be handled separately
aliases2 = {"qux": "qux", "quxxer": "qux", "barer": "bar"}

# NOTE: We assume that setup_components_upstream creates upstream repos in
# setup_aliases_upstream sets version=None for all components
cdeps = setup_aliases_upstream(tmp_path, aliases.items())
# create upstream for `qux` with subpath
cdeps.update(
setup_aliases_upstream(tmp_path, [("qux", "qux")], sub_path="component")
)
# We manually create copies of `qux` and `bar` to prepare the alias upstreams
cdeps["quxxer"] = copy.deepcopy(cdeps["qux"])
cdeps["barer"] = copy.deepcopy(cdeps["bar"])

# setup mock components, we want the full aliases dict here
aliases.update(aliases2)
patch_discover_components.return_value = (components, aliases)

# NOTE: We assume that setup_aliases_upstream creates upstream repos in
# `tmp_path/upstream/<component-name>`
crepos = {cn: git.Repo(tmp_path / "upstream" / cn) for cn in components}

crepos["foo"].version = "master"
crepos["bar"].create_tag("v1.2.3")
# Setup separate versions for bar and it's alias
cdeps["bar"].version = "v1.2.3"
cdeps["barer"].version = "master"
cdeps["baz"].version = crepos["baz"].head.commit.hexsha

patch_read_components.return_value = cdeps
Expand All @@ -113,13 +130,6 @@ def test_compile_meta_creation(
fetch_packages(config)
fetch_components(config)

config.get_components()["qux"]._sub_path = "component"

aliases = {cn: cn for cn in components}
# create alias to verify instance reporting
aliases["quxxer"] = "qux"
config.register_component_aliases(aliases)

meta = CompileMeta(config)
meta_dict = meta.as_dict()
assert set(meta_dict.keys()) == {
Expand All @@ -146,7 +156,14 @@ def test_compile_meta_creation(
) < timedelta(seconds=1)

# check instances
assert set(meta_dict["instances"].keys()) == {"foo", "bar", "baz", "qux", "quxxer"}
assert set(meta_dict["instances"].keys()) == {
"foo",
"bar",
"barer",
"baz",
"qux",
"quxxer",
}
for alias, info in meta_dict["instances"].items():
cn = alias[0:3]
assert len({"url", "version", "gitSha", "component"} - set(info.keys())) == 0
Expand Down