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

Use Jinja for templating #892

Merged
merged 15 commits into from
Nov 18, 2024
Merged

Use Jinja for templating #892

merged 15 commits into from
Nov 18, 2024

Conversation

jaimergp
Copy link
Contributor

@jaimergp jaimergp commented Nov 9, 2024

Description

It was about time.

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@jaimergp jaimergp changed the title Use Jinja for SH installers Use Jinja for templating Nov 9, 2024
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Nov 9, 2024
@jaimergp jaimergp marked this pull request as ready for review November 11, 2024 18:06
@jaimergp jaimergp requested a review from a team as a code owner November 11, 2024 18:06
@jaimergp
Copy link
Contributor Author

This is ready, but I'm inclined to leave it outside of this release in case it breaks something. We have plenty of changes anyway. Thoughts @marcoesters?

@marcoesters
Copy link
Contributor

This is ready, but I'm inclined to leave it outside of this release in case it breaks something. We have plenty of changes anyway. Thoughts @marcoesters?

Agreed

@jaimergp
Copy link
Contributor Author

Ok, this can go in now that 3.10 is out. @marcoesters

Copy link
Contributor

@marcoesters marcoesters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

I just have a couple of comments where I think we could use jinja a little more. If we use jinja's functions more, formatting and data are more cleanly separated and give developers a better idea about how the final product looks like without having to jump between py file and template.


data = data.replace("_SCRIPT_ENV_VARIABLES_=''", '\n'.join(
[f"export {key}='{value}'" for key, value in custom_variables.items()]))
variables["pkg_name_lower"] = pkg_name_lower
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done with jinja

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit more involved... we need access to the info dict in Jinja if we want to do that. See line 324.

constructor/osxpkg.py Outdated Show resolved Hide resolved
constructor/nsis/main.nsi.tmpl Show resolved Hide resolved
constructor/nsis/main.nsi.tmpl Outdated Show resolved Hide resolved
constructor/winexe.py Show resolved Hide resolved
constructor/winexe.py Outdated Show resolved Hide resolved

# From now on, the items added to variables will NOT be escaped

# These are mostly booleans we use with if-checks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is all one dictionary, this could be merged into the variables initializer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to do it here separately because the block above have been stringified and escaped, but we want true booleans for these ones.

constructor/header.sh Show resolved Hide resolved
constructor/shar.py Outdated Show resolved Hide resolved
constructor/osxpkg.py Show resolved Hide resolved
Copy link
Contributor

@marcoesters marcoesters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - can you file an issue to improve Jinja integration so that we can put this on our radar?

@jaimergp jaimergp mentioned this pull request Nov 18, 2024
3 tasks
@jaimergp jaimergp merged commit d4ac85f into conda:main Nov 18, 2024
20 checks passed
@jaimergp
Copy link
Contributor Author

There you go: #901, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants