Skip to content
Closed
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
20 changes: 19 additions & 1 deletion commodore/component/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pathlib import Path as P
from typing import Iterable, Optional
from typing import Dict, Iterable, Optional

import _jsonnet
import click
import yaml

from commodore.gitrepo import GitRepo

Expand Down Expand Up @@ -71,6 +72,12 @@ def class_file(self) -> P:
def defaults_file(self) -> P:
return self.target_directory / "class" / "defaults.yml"

@property
def default_values(self) -> Dict:
with open(self.defaults_file, "r", encoding="utf-8") as f:
defyaml = list(yaml.safe_load_all(f))
return defyaml[0]["parameters"][self.parameters_key]

@property
def lib_files(self) -> Iterable[P]:
lib_dir = self.target_directory / "lib"
Expand All @@ -79,6 +86,17 @@ def lib_files(self) -> Iterable[P]:

return []

def get_library(self, libname: str) -> P:
lib_dir = self.target_directory / "lib"
if not lib_dir.exists():
return None

for f in self.lib_files:
if f.absolute() == P(lib_dir / libname).absolute():
return f.absolute()

return None

@property
def filters_file(self) -> P:
return self.target_directory / "postprocess" / "filters.yml"
Expand Down
3 changes: 3 additions & 0 deletions commodore/component/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from commodore.dependency_mgmt import (
fetch_jsonnet_libraries,
validate_component_library_name,
create_component_library_aliases,
)
from commodore.helpers import kapitan_compile, relsymlink
from commodore.inventory import Inventory
Expand Down Expand Up @@ -61,6 +62,8 @@ def compile_component(
for lib in component.lib_files:
validate_component_library_name(config, component.name, lib)

create_component_library_aliases(config, component)

# Create class for fake parameters
with open(inv.params_file, "w", encoding="utf-8") as file:
file.write(
Expand Down
21 changes: 21 additions & 0 deletions commodore/dependency_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ def validate_component_library_name(cfg: Config, cname: str, lib: P) -> P:
return lib


def create_component_library_aliases(cfg: Config, component: Component):
aliases = (
component.default_values.get("=_metadata", {})
.get("library_aliases", {})
.items()
)
for libalias, libname in aliases:
if cfg.debug:
click.echo(f" > aliasing template library {libname} to {libalias}")
libf = component.get_library(libname)
if not libf:
click.secho(
f" > [WARN] {component.name} template library alias refers to nonexistent template library",
fg="yellow",
)
else:
relsymlink(libf, cfg.inventory.lib_dir, dest_name=libalias)


def create_component_symlinks(cfg, component: Component):
"""
Create symlinks in the inventory subdirectory.
Expand All @@ -49,6 +68,8 @@ def create_component_symlinks(cfg, component: Component):
cfg.inventory.lib_dir,
)

create_component_library_aliases(cfg, component)


def _format_component_list(components: Iterable[str]) -> str:
formatted_list = list(map(lambda c: f"'{c}'", sorted(components)))
Expand Down