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

cookiecutter ignores dictionary variables specified in config-file #1231

Open
dHannasch opened this issue Sep 18, 2019 · 0 comments
Open

cookiecutter ignores dictionary variables specified in config-file #1231

dHannasch opened this issue Sep 18, 2019 · 0 comments

Comments

@dHannasch
Copy link
Contributor

Description:

I am trying to save/load values for dictionary variables in a config file.
However, cookiecutter silently ignores the given value.
I expected the given value to not be ignored.

What I've run:

$ ~/anaconda3/envs/python37env/bin/cookiecutter https://github.com/dHannasch/cookiecutter-pypackage --checkout try-to-make-a-complex-multiple-choice --default-config
full_name [Audrey Roy Greenfeld]: 
email [audreyr@example.com]: 
github_username [audreyr]: 
project_name [Python Boilerplate]: 
project_slug [python_boilerplate]: 
project_short_description [Python Boilerplate contains all the boilerplate you need to create a Python package.]: 
pypi_username [audreyr]: 
Select link_to_website:
1 - {'link_immediately': 'y', 'disable_forever': 'n'}
2 - {'link_immediately': 'n', 'disable_forever': 'n'}
3 - {'link_immediately': 'n', 'disable_forever': 'y'}
Choose from 1, 2, 3 (1, 2, 3) [1]: 2
version [0.1.0]: 
use_pytest [n]: 
use_pypi_deployment_with_travis [y]: 
add_pyup_badge [n]: 
Select command_line_interface:
1 - Click
2 - No command-line interface
Choose from 1, 2 (1, 2) [1]: 
create_author_file [y]: 
Select open_source_license:
1 - MIT license
2 - BSD license
3 - ISC license
4 - Apache Software License 2.0
5 - GNU General Public License v3
6 - Not open source
Choose from 1, 2, 3, 4, 5, 6 (1, 2, 3, 4, 5, 6) [1]: 

Encoded in a config file, these choices are:

default_context:

    _template:                 'cookiecutter-pypackage/'
    add_pyup_badge:            'n'
    command_line_interface:    'Click'
    create_author_file:        'y'
    email:                     'audreyr@example.com'
    full_name:                 'Audrey Roy Greenfeld'
    github_username:           'audreyr'
    link_to_website:           {'link_immediately': 'n', 'disable_forever': 'n'}
    open_source_license:       'MIT license'
    project_name:              'Python Boilerplate'
    project_short_description: 'Python Boilerplate contains all the boilerplate you need to create a Python package.'
    project_slug:              'python_boilerplate'
    pypi_username:             'audreyr'
    use_pypi_deployment_with_travis: 'y'
    use_pytest:                'n'
    version:                   '0.1.0'

So far so good.

$ cd python_boilerplate/
python_boilerplate$ git init
Initialized empty Git repository in /tmp/python_boilerplate/.git/
python_boilerplate$ git add --all
python_boilerplate$ git commit -a -m "Create initial git commit so that we can see the git diff later."
python_boilerplate$ cd ..
$ ~/anaconda3/envs/python37env/bin/cookiecutter https://github.com/dHannasch/cookiecutter-pypackage --checkout try-to-make-a-complex-multiple-choice --config-file python_boilerplate/cookiecutterrc --overwrite-if-exists
You've downloaded /ascldap/users/dahanna/.cookiecutters/cookiecutter-pypackage before. Is it okay to delete and re-download it? [yes]: 
full_name [Audrey Roy Greenfeld]: 
email [audreyr@example.com]: 
github_username [audreyr]: 
project_name [Python Boilerplate]: 
project_slug [python_boilerplate]: 
project_short_description [Python Boilerplate contains all the boilerplate you need to create a Python package.]: 
pypi_username [audreyr]: 
Select link_to_website:
1 - {'link_immediately': 'y', 'disable_forever': 'n'}
2 - {'link_immediately': 'n', 'disable_forever': 'n'}
3 - {'link_immediately': 'n', 'disable_forever': 'y'}
Choose from 1, 2, 3 (1, 2, 3) [1]: 

Huh! The choice in the config-file is silently ignored. And indeed if we check the output, it uses the original default choice, not the choice in the config file.

I also tried

    link_to_website:           2

which is also silently ignored.

Breaking the dictionary up into YAML also doesn't work:

    link_to_website:
      link_immediately: 'n'
      disable_forever: 'n'

(That part isn't new information --- @lbrack tried nesting in YAML and that didn't work. #1149
It looks like @lbrack wrote a fix (?) but I don't see a pull request at the moment. lbrack@c9eb982)

I don't think it matters much whether the config-file is valid YAML, just as long as there's some way to store choices. As @lbrack noted, we totally can enter dictionaries on the command line, and it works great:

operating_systems [default]: {"windows": "n"}

It's strange that the config-files can't do the same thing, even without the proper nested YAML @lbrack wants. I haven't been able to puzzle out what's happening under the hood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
1.8.0 Release
  
To do
Development

No branches or pull requests

3 participants