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

ENH use jinja2 version if we can #1421

Merged
merged 2 commits into from
Jul 30, 2021
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
18 changes: 17 additions & 1 deletion conda_forge_tick/update_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ def get_url(self, meta_yaml) -> Optional[str]:
# TODO: pull this from the graph itself
content = meta_yaml["raw_meta_yaml"]

if any(ln.startswith("{% set version") for ln in content.splitlines()):
has_version_jinja2 = True
else:
has_version_jinja2 = False

# this while statement runs until a bad version is found
# then it uses the previous one
orig_urls = urls_from_meta(meta_yaml["meta_yaml"])
Expand All @@ -426,7 +431,18 @@ def get_url(self, meta_yaml) -> Optional[str]:
for next_ver in self.next_ver_func(current_ver):
logger.debug("trying version: %s", next_ver)

new_content = content.replace(orig_ver, next_ver)
if has_version_jinja2:
_new_lines = []
for ln in content.splitlines():
if ln.startswith("{% set version ") or ln.startswith(
"{% set version=",
):
_new_lines.append('{%% set version = "%s" %%}' % next_ver)
else:
_new_lines.append(ln)
new_content = "\n".join(_new_lines)
else:
new_content = content.replace(orig_ver, next_ver)
new_meta = parse_meta_yaml(new_content)
new_urls = urls_from_meta(new_meta)
if len(new_urls) == 0:
Expand Down
31 changes: 19 additions & 12 deletions conda_forge_tick/update_upstream_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,26 @@ def get_latest_version(
if name == "ca-policy-lcg":
return version_data

excs = []
for source in sources:
logger.debug("source: %s", source.__class__.__name__)
url = source.get_url(meta_yaml)
logger.debug("url: %s", url)
if url is None:
continue
ver = source.get_version(url)
logger.debug("ver: %s", ver)
if ver:
version_data["new_version"] = ver
break
else:
logger.debug(f"Upstream: Could not find version on {source.name}")
try:
logger.debug("source: %s", source.__class__.__name__)
url = source.get_url(meta_yaml)
logger.debug("url: %s", url)
if url is None:
continue
ver = source.get_version(url)
logger.debug("ver: %s", ver)
if ver:
version_data["new_version"] = ver
break
else:
logger.debug(f"Upstream: Could not find version on {source.name}")
except Exception as e:
excs.append(e)

if version_data["new_version"] is False and len(excs) > 0:
raise excs[0]

return version_data

Expand Down
14 changes: 10 additions & 4 deletions conda_forge_tick/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ def render_meta_yaml(text: str, for_pinning=False, **kwargs) -> str:
try:
return env.from_string(text).render(**cfg)
except Exception:
logger.debug("template: %s", text)
logger.debug("context:\n%s", pprint.pformat(cfg))
import traceback

logger.debug("render failure:\n%s", traceback.format_exc())
logger.debug("render template: %s", text)
logger.debug("render context:\n%s", pprint.pformat(cfg))
raise


Expand Down Expand Up @@ -235,8 +238,11 @@ def _run_parsing():
try:
return parse(content, cbc)
except Exception:
logger.debug("template: %s", text)
logger.debug("context:\n%s", pprint.pformat(cfg_as_dict))
import traceback

logger.debug("parse failure:\n%s", traceback.format_exc())
logger.debug("parse template: %s", text)
logger.debug("parse context:\n%s", pprint.pformat(cfg_as_dict))
raise


Expand Down