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

24.7.x loads template relative to --dir #641

Open
iliakur opened this issue Aug 1, 2024 · 2 comments
Open

24.7.x loads template relative to --dir #641

iliakur opened this issue Aug 1, 2024 · 2 comments

Comments

@iliakur
Copy link
Contributor

iliakur commented Aug 1, 2024

We have a repo where one towncrier config and template file are used to generate changelogs for multiple subdirs (the monorepo scenario).

Here's how we configure it all. Here's how we invoke towncrier, note that we pass a --dir argument. It worked fine in v23.11.

24.7 broke this because it started searching for the template file relative to --dir.

I'm going to pin our version of towncrier for now, but would love some guidance how we can support both usecases.

@adiroiban
Copy link
Member

Thanks for the report.

It worked fine in v23.11.

I am sorry to hear about this regression.

It looks like the current automated tests are not good enough.


I am not using mono-repos.
So I don't have much experience with this workflow.

I guess the fix is to search for template path relative to the same directory where the configuration file was found.

But I am not sure what is going in there.
I can see that the template is loaded in _builder.render_fragments as

jinja_template = Template(template, trim_blocks=True)

and then we have

rendered = render_fragments(
# The 0th underline is used for the top line
template,
config.issue_format,
fragments,
config.types,
config.underlines[1:],
config.wrap,
{"name": project_name, "version": project_version, "date": project_date},
top_underline=config.underlines[0],
all_bullets=config.all_bullets,
render_title=render_title,
)

with template value loaded here

# Process 'template'.
markdown_file = Path(config.get("filename", "")).suffix == ".md"
template = config.get("template", "towncrier:default")
if re_resource_template.match(template):
package, resource = template.split(":", 1)
if not Path(resource).suffix:
resource += ".md" if markdown_file else ".rst"
if not _pkg_file_exists(package, resource):
if _pkg_file_exists(package + ".templates", resource):
package += ".templates"
else:
raise ConfigError(
f"'{package}' does not have a template named '{resource}'.",
failing_option="template",
)
template = (package, resource)
else:
template = os.path.join(base_path, template)
if not os.path.isfile(template):
raise ConfigError(
f"The template file '{template}' does not exist.",
failing_option="template",
)
parsed_data["template"] = template

@adiroiban
Copy link
Member

I will not have time in the near future to look at fixing this bug.

But if anyone has a fix, I am happy to review and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants