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

_copier_conf and other global variables can't be used in the questions section #1502

Open
AdrianFreundQC opened this issue Feb 6, 2024 · 3 comments

Comments

@AdrianFreundQC
Copy link
Contributor

Describe the problem

The _copier_conf variable can be used in templated file names, file contents, and task and migration commands, however it can't be used in the questions section, for example in the default or when key of a template.

I don't know if this is intentional design or an oversight. From my point of view it is definitely unexpected.

Supporting this would enable some new use cases. In my case I want to add a new boolean question to a project, that defaults no yes for new projects, but defaults to no for existing projects being updated.

I tried doing this by setting default: "{{ _copier_conf.src_path is not none }}"

This resulted in '_copier_conf' is undefined

Template

use_mypy:
  type: bool
  help: "Should this project run full mypy type checking during CI?"
  default: "{{ _copier_conf.src_path is not none }}" # to prevent breaking existing projects

To Reproduce

No response

Logs

No response

Expected behavior

The question should default to yes for new projects and no for existing projects

Screenshots/screencasts/logs

No response

Operating system

macOS

Operating system distribution and version

Sonoma 14.2.1

Copier version

9.1.1

Python version

Python 3.11.0

Installation method

distro package

Additional context

I can try writing a pull request for this. Doesn't look too hard to fix.

@AdrianFreundQC AdrianFreundQC added bug triage Trying to make sure if this is valid or not labels Feb 6, 2024
@yajo
Copy link
Member

yajo commented Feb 11, 2024

Expected behavior

The question should default to yes for new projects and no for existing projects

I don't think adding ˋ_copier_confˋ to the template context would fix your problem.

When you're updating a project, a question's default value doesn't come from the template defaults. Instead, it comes from the last answers. At least, if the last answer was recorded (it wasn't skipped nor a password).

So, after knowing that, do you think the feature is still relevant?

I'm gonna close the issue assuming there's no real use for this feature, to keep the issue tracker clean. But please feel free to keep commenting. I'll reopen if there comes to be a real use case.

Thanks! ❤️

@yajo yajo closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2024
@geodab
Copy link

geodab commented Aug 14, 2024

Hello, I also found this confusing and unexpected, but for a slightly different use case.

In particular, it would be nice to use the _folder_name or _copier_conf.dst_path as a basis for deriving a project_name or project_type.

Since these are available when rendering the initial _message_before_copy it is surprising that they are unavailable in a question prompt presented immediately afterward.

Also, while trying to understand what was happening I attempted to find a workaround by defining a ContextHook extension to update the context, but I think I ran into the same issue with that--it worked in the context of rendering the message template but not for a prompt default template. Again, that was unexpected, but ultimately led me to discover this closed issue. Would it be possible to reopen it to address these use cases?

@yajo
Copy link
Member

yajo commented Aug 16, 2024

That makes more sense.

@yajo yajo reopened this Aug 16, 2024
@yajo yajo removed the triage Trying to make sure if this is valid or not label Aug 16, 2024
@yajo yajo added this to the Community contribution milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants