Skip to content

Commit

Permalink
apply black and isort fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ademariag committed Sep 1, 2024
1 parent 3c86dc8 commit 0f2f7b6
Show file tree
Hide file tree
Showing 47 changed files with 348 additions and 232 deletions.
5 changes: 3 additions & 2 deletions examples/docker/components/kadet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import json
from kapitan.resources import jinja2_render_file
import os

from kapitan.inputs import kadet
from kapitan.resources import jinja2_render_file

inventory = kadet.inventory()

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

import logging
import os
import sys
import logging


def setup_logging(name=None, level=logging.INFO, force=False):
Expand Down
2 changes: 1 addition & 1 deletion kapitan/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
dot_kapitan = {}
ref_controller_obj = None
revealer_obj = None
args = Namespace() # args won't need resetting
args = Namespace() # args won't need resetting
inv_sources = set()


Expand Down
23 changes: 16 additions & 7 deletions kapitan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,20 @@ def trigger_compile(args):
jinja2_filters=args.jinja2_filters,
verbose=args.verbose,
use_go_jsonnet=args.use_go_jsonnet,
compose_target_name=args.compose_target_name
compose_target_name=args.compose_target_name,
)


def build_parser():
parser = argparse.ArgumentParser(prog=PROJECT_NAME, description=DESCRIPTION)
parser.add_argument("--version", action="version", version=VERSION)
parser.add_argument("--mp-method", action="store", default=from_dot_kapitan("global", "mp-method", "spawn"), help="set multiprocessing start method", choices=["spawn", "fork", "forkserver"])
parser.add_argument(
"--mp-method",
action="store",
default=from_dot_kapitan("global", "mp-method", "spawn"),
help="set multiprocessing start method",
choices=["spawn", "fork", "forkserver"],
)
subparser = parser.add_subparsers(help="commands", dest="subparser_name")

inventory_backend_parser = argparse.ArgumentParser(add_help=False)
Expand All @@ -120,10 +126,13 @@ def build_parser():
)

inventory_backend_parser.add_argument(
"--compose-target-name", "--compose-target-name",
"--compose-target-name",
"--compose-target-name",
help="Create same subfolder structure from inventory/targets inside compiled folder",
action="store_true",
default=from_dot_kapitan("global", "compose-target-name", from_dot_kapitan("compile", "compose-node-name", False)),
default=from_dot_kapitan(
"global", "compose-target-name", from_dot_kapitan("compile", "compose-node-name", False)
),
)

eval_parser = subparser.add_parser("eval", aliases=["e"], help="evaluate jsonnet file")
Expand Down Expand Up @@ -612,7 +621,7 @@ def main():
# and will raise RuntimeError
except RuntimeError:
pass

if getattr(args, "func", None) == generate_inventory and args.pattern and args.target_name == "":
parser.error("--pattern requires --target_name")

Expand All @@ -622,8 +631,8 @@ def main():
parser.print_help()
sys.exit(1)

cached.args = args
cached.args = args

if hasattr(args, "verbose") and args.verbose:
logging_level = logging.DEBUG
elif hasattr(args, "quiet") and args.quiet:
Expand Down
18 changes: 10 additions & 8 deletions kapitan/dependency_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
from mimetypes import MimeTypes
from shutil import copyfile, rmtree

from git import GitCommandError
from git import Repo
from kapitan.errors import GitSubdirNotFoundError, GitFetchingError, HelmFetchingError
from git import GitCommandError, Repo

