-
Notifications
You must be signed in to change notification settings - Fork 255
Relative template_dir path causes TemplateNotFound error in monorepo configuration #845
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
Comments
@deme3 Thanks for the bug report and the initial troubleshooting you have accomplished. I have been working an extensive rewrite of the changelog testing and this will definitely be one of the new tests to add along with a fix. |
@codejedi365 thanks for letting me know. :) Until we get the new release with the changelog rewrite, I can suggest the following patch for whoever is using this tool in a monorepo like me (note that I have no idea if this is good, I haven't looked much into the codebase, I just needed a quick fix for now): unchanged:
--- a/cli/commands/changelog.py
+++ b/cli/commands/changelog.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import logging
import os
from typing import TYPE_CHECKING
+from pathlib import Path
import click
@@ -76,7 +77,8 @@ def changelog(ctx: click.Context, release_tag: str | None = None) -> None:
f"{template_dir!r} relative to {repo.working_dir!r}"
)
else:
- recursive_render(template_dir, environment=env, _root_dir=repo.working_dir)
+ project_root = Path(runtime.global_cli_options.config_file).absolute().parent
+ recursive_render(template_dir, environment=env, _root_dir=project_root)
if release_tag:
if runtime.global_cli_options.noop:
@@ -116,4 +118,4 @@ def changelog(ctx: click.Context, release_tag: str | None = None) -> None:
)
except Exception as e:
log.exception(e)
- ctx.fail(str(e))
\ No newline at end of file
+ ctx.fail(str(e))
unchanged:
--- a/cli/config.py
+++ b/cli/config.py
@@ -395,9 +395,10 @@ class RuntimeContext:
)
# changelog_file
+ project_root = Path(global_cli_options.config_file).absolute().parent
changelog_file = Path(raw.changelog.changelog_file).resolve()
- template_dir = Path(repo.working_tree_dir or ".") / raw.changelog.template_dir
+ template_dir = Path(project_root or ".") / raw.changelog.template_dir
template_environment = environment(
template_dir=raw.changelog.template_dir,
@@ -434,4 +435,4 @@ class RuntimeContext:
# credential masker
self.apply_log_masking(self.masker)
- return self
\ No newline at end of file
+ return self
only in patch2:
unchanged:
--- a/cli/commands/version.py
+++ b/cli/commands/version.py
@@ -5,6 +5,7 @@ import os
import subprocess
from contextlib import nullcontext
from datetime import datetime
+from pathlib import Path
from typing import TYPE_CHECKING, ContextManager, Iterable
import click
@@ -402,6 +403,7 @@ def version( # noqa: C901
hvcs_client=hvcs_client, release_history=rh
)
changelog_context.bind_to_environment(env)
+ project_root = Path(runtime.global_cli_options.config_file).absolute().parent
updated_paths: list[str] = []
if update_changelog:
@@ -409,13 +411,13 @@ def version( # noqa: C901
if opts.noop:
noop_report(
f"would have recursively rendered the template directory "
- f"{template_dir!r} relative to {repo.working_dir!r}. "
+ f"{template_dir!r} relative to {project_root!r}. "
"Paths which would be modified by this operation cannot be "
"determined in no-op mode."
)
else:
updated_paths = recursive_render(
- template_dir, environment=env, _root_dir=repo.working_dir
+ template_dir, environment=env, _root_dir=project_root
)
else:
@@ -425,13 +427,13 @@ def version( # noqa: C901
if opts.noop:
noop_report(
"would have written your changelog to "
- + str(changelog_file.relative_to(repo.working_dir))
+ + str(changelog_file.relative_to(project_root))
)
else:
changelog_text = render_default_changelog_file(env)
changelog_file.write_text(changelog_text, encoding="utf-8")
- updated_paths = [str(changelog_file.relative_to(repo.working_dir))]
+ updated_paths = [str(changelog_file.relative_to(project_root))]
if commit_changes and opts.noop:
noop_report( which instead of using the repository root directory as reference, uses the folder where the config is located. |
@deme3 I hope to have this in next week. My PR has been pending since the weekend. I was a bit concerned that this could break other changelog designs but we didn't have any testing in place to validate either scenario |
It has been 60 days since the last update on this confirmed issue. @python-semantic-release/team can you provide an update on the status of this issue? |
Need to circle back around to this issue. It slipped my mind, unfortunately the patch above will not work anymore given the refactor I did in |
@codejedi365 https://github.com/langchain-ai/langchain/tree/master/libs is a pretty good open source python monorepo |
@JonZeolla, thank you! |
It has been 60 days since the last update on this confirmed issue. @python-semantic-release/team can you provide an update on the status of this issue? |
Still in backlog |
It has been 60 days since the last update on this confirmed issue. @python-semantic-release/team can you provide an update on the status of this issue? |
Still in backlog |
It has been 60 days since the last update on this confirmed issue. @python-semantic-release/team can you provide an update on the status of this issue? |
Still in backlog |
The problem
TemplateNotFound error thrown by Jinja2 when generating changelog in a subfolder. The directory structure is as follows:
To be clear, the templates are discovered by
semantic-release
, but when they're passed to Jinja, a relative path is used, and Jinja is not able to find them.Expected behavior
I expect a generated
CHANGELOG.md
in the same level aspyproject.toml
by using the templates provided in the configuration.Environment
pip freeze
Using
build==1.0.3
andsetuptools=56.0.0
.Configuration
Logs
GitHub Attachment to Logs
Additional context
There's something wrong here:
python-semantic-release/semantic_release/changelog/template.py
Lines 77 to 123 in 82bfcd3
specifically, line 109
python-semantic-release/semantic_release/changelog/template.py
Lines 107 to 110 in 82bfcd3
The text was updated successfully, but these errors were encountered: