Skip to content
Draft
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
35 changes: 0 additions & 35 deletions kapitan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +0,0 @@
#!/usr/bin/env python3

# Copyright 2019 The Kapitan Authors
# SPDX-FileCopyrightText: 2020 The Kapitan Authors <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import sys


def setup_logging(name=None, level=logging.INFO, force=False):
"setup logging and deal with logging behaviours in MacOS python 3.8 and below"
# default opts
kwopts = {"format": "%(message)s", "level": level}

if level == logging.DEBUG:
kwopts["format"] = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"

if sys.version_info >= (3, 8) and force:
kwopts["force"] = True

logging.basicConfig(**kwopts)

if sys.version_info < (3, 8) and force:
logging.getLogger(name).setLevel(level)


# XXX in MacOS, updating logging level in __main__ doesn't work for python3.8+
# XXX this is a hack that seems to work
if "-v" in sys.argv or "--verbose" in sys.argv:
setup_logging(level=logging.DEBUG)
else:
setup_logging()
19 changes: 17 additions & 2 deletions kapitan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@

import argparse
import json
import logging
import multiprocessing
import os
import sys

import yaml
from rich.console import Console

from kapitan import cached, defaults, setup_logging
from kapitan import cached, defaults
from kapitan.errors import KapitanError
from kapitan.initialiser import initialise_skeleton
from kapitan.inputs.jsonnet import select_jsonnet_runtime
from kapitan.inventory import AVAILABLE_BACKENDS, InventoryBackends
from kapitan.lint import start_lint
from kapitan.logging import logging, setup_logging
from kapitan.refs.base import RefController, Revealer
from kapitan.refs.cmd_parser import handle_refs_command
from kapitan.resources import generate_inventory, resource_callbacks, search_imports
Expand Down Expand Up @@ -639,3 +641,16 @@ def main():
args.func(args)

return 0


def console():
console = Console()
try:
main()
except Exception:
console.print_exception()
sys.exit(1)


if __name__ == "__main__":
console()
2 changes: 1 addition & 1 deletion kapitan/dependency_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: Apache-2.0

