Skip to content

Commit

Permalink
optional jsonnet
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanderlinden committed Apr 2, 2021
1 parent c597afd commit 527538b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 2 additions & 4 deletions kapitan/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from kapitan.inputs.external import External
from kapitan.remoteinventory.fetch import fetch_inventories, list_sources
from kapitan.resources import inventory_reclass
from kapitan.utils import dictionary_hash, directory_hash, hashable_lru_cache
from kapitan.utils import dictionary_hash, directory_hash, hashable_lru_cache, JSONNET_AVAILABLE
from kapitan.validator.kubernetes_validator import KubernetesManifestValidator

from reclass.errors import NotFoundError, ReclassException
Expand All @@ -40,9 +40,7 @@


def check_jsonnet_import():
try:
import _gojsonnet
except ImportError:
if not JSONNET_AVAILABLE:
logger.info(
"Note: jsonnet is not yet supported on ARM/M1. You can still use kadet and jinja2 for templating"
)
Expand Down
16 changes: 10 additions & 6 deletions kapitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
from functools import lru_cache, wraps
from hashlib import sha256

import _gojsonnet as jsonnet
JSONNET_AVAILABLE = True
try:
import _gojsonnet as jsonnet
logging.debug('Using GO jsonnet over C jsonnet')
except ImportError:
try:
import _jsonnet as jsonnet
except ImportError:
JSONNET_AVAILABLE = False

import jinja2
import requests
import yaml
Expand All @@ -39,11 +48,6 @@

logger = logging.getLogger(__name__)

try:
import _jsonnet as jsonnet
except ImportError as e:
logger.debug("Could not import jsonnet: %s", e)


try:
from yaml import CSafeLoader as YamlLoader
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# kapitan dependencies
gojsonnet==0.17.0
jsonnet==0.16.0
pyyaml>=5.3.1
toml==0.10.1
Jinja2>=2.11.2
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ def install_deps():
"kapitan=kapitan.cli:main",
],
},
extras_require={
"gojsonnet": ["gojsonnet==0.17.0"]
}
)

0 comments on commit 527538b

Please sign in to comment.