from kapitan.errors import GitFetchingError, GitSubdirNotFoundError, HelmFetchingError
from kapitan.helm_cli import helm_cli
from kapitan.utils import (
copy_tree,
make_request,
unpack_downloaded_file,
safe_copy_tree,
safe_copy_file,
normalise_join_path,
safe_copy_file,
safe_copy_tree,
unpack_downloaded_file,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -235,10 +235,12 @@ def fetch_helm_chart(dep_mapping, save_dir, force):

for dep in deps:
output_path = dep["output_path"]

if not os.path.exists(output_path) or force:
if not exists_in_cache(cached_repo_path):
fetch_helm_archive(source.helm_path, source.repo, source.chart_name, source.version, cached_repo_path)
fetch_helm_archive(
source.helm_path, source.repo, source.chart_name, source.version, cached_repo_path
)
else:
logger.debug("Using cached helm chart at %s", cached_repo_path)

Expand Down
1 change: 1 addition & 0 deletions kapitan/initialiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import logging
import os

from kapitan.utils import copy_tree

logger = logging.getLogger(__name__)
Expand Down
8 changes: 4 additions & 4 deletions kapitan/inputs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import os
from collections.abc import Mapping

import yaml
import toml
import yaml

from kapitan import cached
from kapitan.errors import CompileError, KapitanError
from kapitan.refs.base import Revealer
from kapitan.utils import PrettyDumper
from kapitan import cached

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -129,14 +129,14 @@ def write_yaml(self, obj):
# TODO(ademaria): make it configurable per input type
style_selection = cached.inv[target_name]["parameters"].get("multiline_string_style", None)

if not style_selection:
if not style_selection:
if hasattr(cached.args, "multiline_string_style"):
style_selection = cached.args.multiline_string_style
elif hasattr(cached.args, "yaml_multiline_string_style"):
style_selection = cached.args.yaml_multiline_string_style

dumper = PrettyDumper.get_dumper_for_style(style_selection)

if reveal:
obj = self.revealer.reveal_obj(obj)
else:
Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import logging
import os
import shutil
from kapitan.utils import copy_tree

from kapitan.inputs.base import InputType
from kapitan.utils import copy_tree

logger = logging.getLogger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions 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 subprocess
import re
import logging
import os
import re
import shutil
from kapitan.utils import copy_tree
import subprocess

from kapitan.inputs.base import InputType
from kapitan.utils import copy_tree

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion kapitan/inputs/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import logging
import os

from kapitan import cached
from kapitan.inputs.base import CompiledFile, InputType
from kapitan.resources import inventory
from kapitan.utils import render_jinja2
from kapitan import cached

logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion kapitan/inputs/jinja2_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

import toml
import yaml
from six import string_types

from kapitan import cached, defaults, utils
from kapitan.errors import CompileError
from six import string_types

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 @@ -10,16 +10,17 @@
import logging
import os
import sys
from importlib.util import module_from_spec, spec_from_file_location
import time
from functools import lru_cache
from importlib.util import module_from_spec, spec_from_file_location

import kadet
from kadet import BaseModel, BaseObj, Dict

from kapitan import cached
from kapitan.errors import CompileError
from functools import lru_cache
from kapitan.inputs.base import CompiledFile, InputType
from kapitan.utils import prune_empty
from kapitan import cached

# Set external kadet exception to kapitan.error.CompileError
kadet.ABORT_EXCEPTION_TYPE = CompileError
Expand Down Expand Up @@ -65,6 +66,7 @@ def module_from_path(path, check_name=None):

return mod, spec


def load_from_search_paths(module_name):
"""
loads and executes python module with module_name from search paths
Expand Down
2 changes: 1 addition & 1 deletion kapitan/inputs/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import logging
import os
import shutil
from kapitan.utils import copy_tree

from kapitan.inputs.base import InputType
from kapitan.utils import copy_tree

logger = logging.getLogger(__name__)

Expand Down
6 changes: 5 additions & 1 deletion kapitan/inventory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class InventoryBackends(StrEnum):
"""
Enumeration of available inventory backends.
"""

RECLASS = "reclass"
RECLASS_RS = "reclass-rs"
OMEGACONF = "omegaconf"
Expand All @@ -23,6 +24,7 @@ def load_reclass_backend():
Enable the reclass inventory backend.
"""
from .inv_reclass import ReclassInventory

return ReclassInventory


Expand All @@ -31,6 +33,7 @@ def load_reclass_rs_backend():
Enable the reclass-rs inventory backend.
"""
from .inv_reclass_rs import ReclassRsInventory

return ReclassRsInventory


Expand All @@ -39,6 +42,7 @@ def load_omegaconf_backend():
Enable the omegaconf inventory backend.
"""
from .inv_omegaconf.inv_omegaconf import OmegaConfInventory

return OmegaConfInventory


Expand All @@ -55,4 +59,4 @@ def get_inventory_backend(backend_name: str) -> Type[Inventory]:
"""
Get the `Inventory` subclass associated with the given `backend_name`.
"""
return AVAILABLE_BACKENDS.get(backend_name, AVAILABLE_BACKENDS[InventoryBackends.DEFAULT])()
return AVAILABLE_BACKENDS.get(backend_name, AVAILABLE_BACKENDS[InventoryBackends.DEFAULT])()
Loading

0 comments on commit 0f2f7b6

Please sign in to comment.