import hashlib
import logging
import multiprocessing
import os
from collections import defaultdict, namedtuple
Expand All @@ -16,6 +15,7 @@
from kapitan.errors import GitFetchingError, GitSubdirNotFoundError, HelmFetchingError
from kapitan.helm_cli import helm_cli
from kapitan.inventory.model.dependencies import KapitanDependencyTypes
from kapitan.logging import logging
from kapitan.utils import (
copy_tree,
make_request,
Expand Down
3 changes: 2 additions & 1 deletion kapitan/helm_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import os
import subprocess
from subprocess import DEVNULL, PIPE

from kapitan.logging import logging

logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion kapitan/initialiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"initialiser module"

import glob
import logging
import os

from copier import run_copy

from kapitan.errors import KapitanError
from kapitan.logging import logging
from kapitan.version import VERSION as kapitan_version

logger = logging.getLogger(__name__)
Expand Down
22 changes: 8 additions & 14 deletions kapitan/inputs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import glob
import itertools
import json
import logging
import os
from collections.abc import Mapping

Expand All @@ -19,6 +18,7 @@
from kapitan import cached
from kapitan.errors import CompileError, KapitanError
from kapitan.inventory.model.input_types import CompileInputTypeConfig, OutputType
from kapitan.logging import logging
from kapitan.refs.base import Revealer
from kapitan.utils import PrettyDumper, prune_empty

Expand Down Expand Up @@ -156,20 +156,14 @@ def compile_input_path(self, comp_obj: CompileInputTypeConfig, input_path: str):

logger.debug("Compiling %s", input_path)

try:
target_compile_path = os.path.join(self.compile_path, target_name.replace(".", "/"), output_path)
os.makedirs(target_compile_path, exist_ok=True)
target_compile_path = os.path.join(self.compile_path, target_name.replace(".", "/"), output_path)
os.makedirs(target_compile_path, exist_ok=True)

self.compile_file(
comp_obj,
input_path,
target_compile_path,
)

except KapitanError as e:
raise CompileError(
"{}\nCompile error: failed to compile target: {}".format(e, target_name)
) from e
self.compile_file(
comp_obj,
input_path,
target_compile_path,
)

@abc.abstractmethod
def compile_file(self, config: CompileInputTypeConfig, input_path: str, compile_path: str):
Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import shutil

from kapitan.inputs.base import InputType
from kapitan.inventory.model.input_types import KapitanInputTypeCopyConfig
from kapitan.logging import logging
from kapitan.utils import copy_tree

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import re
import subprocess
from typing import Dict, List

from kapitan.inputs.base import InputType
from kapitan.inventory.model.input_types import KapitanInputTypeExternalConfig
from kapitan.logging import logging

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import tempfile

Expand All @@ -16,6 +15,7 @@
from kapitan.inputs.base import CompiledFile, InputType
from kapitan.inputs.kadet import BaseModel, BaseObj
from kapitan.inventory.model.input_types import KapitanInputTypeHelmConfig
from kapitan.logging import logging

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#
# SPDX-License-Identifier: Apache-2.0

import logging
import os

from kapitan import cached
from kapitan.inputs.base import CompiledFile, InputType
from kapitan.inventory.model.input_types import KapitanInputTypeJinja2Config
from kapitan.logging import logging
from kapitan.utils import render_jinja2

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/jsonnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# SPDX-License-Identifier: Apache-2.0

import json
import logging
import os

from kapitan.errors import CompileError
from kapitan.inputs.base import InputType
from kapitan.inventory.model.input_types import KapitanInputTypeJsonnetConfig
from kapitan.logging import logging
from kapitan.resources import resource_callbacks, search_imports

logger = logging.getLogger(__name__)
Expand Down
8 changes: 5 additions & 3 deletions kapitan/inputs/kadet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import contextvars
import inspect
import logging
import os
import sys
from functools import lru_cache
Expand All @@ -20,6 +19,7 @@
from kapitan.errors import CompileError
from kapitan.inputs.base import InputType
from kapitan.inventory.model.input_types import KapitanInputTypeKadetConfig
from kapitan.logging import logging

# Set external kadet exception to kapitan.error.CompileError
kadet.ABORT_EXCEPTION_TYPE = CompileError
Expand Down Expand Up @@ -110,7 +110,10 @@ def compile_file(self, config: KapitanInputTypeKadetConfig, input_path, compile_

kadet_module, spec = module_from_path(input_path)
sys.modules[spec.name] = kadet_module
spec.loader.exec_module(kadet_module)
try:
spec.loader.exec_module(kadet_module)
except Exception as e:
raise CompileError(f"{spec.name} - {e}")
logger.debug("Kadet.compile_file: spec.name: %s", spec.name)

kadet_arg_spec = inspect.getfullargspec(kadet_module.main)
Expand All @@ -128,7 +131,6 @@ def compile_file(self, config: KapitanInputTypeKadetConfig, input_path, compile_

except Exception as exc:
# Log traceback and exception as is
logger.exception("")
raise CompileError(f"Could not load Kadet module: {spec.name[16:]}") from exc

output_obj = _to_dict(output_obj)
Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import shutil

from kapitan.inputs.base import InputType
from kapitan.inventory.model.input_types import KapitanInputTypeCopyConfig
from kapitan.logging import logging

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kapitan/inventory/backends/omegaconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
# SPDX-License-Identifier: Apache-2.0

import logging
import multiprocessing as mp
import os
import time
Expand All @@ -19,6 +18,7 @@
from kapitan.errors import InventoryError
from kapitan.inventory import Inventory, InventoryTarget
from kapitan.inventory.model import KapitanInventoryMetadata, KapitanInventoryParameters
from kapitan.logging import logging

from .migrate import migrate
from .resolvers import register_resolvers
Expand Down
3 changes: 2 additions & 1 deletion kapitan/inventory/backends/omegaconf/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
# SPDX-License-Identifier: Apache-2.0

import copy
import logging
import os
import sys
from typing import Any

import yaml
from omegaconf import Container, ListMergeMode, Node, OmegaConf

from kapitan.logging import logging

logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion kapitan/inventory/backends/reclass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
from datetime import datetime

Expand All @@ -9,6 +8,7 @@

from kapitan.errors import InventoryError
from kapitan.inventory import Inventory, InventoryTarget
from kapitan.logging import logging

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kapitan/inventory/backends/reclass_rs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from datetime import datetime

import reclass_rs

from kapitan.errors import InventoryError
from kapitan.inventory import Inventory
from kapitan.inventory.backends.reclass import get_reclass_config
from kapitan.logging import logging

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kapitan/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# SPDX-License-Identifier: Apache-2.0

import functools
import logging
import os
from abc import ABC, abstractmethod
from typing import Dict
Expand All @@ -15,6 +14,7 @@

from kapitan.errors import InventoryError
from kapitan.inventory.model import KapitanInventoryParameters
from kapitan.logging import logging

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kapitan/jinja2_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import base64
import datetime
import glob
import logging
import os
import re
import stat
Expand All @@ -26,6 +25,7 @@

from kapitan import cached, defaults, utils
from kapitan.errors import CompileError
from kapitan.logging import logging

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kapitan/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"lint module"

import logging
import os
import sys
from pprint import pformat
Expand All @@ -16,6 +15,7 @@
from yamllint.config import YamlLintConfig

from kapitan.errors import KapitanError
from kapitan.logging import logging
from kapitan.utils import list_all_paths

logger = logging.getLogger(__name__)
Expand Down
Loading
Loading