fix: modifying start and end variable strings#1963
fix: modifying start and end variable strings#1963sacha-c wants to merge 3 commits intocookiecutter:mainfrom
Conversation
bb4f688 to
84e7447
Compare
84e7447 to
09a106c
Compare
|
(EDIT: This comment is now resolved with my latest change) After further testing, I found that the placeholders used to generate the This means that currently a file with: {
"name": "Easy Project",
"slug": "{%{ cookiecutter.name.lower().replace(' ', '-') }%}",
"repo_path": "elements/elements-react-native/{%{ cookiecutter.slug }%}",
"author_name": "John Doe",
"author_email": "john.doe@elements.nl",
"description": "The greatest project ever created.",
"use_renovate": [
"yes",
"no"
],
"_jinja2_env_vars": {
"variable_start_string": "{%{",
"variable_end_string": "}%}"
}
}will not work, because cookiecutter renders The issue is that prompt_for_config is being called without passing the I am setting this PR to draft and will try to make the improvements for this to work. EDIT: I have updated the PR with a solution. Looking forward to your feedback 🙂 |
Cookiecutter supports using _jinja2_env_vars to modify the jinja environment. However when modifying variable_start_string or variable_end_string it will not work because we are hard-coding the start and end strings for the main directory creation. This change leverages the _jinja2_env_vars to search for the main directory, to allow this customization of variable_start_string and variable_end_string. I also remove the `ensure_dir_is_templated` check because the same logic is used to find the dir, which is therefore redundant.
prompt_and_delete was a function in utils which also made use of read_user_yes_no which was in prompt. This means that prompt could not import utils because it would create a circular import. This change moves prompt_and_delete to prompt, so that prompt may make use of util functions
09a106c to
97f9126
Compare
|
@kurtmckee thanks for taking a look! I really appreciate it 👍 And thanks for linking that PR, I had totally missed it when investigating this issue. However reading through it it looks like it is missing an additional fix
I did like the use of I would suggest closing the other PR in favor of this one. |
|
Oh, nice! Thanks for responding back! ...and I just discovered that I only have repo permissions to close PRs but not to re-open them. I assumed that I could re-open PRs. 😞 @ericof and @jensens, please re-open this PR and review in light of the additional bug fix that this offers over #1837 (interpreting template openers/closers in variables in |
|
Hello! |
|
Hello, |
|
I cannot re-open PRs; @ericof it will be helpful if you can reopen this. Thanks! |
|
@sacha-c If this doesn't get re-opened, please open a new PR. My apologies for these difficulties! |
|
Unfortunately I could not reopen (at least not in mobile app) |
|
I have just recreated the PR as requested: #1997 |
Description
Cookiecutter supports using _jinja2_env_vars to modify the jinja environment. However when modifying
variable_start_stringorvariable_end_stringit will not work because we are hard-coding the start and end strings for the main directory creation (see here). In addition, the jinja context is not always populated with the _jinja2_env_vars, for example when getting the placeholder prompts hereTechnical details
This change does 3 things (which are in separate commits for readability):
create_env_with_contextso the jinja environment is created similarly and with context each time.prompt_and_deletefromutilstoprompt. It was causing circular import issues when havingpromptimportutils, becauseutilswas importingprompt. And in any case I would say it makes more sense for it to live inpromptbecause it is a prompt as well after all.I also removed the
ensure_dir_is_templatedcheck because the same logic is used to find the dir, and is therefore redundant.Use-case
In react-native projects, it's extremely common to use
{{and}}to pass objects to components. For example:Since
{{is the default jinja variable string prefix, jinja goes crazy with react-native templates 🤪 .A solution to this is to set
_jinja2_env_vars.variable_start_string == '{%{'(or something else). But cookiecutter currently has issues when overriding this setting.Testing
Tested locally on a react-native project with
_jinja2_env_vars.variable_start_string == '{%{'and_jinja2_env_vars.variable_end_string == '}%}'