{"action":"created","comment":{"url":"https://api.github.com/repos/rpm-software-management/mock/pulls/comments/168150329","pull_request_review_id":96468720,"id":168150329,"diff_hunk":"@@ -1175,35 +1175,71 @@ def check_config(config_opts):\n                                     \"- option config_opts['root'] must be present in your config.\")\n \n \n-@traceLog()\n-def include(config_file, config_opts, is_statement=False):\n-    if os.path.exists(config_file):\n-        if is_statement and config_file in config_opts['config_paths']:\n-            getLog().warning(\"Multiple inclusion of %s, skipping\" % config_file)\n-            return\n-\n-        config_opts['config_paths'].append(config_file)\n-\n-        with open(config_file) as f:\n-            content = f.read()\n-            content = re.sub(r'include\\((.*)\\)', r'include(\\g<1>, config_opts, True)', content)\n-            code = compile(content, config_file, 'exec')\n-        # pylint: disable=exec-used\n+def _check_unrendered_config_opts(config_opts, content):\n+    env = jinja2.Environment(undefined=jinja2.StrictUndefined, loader=jinja2.FileSystemLoader('/'))\n+    template = env.from_string(content)\n+\n+    try:\n+        template.render(config=config_opts)\n+    except jinja2.exceptions.UndefinedError as ex:\n+        m_ar = ex.message.split('attribute')\n+        if len(m_ar) == 2:\n+            new_msg = \"Missing config option %s\" % m_ar[-1].strip()\n+        else:\n+            new_msg = ex.message\n+        raise exception.ConfigError(new_msg)\n+\n+\n+def _render_config_template(content, config_opts):\n+\n+    def _non_empty_finalizer(v):\n+        return None if isinstance(v, jinja2.Undefined) else v\n+\n+    env = jinja2.Environment(finalize=_non_empty_finalizer, loader=jinja2.FileSystemLoader('/'))\n+    template = env.from_string(content)\n+    part_old = None\n+    while True:\n+        part = template.render(config=config_opts)\n+        code = compile(part, '<string>', 'exec')\n         exec(code)\n-    else:\n-        raise exception.ConfigError(\"Could not find included config file: %s\" % config_file)\n+        if part_old == part:\n+            break","path":"mock/py/mockbuild/util.py","position":57,"original_position":57,"commit_id":"cc0feecaf0903f4d7833e5699cdc618a3ca2ed0b","original_commit_id":"cc0feecaf0903f4d7833e5699cdc618a3ca2ed0b","user":{"login":"plageat","id":2870966,"avatar_url":"https://avatars1.githubusercontent.com/u/2870966?v=4","gravatar_id":"","url":"https://api.github.com/users/plageat","html_url":"https://github.com/plageat","followers_url":"https://api.github.com/users/plageat/followers","following_url":"https://api.github.com/users/plageat/following{/other_user}","gists_url":"https://api.github.com/users/plageat/gists{/gist_id}","starred_url":"https://api.github.com/users/plageat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plageat/subscriptions","organizations_url":"https://api.github.com/users/plageat/orgs","repos_url":"https://api.github.com/users/plageat/repos","events_url":"https://api.github.com/users/plageat/events{/privacy}","received_events_url":"https://api.github.com/users/plageat/received_events","type":"User","site_admin":false},"body":"This 'while True' loop is for the nested level references:\r\n\r\n`config_opts['var1'] = 'value1'`\r\n`config_opts['var2'] = {{ config_opts.var1  }}`\r\n`config_opts['var3'] = {{ config_opts.var2  }}`\r\n\r\nThe loop will try to expand everything until nothing else is not expanded more\r\n\r\nFor code above 3 render loops:\r\n- one for {{ config_opts.var1  }}\r\n- second for {{ config_opts.var2  }}`\r\n- third to get same rendering result and to stop\r\n\r\nSo, if you think there will be 1000 nested level references , consider to add such an option. But I really doubt of it","created_at":"2018-02-14T11:45:58Z","updated_at":"2018-02-14T11:45:58Z","html_url":"https://github.com/rpm-software-management/mock/pull/161#discussion_r168150329","pull_request_url":"https://api.github.com/repos/rpm-software-management/mock/pulls/161","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rpm-software-management/mock/pulls/comments/168150329"},"html":{"href":"https://github.com/rpm-software-management/mock/pull/161#discussion_r168150329"},"pull_request":{"href":"https://api.github.com/repos/rpm-software-management/mock/pulls/161"}},"in_reply_to_id":168146194},"pull_request":{"url":"https://api.github.com/repos/rpm-software-management/mock/pulls/161","id":168567775,"html_url":"https://github.com/rpm-software-management/mock/pull/161","diff_url":"https://github.com/rpm-software-management/mock/pull/161.diff","patch_url":"https://github.com/rpm-software-management/mock/pull/161.patch","issue_url":"https://api.github.com/repos/rpm-software-management/mock/issues/161","number":161,"state":"open","locked":false,"title":"Unified configuration processing system","user":{"login":"plageat","id":2870966,"avatar_url":"https://avatars1.githubusercontent.com/u/2870966?v=4","gravatar_id":"","url":"https://api.github.com/users/plageat","html_url":"https://github.com/plageat","followers_url":"https://api.github.com/users/plageat/followers","following_url":"https://api.github.com/users/plageat/following{/other_user}","gists_url":"https://api.github.com/users/plageat/gists{/gist_id}","starred_url":"https://api.github.com/users/plageat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plageat/subscriptions","organizations_url":"https://api.github.com/users/plageat/orgs","repos_url":"https://api.github.com/users/plageat/repos","events_url":"https://api.github.com/users/plageat/events{/privacy}","received_events_url":"https://api.github.com/users/plageat/received_events","type":"User","site_admin":false},"body":"So, this is an attempt to re-design mock's configuration system (BZ#1208344, issue #6) with templates args based on jinja2.\r\nI hope this at least will stimulate some discussion of the topic as well as this patch does not introduce a lot of new bugs :)\r\n\r\nShort description of new algorithm:\r\n1. gather all config paths\r\n2. merge all configs in one\r\n3. expand jinja2 templates\r\n4. provide final config or configuration error\r\n5. do config post setup\r\n\r\nNotes:\r\n- config_opt definitions and expansions are located in one place (hope so)\r\n- almost all string formatting transformed to jinja2 show template, for example:\r\n    \"%(cache_topdir)s/%(root)s/ccache/u%(chrootuid)s/\"\r\n         => \r\n    \"{{ config.cache_topdir }}/{{ config.root }}/ccache/u{{ config.chrootuid }}/\"\r\n- 'include()' became '{% include '/absolute/path/to/config.cfg' %}'\r\n- multiple inclusion detection is not detected anymore, if there is recursive include, max depth error will be shown\r\n- template string substitution is missing in cmd options at the moment (that one: --resultdir=./my/\"%(dist)s\"/\"%(target_arch)s\")\r\n- ofc, not all of jinja2 features can be used (like {% import ... % as ... %}, etc.)","created_at":"2018-02-12T12:35:23Z","updated_at":"2018-02-14T11:45:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b331a023a670421f93ca3c55b19e5996ae3918b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rpm-software-management/mock/pulls/161/commits","review_comments_url":"https://api.github.com/repos/rpm-software-management/mock/pulls/161/comments","review_comment_url":"https://api.github.com/repos/rpm-software-management/mock/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rpm-software-management/mock/issues/161/comments","statuses_url":"https://api.github.com/repos/rpm-software-management/mock/statuses/cc0feecaf0903f4d7833e5699cdc618a3ca2ed0b","head":{"label":"plageat:param_config","ref":"param_config","sha":"cc0feecaf0903f4d7833e5699cdc618a3ca2ed0b","user":{"login":"plageat","id":2870966,"avatar_url":"https://avatars1.githubusercontent.com/u/2870966?v=4","gravatar_id":"","url":"https://api.github.com/users/plageat","html_url":"https://github.com/plageat","followers_url":"https://api.github.com/users/plageat/followers","following_url":"https://api.github.com/users/plageat/following{/other_user}","gists_url":"https://api.github.com/users/plageat/gists{/gist_id}","starred_url":"https://api.github.com/users/plageat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plageat/subscriptions","organizations_url":"https://api.github.com/users/plageat/orgs","repos_url":"https://api.github.com/users/plageat/repos","events_url":"https://api.github.com/users/plageat/events{/privacy}","received_events_url":"https://api.github.com/users/plageat/received_events","type":"User","site_admin":false},"repo":{"id":115633835,"name":"mock","full_name":"plageat/mock","owner":{"login":"plageat","id":2870966,"avatar_url":"https://avatars1.githubusercontent.com/u/2870966?v=4","gravatar_id":"","url":"https://api.github.com/users/plageat","html_url":"https://github.com/plageat","followers_url":"https://api.github.com/users/plageat/followers","following_url":"https://api.github.com/users/plageat/following{/other_user}","gists_url":"https://api.github.com/users/plageat/gists{/gist_id}","starred_url":"https://api.github.com/users/plageat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plageat/subscriptions","organizations_url":"https://api.github.com/users/plageat/orgs","repos_url":"https://api.github.com/users/plageat/repos","events_url":"https://api.github.com/users/plageat/events{/privacy}","received_events_url":"https://api.github.com/users/plageat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/plageat/mock","description":"Mock is a tool for reproducible build of RPM packages.","fork":true,"url":"https://api.github.com/repos/plageat/mock","forks_url":"https://api.github.com/repos/plageat/mock/forks","keys_url":"https://api.github.com/repos/plageat/mock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/plageat/mock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/plageat/mock/teams","hooks_url":"https://api.github.com/repos/plageat/mock/hooks","issue_events_url":"https://api.github.com/repos/plageat/mock/issues/events{/number}","events_url":"https://api.github.com/repos/plageat/mock/events","assignees_url":"https://api.github.com/repos/plageat/mock/assignees{/user}","branches_url":"https://api.github.com/repos/plageat/mock/branches{/branch}","tags_url":"https://api.github.com/repos/plageat/mock/tags","blobs_url":"https://api.github.com/repos/plageat/mock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/plageat/mock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/plageat/mock/git/refs{/sha}","trees_url":"https://api.github.com/repos/plageat/mock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/plageat/mock/statuses/{sha}","languages_url":"https://api.github.com/repos/plageat/mock/languages","stargazers_url":"https://api.github.com/repos/plageat/mock/stargazers","contributors_url":"https://api.github.com/repos/plageat/mock/contributors","subscribers_url":"https://api.github.com/repos/plageat/mock/subscribers","subscription_url":"https://api.github.com/repos/plageat/mock/subscription","commits_url":"https://api.github.com/repos/plageat/mock/commits{/sha}","git_commits_url":"https://api.github.com/repos/plageat/mock/git/commits{/sha}","comments_url":"https://api.github.com/repos/plageat/mock/comments{/number}","issue_comment_url":"https://api.github.com/repos/plageat/mock/issues/comments{/number}","contents_url":"https://api.github.com/repos/plageat/mock/contents/{+path}","compare_url":"https://api.github.com/repos/plageat/mock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/plageat/mock/merges","archive_url":"https://api.github.com/repos/plageat/mock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/plageat/mock/downloads","issues_url":"https://api.github.com/repos/plageat/mock/issues{/number}","pulls_url":"https://api.github.com/repos/plageat/mock/pulls{/number}","milestones_url":"https://api.github.com/repos/plageat/mock/milestones{/number}","notifications_url":"https://api.github.com/repos/plageat/mock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/plageat/mock/labels{/name}","releases_url":"https://api.github.com/repos/plageat/mock/releases{/id}","deployments_url":"https://api.github.com/repos/plageat/mock/deployments","created_at":"2017-12-28T15:03:28Z","updated_at":"2017-12-28T15:03:30Z","pushed_at":"2018-02-14T10:51:05Z","git_url":"git://github.com/plageat/mock.git","ssh_url":"git@github.com:plageat/mock.git","clone_url":"https://github.com/plageat/mock.git","svn_url":"https://github.com/plageat/mock","homepage":"","size":2717,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"rpm-software-management:devel","ref":"devel","sha":"bfb431a5e4d8e385e8a4d624611a3b26175e5948","user":{"login":"rpm-software-management","id":8504469,"avatar_url":"https://avatars3.githubusercontent.com/u/8504469?v=4","gravatar_id":"","url":"https://api.github.com/users/rpm-software-management","html_url":"https://github.com/rpm-software-management","followers_url":"https://api.github.com/users/rpm-software-management/followers","following_url":"https://api.github.com/users/rpm-software-management/following{/other_user}","gists_url":"https://api.github.com/users/rpm-software-management/gists{/gist_id}","starred_url":"https://api.github.com/users/rpm-software-management/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpm-software-management/subscriptions","organizations_url":"https://api.github.com/users/rpm-software-management/orgs","repos_url":"https://api.github.com/users/rpm-software-management/repos","events_url":"https://api.github.com/users/rpm-software-management/events{/privacy}","received_events_url":"https://api.github.com/users/rpm-software-management/received_events","type":"Organization","site_admin":false},"repo":{"id":65797337,"name":"mock","full_name":"rpm-software-management/mock","owner":{"login":"rpm-software-management","id":8504469,"avatar_url":"https://avatars3.githubusercontent.com/u/8504469?v=4","gravatar_id":"","url":"https://api.github.com/users/rpm-software-management","html_url":"https://github.com/rpm-software-management","followers_url":"https://api.github.com/users/rpm-software-management/followers","following_url":"https://api.github.com/users/rpm-software-management/following{/other_user}","gists_url":"https://api.github.com/users/rpm-software-management/gists{/gist_id}","starred_url":"https://api.github.com/users/rpm-software-management/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpm-software-management/subscriptions","organizations_url":"https://api.github.com/users/rpm-software-management/orgs","repos_url":"https://api.github.com/users/rpm-software-management/repos","events_url":"https://api.github.com/users/rpm-software-management/events{/privacy}","received_events_url":"https://api.github.com/users/rpm-software-management/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rpm-software-management/mock","description":"Mock is a tool for a reproducible build of RPM packages.","fork":false,"url":"https://api.github.com/repos/rpm-software-management/mock","forks_url":"https://api.github.com/repos/rpm-software-management/mock/forks","keys_url":"https://api.github.com/repos/rpm-software-management/mock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rpm-software-management/mock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rpm-software-management/mock/teams","hooks_url":"https://api.github.com/repos/rpm-software-management/mock/hooks","issue_events_url":"https://api.github.com/repos/rpm-software-management/mock/issues/events{/number}","events_url":"https://api.github.com/repos/rpm-software-management/mock/events","assignees_url":"https://api.github.com/repos/rpm-software-management/mock/assignees{/user}","branches_url":"https://api.github.com/repos/rpm-software-management/mock/branches{/branch}","tags_url":"https://api.github.com/repos/rpm-software-management/mock/tags","blobs_url":"https://api.github.com/repos/rpm-software-management/mock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rpm-software-management/mock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rpm-software-management/mock/git/refs{/sha}","trees_url":"https://api.github.com/repos/rpm-software-management/mock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rpm-software-management/mock/statuses/{sha}","languages_url":"https://api.github.com/repos/rpm-software-management/mock/languages","stargazers_url":"https://api.github.com/repos/rpm-software-management/mock/stargazers","contributors_url":"https://api.github.com/repos/rpm-software-management/mock/contributors","subscribers_url":"https://api.github.com/repos/rpm-software-management/mock/subscribers","subscription_url":"https://api.github.com/repos/rpm-software-management/mock/subscription","commits_url":"https://api.github.com/repos/rpm-software-management/mock/commits{/sha}","git_commits_url":"https://api.github.com/repos/rpm-software-management/mock/git/commits{/sha}","comments_url":"https://api.github.com/repos/rpm-software-management/mock/comments{/number}","issue_comment_url":"https://api.github.com/repos/rpm-software-management/mock/issues/comments{/number}","contents_url":"https://api.github.com/repos/rpm-software-management/mock/contents/{+path}","compare_url":"https://api.github.com/repos/rpm-software-management/mock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rpm-software-management/mock/merges","archive_url":"https://api.github.com/repos/rpm-software-management/mock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rpm-software-management/mock/downloads","issues_url":"https://api.github.com/repos/rpm-software-management/mock/issues{/number}","pulls_url":"https://api.github.com/repos/rpm-software-management/mock/pulls{/number}","milestones_url":"https://api.github.com/repos/rpm-software-management/mock/milestones{/number}","notifications_url":"https://api.github.com/repos/rpm-software-management/mock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rpm-software-management/mock/labels{/name}","releases_url":"https://api.github.com/repos/rpm-software-management/mock/releases{/id}","deployments_url":"https://api.github.com/repos/rpm-software-management/mock/deployments","created_at":"2016-08-16T07:24:01Z","updated_at":"2018-02-13T11:09:12Z","pushed_at":"2018-02-14T10:51:07Z","git_url":"git://github.com/rpm-software-management/mock.git","ssh_url":"git@github.com:rpm-software-management/mock.git","clone_url":"https://github.com/rpm-software-management/mock.git","svn_url":"https://github.com/rpm-software-management/mock","homepage":"","size":2723,"stargazers_count":75,"watchers_count":75,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":62,"mirror_url":null,"archived":false,"open_issues_count":26,"license":{"key":"gpl-2.0","name":"GNU General Public License v2.0","spdx_id":"GPL-2.0","url":"https://api.github.com/licenses/gpl-2.0"},"forks":62,"open_issues":26,"watchers":75,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/rpm-software-management/mock/pulls/161"},"html":{"href":"https://github.com/rpm-software-management/mock/pull/161"},"issue":{"href":"https://api.github.com/repos/rpm-software-management/mock/issues/161"},"comments":{"href":"https://api.github.com/repos/rpm-software-management/mock/issues/161/comments"},"review_comments":{"href":"https://api.github.com/repos/rpm-software-management/mock/pulls/161/comments"},"review_comment":{"href":"https://api.github.com/repos/rpm-software-management/mock/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rpm-software-management/mock/pulls/161/commits"},"statuses":{"href":"https://api.github.com/repos/rpm-software-management/mock/statuses/cc0feecaf0903f4d7833e5699cdc618a3ca2ed0b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"plageat"}}