question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-prompted values

See original GitHub issue

In my templates I often duplicate code to build a string based on the user’s answers. I would like to avoid duplicating this code and instead populate a variable once, in copier.yml using a non-prompted value. The user must not change this value, I’d like to always use the default. Something like this maybe?

gitlab_namespace:
  type: str

repository_name:
  type: str

# here
namespace_id:
  type: str
  prompt: no
  default: "[% if gitlab_namespace.count('/') %]r-[% else %]p-[% endif %][[ gitlab_namespace.split('/')[-1] ]]"

# then I could populate other variables as well, these are just examples
docker_image:
  type: str
  prompt: no
  default: "[[ namespace_id ]]/[[ repository_name ]]-docker"

package_distribution_name:
  type: str
  prompt: no
  default: "[[ namespace_id ]]-[[ repository_name ]]"

There surely are other ways than introducing a new prompt key to do this though, like injecting data in the context from a special _context list or a pre-generation hook (like a Python script modifying and returning the context dict). Maybe there’s a way to play with Jinja2’s extends, include, macro, with or set capabilities as well 🙂

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
pawamoycommented, Sep 24, 2020

I forgot to report back. It actually works. Filename are horribly long and difficult to read, but it works. The “context” file also must be placed at the root of the template, because slashes are not allowed in filenames.

1reaction
yajocommented, Jul 22, 2020

Those problems are not big deals IMHO. I am used to importing other functions from other modules in Python and that sounds natural to me. Actually, being explicit on why things work is good, thinking about maintenance (not just Copier, but also downstream templates).

About parenthesis, actually they seem good to me also. If you’re all the time reusing the same macros (slugify could be one of those), you can have a separate git repository with macros that you include as a submodule in your other templates (remember Copier supports git submodules). Then, it would make more sense to use macro arguments, since the context can easily differ on each template. Maintainability isn’t always about saving keystrokes! 😊

Well, as I think we agree this is a good solution, let me close this. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

You Need to Know about Prompted and Unprompted Feedback
Assign different values to your customers based on the level of satisfaction and loyalty. You should prioritize communication with clients who ...
Read more >
THE EFFECTS OF DIFFERENTIAL REINFORCEMENT ... - NCBI
The purpose of the current investigation was to compare the delivery of high-quality reinforcers exclusively following unprompted responses (differential ...
Read more >
What does unprompted mean? - Definitions.net
The numerical value of unprompted in Chaldean Numerology is: 8. Pythagorean Numerology. The numerical value of unprompted in Pythagorean Numerology is: 7 ...
Read more >
11.5: Spontaneous Reactions and Free Energy
Determine the spontaneity of a reaction based on the value of its change in free energy at high and low temperatures.
Read more >
Spontaneity and Equilibrium - 2012 Book Archive
Table 18.3 "Criteria for the Spontaneity of a Process as Written" summarizes these criteria and their relative values for spontaneous, nonspontaneous, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found