Skip to content

Commit

Permalink
fix typo in ignore_class_not_found
Browse files Browse the repository at this point in the history
  • Loading branch information
ademariag committed May 9, 2024
1 parent ebdc214 commit c4751e8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 116 deletions.
10 changes: 5 additions & 5 deletions kapitan/inventory/inv_reclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

class ReclassInventory(Inventory):

def render_targets(self, targets: list[InventoryTarget] = None, ignore_class_notfound: bool = False) -> None:
def render_targets(self, targets: list[InventoryTarget] = None, ignore_class_not_found: bool = False) -> None:
"""
Runs a reclass inventory in inventory_path
(same output as running ./reclass.py -b inv_base_uri/ --inventory)
Will attempt to read reclass config from 'reclass-config.yml' otherwise
it will fall back to the default config.
Returns a reclass style dictionary
Does not throw errors if a class is not found while ignore_class_notfound is specified
Does not throw errors if a class is not found while ignore_class_not_found is specified
"""
reclass_config = get_reclass_config(
self.inventory_path, ignore_class_notfound, self.compose_target_name
self.inventory_path, ignore_class_not_found, self.compose_target_name
)

try:
Expand Down Expand Up @@ -62,7 +62,7 @@ def render_targets(self, targets: list[InventoryTarget] = None, ignore_class_not

def get_reclass_config(
inventory_path: str,
ignore_class_notfound: bool = False,
ignore_class_not_found: bool = False,
compose_target_name: bool = False,
normalise_nodes_classes: bool = True,
) -> dict:
Expand All @@ -74,7 +74,7 @@ def get_reclass_config(
"classes_uri": "classes",
"compose_node_name": compose_target_name,
"allow_none_override": True,
"ignore_class_notfound": ignore_class_notfound,
"ignore_class_not_found": ignore_class_not_found,
}
try:
from yaml import CSafeLoader as YamlLoader
Expand Down
8 changes: 4 additions & 4 deletions kapitan/inventory/inv_reclass_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@


class ReclassRsInventory(Inventory):
def _make_reclass_rs(self, ignore_class_notfound: bool):
def _make_reclass_rs(self, ignore_class_not_found: bool):
# Get Reclass config options with the same method that's used for `ReclassInventory`, but
# disable the logic to normalise the `nodes_uri` and `classes_uri` options, since reclass-rs
# expects those fields to be relative to the inventory path.
config_dict = get_reclass_config(
self.inventory_path, ignore_class_notfound, self.compose_target_name, False
self.inventory_path, ignore_class_not_found, self.compose_target_name, False
)

# Turn on verbose config loading only if Kapitan loglevel is set to at least DEBUG.
Expand All @@ -27,9 +27,9 @@ def _make_reclass_rs(self, ignore_class_notfound: bool):
)
return reclass_rs.Reclass.from_config(config)

def render_targets(self, targets: list = None, ignore_class_notfound: bool = False):
def render_targets(self, targets: list = None, ignore_class_not_found: bool = False):
try:
r = self._make_reclass_rs(ignore_class_notfound)
r = self._make_reclass_rs(ignore_class_not_found)
start = datetime.now()
inv = r.inventory()
elapsed = datetime.now() - start
Expand Down
4 changes: 2 additions & 2 deletions kapitan/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class InventoryTarget(BaseModel):


class Inventory(ABC):
def __init__(self, inventory_path: str = "inventory", compose_target_name: bool = False, ignore_class_notfound=False):
def __init__(self, inventory_path: str = "inventory", compose_target_name: bool = False, ignore_class_not_found=False):
self.inventory_path = inventory_path
self.compose_target_name = compose_target_name
self.targets_path = os.path.join(self.inventory_path, 'targets')
self.classes_path = os.path.join(self.inventory_path, 'classes')
self.initialised: bool = False
self.targets: dict[str, InventoryTarget] = {}

self.__initialise(ignore_class_not_found=ignore_class_notfound)
self.__initialise(ignore_class_not_found=ignore_class_not_found)

@property
def inventory(self) -> dict:
Expand Down
4 changes: 2 additions & 2 deletions kapitan/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def generate_inventory(args):
sys.exit(1)


