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

Dictionary variables: example from docs doesn't work any more after 2.2+ #1960

Open
sandroden opened this issue Oct 15, 2023 · 1 comment
Open
Labels
documentation This issue/PR relates to or includes documentation.

Comments

@sandroden
Copy link

Starting from cookiecutter 2.2 and surely on 2.4 the example of dictionary variables from the docs doesn't work anymore.

I should probably say: It doesn't work as I was used to using it... and it seemed perfectly reasonable to me.

It seems that the current implementation doesn't allow anything not written in cookiecutter.json while up to 2.1.1 you could just give a template of what you would have added. In the example docs, if you wanted to add different file_types you could just pass them in the context (when working from Python script) and it just worked.
Now we completely lost any dynamicity, you have to write down all the possibilities in advance, which is not an option in many cases.

Let me know if I just overlooked the docs and missed how to add dynamicity, if not please consider how many people were relying on that feature or could benefit from that feature. I could provide tons of examples... currently, I was looping on users on docker services, on ports, on files... all this just stopped working.

The docs say "Dictionary variables provide a way to define deep structured information when rendering a template.".
It states structure not data! The current implementation meddles with data, you can't send a file_type if not in cookiecutter.json

If I understood correctly the move with 2.2 was to create a nested choice type (please tell me if I'm wrong), but that should not be as the expenses of the possibility already there from 1.5+ to loop on dynamic values.

BTW: If I create an extra_context that only has one file_type, the other is added anyhow, I would consider this definitely a bug

@tied
Copy link

tied commented Oct 22, 2023

Maybe I have the same problem. With cookiecutter 2.1.1 everything works fine.

After that line the try exits with an exception:

    try: 
        context = {{ cookiecutter | jsonify }}
        ...
    except BaseException as e:
        print('Applications create errors! ' + str(e))
        sys.exit(1)

name 'null' is not defined doesn't really make sense to me because I don't have any var which is called name.
Here my cookiecutter.json

{
    "customer_name": "",
    "customer_slug": "{{ cookiecutter.customer_name|lower|replace(' ', '-') }}",
    "default_environments": "production,test",
    ...
}

Is it possible that everything before the underscore is ignored?

@ericof ericof added the documentation This issue/PR relates to or includes documentation. label Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This issue/PR relates to or includes documentation.
Projects
None yet
Development

No branches or pull requests

3 participants