-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(config/toml): support jinja templates in toml files #33123
Conversation
Following the specification in https://jinja.palletsprojects.com/en/stable/templates/#synopsis, there are three types of delimiters: 1. Statements 2. Expressions 3. Comments
fa5430b
to
0099a48
Compare
Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
@viceice I've added tests for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inline the fixtures as part of the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're currently not merging features because all maintainer are in Christmas holiday and we don't want to break anything now.
Thanks for letting me know. Have a wonderful holiday! |
Is this still being considered? Seems it got lost over New Year's |
@viceice could you please have another look at this and let me know if I can help in any way. |
@@ -258,7 +258,7 @@ export const MultidocYaml = z.string().transform((str, ctx): JsonArray => { | |||
|
|||
export const Toml = z.string().transform((str, ctx) => { | |||
try { | |||
return parseToml(str); | |||
return parseToml(str, { removeTemplates: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like to do this by default. @zharinov how to best handle such options 🤔
Maybe we should export a toml
function which allows to pass parder options? would this help for yaml on gitlab too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it isn't necessary to couple with TOML parsing.
Let's use stripTemplates(parseToml(...))
or StripTemplates.pipe(Toml).pipe(z.object(...))
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these transforms could lead to errors that are hard to detect.
Let's keep it localized to the Python ecosystem:
How can we proceed here? Is this waiting for response from @zharinov ? |
|
@zharinov I tried latest renovate with our pyproject.toml.jinja file, but unfortunately it still fails {
"err":
{
"column": 1,
"index": 709,
"lineNumber": 39,
"message": "Unexpected token",
"stack": "SyntaxError: Unexpected token
at Context.reportParseError (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/toml-eslint-parser/lib/toml-parser/context.js:114:15)
at TOMLParser.TABLE (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/toml-eslint-parser/lib/toml-parser/index.js:107:20)
at TOMLParser.parse (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/toml-eslint-parser/lib/toml-parser/index.js:77:51)
at parseForESLint (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/toml-eslint-parser/lib/parser.js:11:24)
at parseTOML (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/toml-eslint-parser/lib/index.js:46:40)
at parse (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/util/toml.ts:4:24)
at parsePyProject (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/modules/manager/pep621/utils.ts:140:30)
at Object.extractPackageFile (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/modules/manager/pep621/extract.ts:25:29)
at extractPackageFile (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/modules/manager/index.ts:75:9)
at getManagerPackageFiles (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/repository/extract/manager-files.ts:58:43)
at /opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/repository/extract/index.ts:57:28
at async Promise.all (index 3)
at extractAllDependencies (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/repository/extract/index.ts:54:26)
at extract (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/repository/process/extract-update.ts:160:28)
at extractDependencies (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/repository/process/index.ts:158:26)
at Object.renovateRepository (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/repository/index.ts:71:9)
at attributes.repository (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/global/index.ts:206:11)
at start (/opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/workers/global/index.ts:191:7)
at /opt/containerbase/tools/renovate/39.180.2/22.11.0/node_modules/renovate/lib/renovate.ts:19:22"
},
"hostname": "runner-cqva6w8oe-project-1694-concurrent-0",
"level": 20,
"logContext": "XBuHFJk1JOOxotnc2vNXs",
"msg": "Failed to parse and validate pyproject file",
"name": "renovate",
"packageFile": "templates/pyproject.toml.jinja",
"pid": 17,
"repository": "pes/common/pes-python-module-template",
"time": "2025-02-25T12:58:37.776Z",
"v": 0
} this is the file [project]
name = "{{ distribution_pkg_name }}"
dynamic = ["version"]
description = "{{ module_short_description }}"
readme = "README.md"
keywords = [
"python",
"module"
]
classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
maintainers = [
{name = "{{ author_first_name }} {{ author_surname }}", email = "{{ author_mail }}"},
]
authors = [
{name = "{{ author_first_name }} {{ author_surname }}", email = "{{ author_mail }}"},
]
license = {file = "LICENSE"}
dependencies = [
"pycowsay>=0.0.0.1",
{%- if is_application %}
"click>=8.1.7",
{%- endif %}
]
requires-python = ">=3.10"
[project.urls]
Repository = "{{ gitlab_url }}"
{%- if is_application %}
[project.scripts]
{{ distribution_pkg_name }} = "{{ import_pkg_name }}.__main__:cli"
{%- endif %}
[build-system]
requires = ["pdm-backend==2.3.3", "pdm-build-locked==0.3.2"]
build-backend = "pdm.backend"
#########
# TOOLS #
#########
[tool.pdm.version]
source = "scm"
[tool.pdm]
plugins = [
"pdm-build-locked"
]
[tool.pdm.build]
package-dir = "src"
excludes = ["tests/_temp"]
{%- if is_application %}
locked = true
{%- endif %} |
Fixed with 39.185.6 |
Changes
removeTemplate
option to theparseToml
functionremoveTemplate: true
config topoetry
andpep621
pyproject.toml
parsers.Context
This addresses the feature request raised in #33105 by applying a similar method in the
yaml
parser in #26682.Documentation (please check one with an [x])
How I've tested my work (please select one)
I have verified these changes via: