Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datatime issue when inventory key contains a date #1266

Merged
merged 2 commits into from
Nov 12, 2024
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
36 changes: 2 additions & 34 deletions kapitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import tarfile
import traceback
from collections import Counter, defaultdict
from functools import lru_cache, wraps
from datetime import time
from functools import lru_cache
from hashlib import sha256
from zipfile import ZipFile

Expand Down Expand Up @@ -57,38 +58,6 @@ def fatal_error(message):
sys.exit(1)


def hashable_lru_cache(func):
"""Usable instead of lru_cache for functions using unhashable objects"""

cache = lru_cache(maxsize=256)

def deserialise(value):
try:
return json.loads(value)
except Exception:
logger.debug("hashable_lru_cache: %s not serialiseable, using generic lru_cache instead", value)
return value

def func_with_serialized_params(*args, **kwargs):
_args = tuple([deserialise(arg) for arg in args])
_kwargs = {k: deserialise(v) for k, v in kwargs.items()}
return func(*_args, **_kwargs)

cached_function = cache(func_with_serialized_params)

@wraps(func)
def lru_decorator(*args, **kwargs):
_args = tuple([json.dumps(arg, sort_keys=True) if type(arg) in (list, dict) else arg for arg in args])
_kwargs = {
k: json.dumps(v, sort_keys=True) if type(v) in (list, dict) else v for k, v in kwargs.items()
}
return cached_function(*_args, **_kwargs)

lru_decorator.cache_info = cached_function.cache_info
lru_decorator.cache_clear = cached_function.cache_clear
return lru_decorator


class termcolor:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
Expand Down Expand Up @@ -270,7 +239,6 @@ def flatten_dict(d, parent_key="", sep="."):
return dict(items)


@hashable_lru_cache
def deep_get(dictionary, keys, previousKey=None):
"""Search recursively for 'keys' in 'dictionary' and return value, otherwise return None"""
value = None
Expand Down
50 changes: 25 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading