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

Boolean in data-file #1951

Open
crenus opened this issue Jan 27, 2025 · 9 comments
Open

Boolean in data-file #1951

crenus opened this issue Jan 27, 2025 · 9 comments
Labels
bug triage Trying to make sure if this is valid or not

Comments

@crenus
Copy link

crenus commented Jan 27, 2025

Describe the problem

Current problem i am facing is the passing of a boolean in a datafile. I have a jinja condition around creating a file, and when its false, it doesnt generate. I am using a data file for "test cases" that the template works. If i pass the value false in a data file, the template still creates the file.

If I change the template to check for the value of the input, it works but that would break the usage, cause one uses a string while the input should be a boolean if used by cli

Template

{% if include_echo_controller %}EchoController.java.jinja{% endif %}

And the data file just has:
include_echo_controller: false

And in copier.yml

include_echo_controller:
  type: bool
  default: false
  help: "Do you want to include the example EchoController?"

To Reproduce

No response

Logs

Expected behavior

I expect the parser to treat a boolean in a yaml file as such.

Screenshots/screencasts/logs

No response

Operating system

Linux

Operating system distribution and version

Ubuntu

Copier version

copier 9.4.0

Python version

3.14

Installation method

pip+git

Additional context

No response

@crenus crenus added bug triage Trying to make sure if this is valid or not labels Jan 27, 2025
@pawamoy
Copy link
Contributor

pawamoy commented Jan 27, 2025

Try moving the extension outside of the tag:

{% if include_echo_controller %}EchoController.java{% endif %}.jinja

@crenus
Copy link
Author

crenus commented Jan 28, 2025

Na, same thing. even with the .jinja on the outside, it still generates the file. I have tried the value include_echo_controller in different formats as well using false, False, but still same thing. If I do string comparison it works, but obviously thats an issue cause the copier.yml states the type as bool

@pawamoy
Copy link
Contributor

pawamoy commented Jan 28, 2025

I cannot reproduce the issue you describe:

% cd /tmp 
% mkdir template
mkdir: created directory 'template'
% echo -e 'include_echo_controller:\n  type: bool\n  default: false' > template/copier.yml
% echo -e 'hello' > 'template/{% if include_echo_controller %}EchoController.java{% endif %}.jinja'
% ll template 
total 8.0K
-rw-r--r-- 1 pawamoy users 54 Jan 28 17:23  copier.yml
-rw-r--r-- 1 pawamoy users  6 Jan 28 17:24 '{% if include_echo_controller %}EchoController.java{% endif %}.jinja'
% copier copy template project
🎤 include_echo_controller (bool)
   No

Copying from template version None
    create  .


% ll project 
total 0
% rf project                  
% copier copy template project
🎤 include_echo_controller (bool)
   Yes

Copying from template version None
    create  .
    create  EchoController.java

@crenus
Copy link
Author

crenus commented Jan 28, 2025

Yea so only difference is using a data file. So if you create a yaml wiht:

include_echo_controller: false

And then

   copier copy --data-file="values.yaml" ./ "$temp_dir" --trust

use what you would need to passs, but mainly here passing as a data file is what causes this

@pawamoy
Copy link
Contributor

pawamoy commented Jan 28, 2025

Ah, right, my bad, let me try again 🙂

@crenus
Copy link
Author

crenus commented Jan 28, 2025

No problem!
I also just tried using the answers-file flag and didnt work.
Just to see, i also removed that value from my file, and then passed the --defaults, but that still does the same thing, and the default is false. So maybe there is something else i am missing? Verison issue or other?

@pawamoy
Copy link
Contributor

pawamoy commented Jan 28, 2025

Still cannot reproduce:

% ll template 
total 8.0K
-rw-r--r-- 1 pawamoy users 55 Jan 28 17:25  copier.yml
-rw-r--r-- 1 pawamoy users  6 Jan 28 17:24 '{% if include_echo_controller %}EchoController.java{% endif %}.jinja'
-rw-r--r-- 1 pawamoy users  0 Jan 28 18:44  readme.md
% cat values.yml                                             
include_echo_controller: false
% copier copy --trust --data-file=values.yml template project

Copying from template version 0.2.0
    create  readme.md


% ll project 
total 0
-rw-r--r-- 1 pawamoy users 0 Jan 28 18:45 readme.md
% vim values.yml         
% cat values.yml                                             
include_echo_controller: true
% rf project 
% copier copy --trust --data-file=values.yml template project

Copying from template version 0.2.0
    create  readme.md
    create  EchoController.java


% ll project 
total 4.0K
-rw-r--r-- 1 pawamoy users 6 Jan 28 18:46 EchoController.java
-rw-r--r-- 1 pawamoy users 0 Jan 28 18:46 readme.md

I added a readme.md file because without it, the generated folder would be empty, and Copier seems to remove it (no project output directory generated).

@crenus
Copy link
Author

crenus commented Jan 28, 2025

What version of copier and what system are you on?
im running python 3.13 ( which I now see is different than I stated above) in docker on alpine, with copier 9.4.1...

This is super funky to me... Im going to try out a few different things i guess

@pawamoy
Copy link
Contributor

pawamoy commented Jan 28, 2025

Copier 9.4.1 too, ArchLinux, Python 3.11.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Trying to make sure if this is valid or not
Projects
None yet
Development

No branches or pull requests

2 participants