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.

In order to factor out common calculations, especially amongst file and directory names, it would be useful to be able to define variables in copier.yml whose values are calculated based on answers or other variables.

For example, when creating a template for a Java project, based on the name of the project, I would like to calculate the name of the root package, and also the path of the root package.

project_name:
  type: str
  default: hello-world

root_package:
  type: str
  default: "org.example.{{ project_name | title | regex_replace('-', '.') }}"

root_package_dir:
  type: str
  default: "{{ root_package | regex_replace('.', '/') }}"

The root package variable would be referred to by multiple files.

The root package directory must be calculated this way since you cannot have a filename with a slash (/).

Describe the solution you’d like I suggest adding support for defining variables in copier.yml in a similar way as defining questions. The two are distinguished in some way, perhaps by a prefix such as a double underscore (__) or by a key such as hidden: true. I suggest that it be possible to mix defining variables and questions such that a question definition can refer to prior variables.

Describe alternatives you’ve considered This feature is called Private Variables in Cookicutter.

An obvious workaround is to define questions with default values. This is unsatisfactory because this forces users to read the trivial question and decide to hit the enter key, which adds unnecessary overhead and

Additional context The given example refers to Java, but templates for other programming languages, including Python, could have similar issues.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pawamoycommented, Sep 30, 2022

@FlorianLudwig when: false can lead to surprising behavior, see https://github.com/copier-org/copier/discussions/678#discussioncomment-2822746 (just for your information, not trying to prevent you from using when: false if that works for you 🙂 )

1reaction
yajocommented, Jul 16, 2022

For the time being, you already know the workarounds we have. However, you inspired me to write #718. Let’s close this one. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does the term "shared variable" mean? How is it different ...
In OOP, Shared Variables are the variables that can be accessed for more than one object. Global Variables are the ones with the...
Read more >
Using the LabVIEW Shared Variable - NI - National Instruments
Use single-process variables to transfer data between two different locations on the same VI that cannot be connected by wires, such as parallel ......
Read more >
9.10 Shared Variables
9.10 Shared Variables. Static Semantics. 1. If two different objects, including nonoverlapping parts of the same object, are independently addressable, ...
Read more >
Shared variables - Apache FreeMarker Manual
Shared variables are variables that are defined for all templates. You can add shared variables to the configuration with the setSharedVariable methods:.
Read more >
Shared Variables in Pthreads
Initialized data, uninitialized data, and heap segments. Implications for Variable Sharing. "Global" Data Segments: Threads can "share" variables in the ...
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