def get_inventory(inventory_path, ignore_class_notfound: bool = False) -> Inventory:
def get_inventory(inventory_path, ignore_class_not_found: bool = False) -> Inventory:
"""
generic inventory function that makes inventory backend pluggable
default backend is reclass
Expand All @@ -329,7 +329,7 @@ def get_inventory(inventory_path, ignore_class_notfound: bool = False) -> Invent
inventory_backend: Inventory = None

logger.debug(f"Using {backend_id} as inventory backend")
inventory_backend = backend(inventory_path=inventory_path, compose_target_name=compose_target_name, ignore_class_notfound=ignore_class_notfound)
inventory_backend = backend(inventory_path=inventory_path, compose_target_name=compose_target_name, ignore_class_not_found=ignore_class_not_found)

cached.inv = inventory_backend
# migrate inventory to selected inventory backend
Expand Down
18 changes: 9 additions & 9 deletions kapitan/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def compile_targets(

if fetch:
# skip classes that are not yet available
target_objs = load_target_inventory(inventory_path, updated_targets, ignore_class_notfound=True)
target_objs = load_target_inventory(inventory_path, updated_targets, ignore_class_not_found=True)
else:
# ignore_class_notfound = False by default
# ignore_class_not_found = False by default
target_objs = load_target_inventory(inventory_path, updated_targets)

# append "compiled" to output_path so we can safely overwrite it
Expand All @@ -119,14 +119,14 @@ def compile_targets(
)
cached.reset_inv()
target_objs = load_target_inventory(
inventory_path, updated_targets, ignore_class_notfound=True
inventory_path, updated_targets, ignore_class_not_found=True
)
cached.inv_sources.update(new_sources)
new_sources = list(set(list_sources(target_objs)) - cached.inv_sources)
# reset inventory cache and load target objs to check for missing classes
if new_sources:
cached.reset_inv()
target_objs = load_target_inventory(inventory_path, updated_targets, ignore_class_notfound=False)
target_objs = load_target_inventory(inventory_path, updated_targets, ignore_class_not_found=False)
# fetch dependencies
if fetch:
fetch_dependencies(output_path, target_objs, dep_cache_dir, force_fetch, pool)
Expand Down Expand Up @@ -362,10 +362,10 @@ def save_inv_cache(compile_path, targets):
yaml.dump(cached.inv_cache, stream=f, default_flow_style=False)


def load_target_inventory(inventory_path, requested_targets, ignore_class_notfound=False):
def load_target_inventory(inventory_path, requested_targets, ignore_class_not_found=False):
"""returns a list of target objects from the inventory"""
target_objs = []
inv = get_inventory(inventory_path, ignore_class_notfound)
inv = get_inventory(inventory_path, ignore_class_not_found)

# if '-t' is set on compile, only loop through selected targets
if requested_targets:
Expand All @@ -376,17 +376,17 @@ def load_target_inventory(inventory_path, requested_targets, ignore_class_notfou
for target_name, target in targets.items():
try:
if not target.parameters:
if ignore_class_notfound:
if ignore_class_not_found:
continue
else:
raise InventoryError(f"InventoryError: {target_name}: parameters is empty")

kapitan_target_configs = inv.get_parameters(target_name, ignore_class_notfound).get("kapitan")
kapitan_target_configs = inv.get_parameters(target_name, ignore_class_not_found).get("kapitan")
# check if parameters.kapitan is empty
if not kapitan_target_configs:
raise InventoryError(f"InventoryError: {target_name}: parameters.kapitan has no assignment")
kapitan_target_configs["target_full_path"] = inv.targets[target_name].name.replace(".", "/")
require_compile = not ignore_class_notfound
require_compile = not ignore_class_not_found
valid_target_obj(kapitan_target_configs, require_compile)
validate_matching_target_name(target_name, kapitan_target_configs, inventory_path)
logger.debug(f"load_target_inventory: found valid kapitan target {target_name}")
Expand Down
50 changes: 0 additions & 50 deletions tests/test_compile_code.py

This file was deleted.

44 changes: 0 additions & 44 deletions tests/test_omegaconf.py

This file was deleted.

0 comments on commit c4751e8

Please sign in to comment.