- Notifications
You must be signed in to change notification settings - Fork262
Open
Milestone
Description
The problem
TemplateNotFound error thrown by Jinja2 when generating changelog in a subfolder. The directory structure is as follows:
- main_program+-- templates +-- main_program +-- CHANGELOG.md.j2+-- CHANGELOG.md+-- pyproject.toml+-- ...- lib1- lib2To be clear, the templates are discovered bysemantic-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 generatedCHANGELOG.md in the same level aspyproject.toml by using the templates provided in the configuration.
Environment
- Python Version: v3.8.18
- Pip Version: v23.0.1
- Semantic Release Version: v9.1.0
pip freeze
annotated-types==0.6.0antlr4-python3-runtime==4.13.1antlr4-tools==0.2argcomplete==3.2.2argparse-addons==0.12.0asn1tools==0.166.0bcrypt==4.0.1Beaker==1.12.1beautifulsoup4==4.12.2bitstruct==8.17.0build==1.0.3cantools==39.0.0capstone==5.0.0rc2certifi==2024.2.2cffi==1.15.1charset-normalizer==3.3.2click==8.1.7colorama==0.4.6colored-traceback==0.3.0crccheck==1.3.0cryptography==40.0.2cssselect==1.2.0decli==0.6.1decorator==5.1.1diskcache==5.6.1docutils==0.20.1dotty-dict==1.3.1exceptiongroup==1.1.3filebytes==0.10.2FormEncode==2.1.0future==0.18.3gitdb==4.0.11GitPython==3.1.42idna==3.6importlib-metadata==7.0.1importlib-resources==6.1.1iniconfig==2.0.0install-jdk==1.1.0intervaltree==3.1.0jaraco.classes==3.3.1jeepney==0.8.0Jinja2==3.1.3keyring==24.3.0lark==1.1.8-e git+<redacted>lxml==4.9.3Mako==1.2.4markdown-it-py==3.0.0MarkupSafe==2.1.2mdurl==0.1.2mikai==4.0.1more-itertools==10.2.0msgpack==1.0.5-e git+<redacted>nh3==0.2.15nose==1.3.7numpy==1.24.4packaging==23.1paramiko==3.1.0Paste==3.7.1PasteDeploy==3.1.0PasteScript==3.3.0pkginfo==1.9.6pluggy==1.3.0plumbum==1.8.1prompt-toolkit==3.0.36psutil==5.9.5pwntools==4.9.0pycparser==2.21pydantic==2.6.1pydantic_core==2.16.2pyelftools==0.29Pygments==2.16.1Pylons==1.0.3PyNaCl==1.5.0pyparsing==3.1.0pyproject_hooks==1.0.0pyserial==3.5PySide6==6.6.1PySide6-Addons==6.6.1PySide6-Essentials==6.6.1PySocks==1.7.1pytest==7.4.2python-can==4.2.2python-dateutil==2.8.2python-gitlab==4.4.0python-semantic-release==9.1.0pytz==2023.3PyYAML==6.0.1questionary==2.0.1readme-renderer==42.0repoze.lru==0.7requests==2.31.0requests-toolbelt==1.0.0rfc3986==2.0.0rich==13.7.0ROPGadget==7.3ropper==1.13.8Routes==2.5.1rpyc==5.3.1SecretStorage==3.3.3shellingham==1.5.4shiboken6==6.6.1simplejson==3.19.2six==1.16.0smmap==5.0.1sortedcontainers==2.4.0soupsieve==2.5Tempita==0.5.2termcolor==2.4.0textparser==0.24.0tomli==2.0.1tomlkit==0.12.3twine==5.0.0typing_extensions==4.7.1tzdata==2023.3unicorn==2.0.1.post1urllib3==2.2.1waitress==2.1.2wcwidth==0.2.9WebError==0.13.1WebHelpers==1.3WebOb==1.8.7WebTest==3.0.0wrapt==1.15.0zipp==3.17.0Usingbuild==1.0.3 andsetuptools=56.0.0.
Configuration
[tool.semantic_release]assets = []commit_message ="chore: bumped version to {version}\n\nAutomatically generated by python-semantic-release"commit_parser ="angular"logging_use_named_masks =falsemajor_on_zero =truetag_format ="main_program-v{version}"version_variables = ["main_program/__init__.py:__version__"][tool.semantic_release.changelog]template_dir ="main_program/templates"changelog_file ="CHANGELOG.md"exclude_commit_patterns = []
Logs
Additional context
There's something wrong here:
python-semantic-release/semantic_release/changelog/template.py
Lines 77 to 123 in82bfcd3
| defrecursive_render( | |
| template_dir:Path, | |
| environment:Environment, | |
| _root_dir:str|os.PathLike[str]=".", | |
| )->list[str]: | |
| rendered_paths:list[str]= [] | |
| forroot,filein ( | |
| (Path(root),file) | |
| forroot,_,filesinos.walk(template_dir) | |
| forfileinfiles | |
| # we slice relpath.parts[1:] to allow the top-level | |
| # template folder to have a dot prefix. | |
| # e.g. to permit ".github/psr-templates" to contain the templates, | |
| # rather than enforcing a top-level, non-hidden directory | |
| ifnotany( | |
| elem.startswith(".") | |
| foreleminPath(root).relative_to(template_dir).parts[1:] | |
| ) | |
| andnotfile.startswith(".") | |
| ): | |
| output_path= (_root_dir/root.relative_to(template_dir)).resolve() | |
| log.info("Rendering templates from %s to %s",root,output_path) | |
| output_path.mkdir(parents=True,exist_ok=True) | |
| iffile.endswith(".j2"): | |
| # We know the file ends with .j2 by the filter in the for-loop | |
| output_filename=file[:-3] | |
| # Strip off the template directory from the front of the root path - | |
| # that's the output location relative to the repo root | |
| src_file_path=str((root/file).relative_to(template_dir)) | |
| output_file_path=str((output_path/output_filename).resolve()) | |
| log.debug("rendering %s to %s",src_file_path,output_file_path) | |
| stream=environment.get_template(src_file_path).stream() | |
| withopen(output_file_path,"wb+")asoutput_file: | |
| stream.dump(output_file,encoding="utf-8") | |
| rendered_paths.append(output_file_path) | |
| else: | |
| src_file=str((root/file).resolve()) | |
| target_file=str((output_path/file).resolve()) | |
| log.debug( | |
| "source file %s is not a template, copying to %s",src_file,target_file | |
| ) | |
| shutil.copyfile(src_file,target_file) | |
| rendered_paths.append(target_file) | |
| returnrendered_paths |
specifically, line 109
python-semantic-release/semantic_release/changelog/template.py
Lines 107 to 110 in82bfcd3
| log.debug("rendering %s to %s",src_file_path,output_file_path) | |
| stream=environment.get_template(src_file_path).stream() | |