diff options
author | Daniel Watkins <daniel.watkins@canonical.com> | 2019-07-29 14:19:14 -0400 |
---|---|---|
committer | Daniel Watkins <daniel.watkins@canonical.com> | 2019-07-29 14:41:52 -0400 |
commit | 63c02a8092dcc77163aa542cce8a6105f5759cbc (patch) | |
tree | f1b37573639d6c5f72994919df263a096440dc76 | |
parent | 1d48093fe91344af6e921f14dec42fc5d2718be4 (diff) | |
download | python-jenkins-job-builder-63c02a8092dcc77163aa542cce8a6105f5759cbc.tar.gz python-jenkins-job-builder-63c02a8092dcc77163aa542cce8a6105f5759cbc.tar.xz python-jenkins-job-builder-63c02a8092dcc77163aa542cce8a6105f5759cbc.zip |
Revert "Add support for rendering jinja template as yaml"
This reverts commit a9e12ed4a9f5866da0af5fdc68f60b09ca8efa4b.
Change-Id: I2bbb2cc167a4c2cd95ac6b376ebe83bcf7a263ad
-rw-r--r-- | jenkins_jobs/formatter.py | 24 | ||||
-rw-r--r-- | jenkins_jobs/local_yaml.py | 19 | ||||
-rw-r--r-- | jenkins_jobs/parser.py | 10 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/jinja-as-yaml-include01.xml | 31 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml | 7 | ||||
-rw-r--r-- | tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc | 3 |
6 files changed, 5 insertions, 89 deletions
diff --git a/jenkins_jobs/formatter.py b/jenkins_jobs/formatter.py index 5bd1b710..bd2576b9 100644 --- a/jenkins_jobs/formatter.py +++ b/jenkins_jobs/formatter.py @@ -26,7 +26,7 @@ from jenkins_jobs.local_yaml import CustomLoader logger = logging.getLogger(__name__) -def deep_format(obj, paramdict, allow_empty=False, template=True): +def deep_format(obj, paramdict, allow_empty=False): """Apply the paramdict via str.format() to all string objects found within the supplied obj. Lists and dicts are traversed recursively.""" # YAML serialisation was originally used to achieve this, but that places @@ -50,26 +50,13 @@ def deep_format(obj, paramdict, allow_empty=False, template=True): elif isinstance(obj, list): ret = type(obj)() for item in obj: - ret.append(deep_format(item, paramdict, - allow_empty=allow_empty, - template=template)) + ret.append(deep_format(item, paramdict, allow_empty)) elif isinstance(obj, dict): ret = type(obj)() for item in obj: try: - # deep_formatting dsl when not a job-template is not necessary - # as it will most likely result in keyerror due to trying - # to substitute values inside the dsl that do not exist. - if item not in ['dsl'] or template: - ret[CustomFormatter(allow_empty).format(item, - **paramdict)] = \ - deep_format(obj[item], paramdict, - allow_empty=allow_empty, - template=template) - else: - ret[CustomFormatter(allow_empty).format(item, - **paramdict)] = \ - obj[item] + ret[CustomFormatter(allow_empty).format(item, **paramdict)] = \ + deep_format(obj[item], paramdict, allow_empty) except KeyError as exc: missing_key = exc.args[0] desc = "%s parameter missing to format %s\nGiven:\n%s" % ( @@ -85,8 +72,7 @@ def deep_format(obj, paramdict, allow_empty=False, template=True): if isinstance(ret, CustomLoader): # If we have a CustomLoader here, we've lazily-loaded a template; # attempt to format it. - ret = deep_format(ret, paramdict, allow_empty=allow_empty, - template=template) + ret = deep_format(ret, paramdict, allow_empty=allow_empty) return ret diff --git a/jenkins_jobs/local_yaml.py b/jenkins_jobs/local_yaml.py index 75d1c5c6..213d8a7a 100644 --- a/jenkins_jobs/local_yaml.py +++ b/jenkins_jobs/local_yaml.py @@ -491,17 +491,6 @@ class YamlIncludeJinja2(YamlIncludeRaw): return Jinja2Loader(contents, loader.search_path) -class YamlIncludeJinja2AsYaml(YamlIncludeJinja2): - yaml_tag = u'!include-jinja2-as-yaml:' - - @classmethod - def _from_file(cls, loader, node): - contents = cls._open_file(loader, node) - if isinstance(contents, LazyLoader): - return contents - return Jinja2LoaderAsYaml(contents, loader.search_path) - - class DeprecatedTag(BaseYAMLObject): @classmethod @@ -548,14 +537,6 @@ class Jinja2Loader(CustomLoader): return self._template.render(kwargs) -class Jinja2LoaderAsYaml(Jinja2Loader): - """A loader for Jinja2-templated files that renders yaml.""" - - def format(self, **kwargs): - raw_yaml = super(Jinja2LoaderAsYaml, self).format(**kwargs) - return yaml.load(raw_yaml) - - class CustomLoaderCollection(object): """Helper class to format a collection of CustomLoader objects""" def __init__(self, sequence): diff --git a/jenkins_jobs/parser.py b/jenkins_jobs/parser.py index e8549c8f..667ce426 100644 --- a/jenkins_jobs/parser.py +++ b/jenkins_jobs/parser.py @@ -243,16 +243,6 @@ class YamlParser(object): if jobs_glob and not matches(job['name'], jobs_glob): logger.debug("Ignoring job {0}".format(job['name'])) continue - - # Attempt to format all parts of the job definition as they might - # be using custom loaders. - try: - job = deep_format(job, job, template=False) - except Exception: - logging.error( - "Failure formatting job '%s' with itself", job) - raise - logger.debug("Expanding job '{0}'".format(job['name'])) self._formatDescription(job) self.jobs.append(job) diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml b/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml deleted file mode 100644 index 732bb2c4..00000000 --- a/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<project> - <actions/> - <description><!-- Managed by Jenkins Job Builder --></description> - <keepDependencies>false</keepDependencies> - <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> - <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> - <concurrentBuild>false</concurrentBuild> - <canRoam>true</canRoam> - <properties> - <hudson.model.ParametersDefinitionProperty> - <parameterDefinitions> - <hudson.model.ChoiceParameterDefinition> - <name>TEST_CHOICE</name> - <description/> - <choices class="java.util.Arrays$ArrayList"> - <a class="string-array"> - <string>a</string> - <string>b</string> - <string>c</string> - </a> - </choices> - </hudson.model.ChoiceParameterDefinition> - </parameterDefinitions> - </hudson.model.ParametersDefinitionProperty> - </properties> - <scm class="hudson.scm.NullSCM"/> - <builders/> - <publishers/> - <buildWrappers/> -</project> diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml deleted file mode 100644 index 2ea430f0..00000000 --- a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml +++ /dev/null @@ -1,7 +0,0 @@ -- job: - name: test-job-as-yaml - parameters: - - choice: - name: TEST_CHOICE - choices: - !include-jinja2-as-yaml: jinja-as-yaml-include01.yaml.inc diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc deleted file mode 100644 index c1c3c8b3..00000000 --- a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc +++ /dev/null @@ -1,3 +0,0 @@ -{% for item in ['a', 'b', 'c'] %} -- {{ item }} -{% endfor -%} |