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

Resolve template path from package at configuration load time #634

Open
adiroiban opened this issue Jul 31, 2024 · 0 comments
Open

Resolve template path from package at configuration load time #634

adiroiban opened this issue Jul 31, 2024 · 0 comments

Comments

@adiroiban
Copy link
Member

adiroiban commented Jul 31, 2024

We have the config.template as both a path or tuple(package_name, resource_name)

The loading is done 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)

And then the actual path is resovled here

if isinstance(config.template, tuple):
template = (
resources.files(config.template[0])
.joinpath(config.template[1])
.read_text(encoding="utf-8")
)


I think that is best to resolve the full path when the configuration is loades so that config.template is always a text path.


also see the converstation from #633 and see why the test pass when we don't add the special exception for a tuple.

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

1 participant