Skip to content

Using template as a key in the cookiecutter context has special meaning in versions >=2.2.0 #1347

@rmartin16

Description

@rmartin16

Workaround

Until Briefcase v0.3.15 is released, run this command after Briefcase is installed:

python -m pip install cookiecutter==2.1.1

Impact

The briefcase new command is unusable with cookiecutter>=2.2.0.

Describe the bug

The release of cookiecutter 2.2.0 (and 2.2.1) introduces special meaning for template in a cookiecutter context. This was to add support for nested templates in cookiecutter/cookiecutter#1770.

Briefcase is currently passing a URL or filepath here from briefcase new so the source of the template is included in pyproject.toml of the rolled out project.

Example trace from running briefcase new:

Traceback (most recent call last):
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/bin/briefcase", line 8, in <module>
    sys.exit(main())
  File "/home/russell/github/beeware/briefcase/src/briefcase/__main__.py", line 25, in main
    command(**options)
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/new.py", line 531, in __call__
    return self.new_app(
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/new.py", line 497, in new_app
    self.generate_template(
  File "/home/russell/github/beeware/briefcase/src/briefcase/commands/base.py", line 891, in generate_template
    self.tools.cookiecutter(
  File "/home/russell/github/beeware/briefcase/venv-3.10-briefcase/lib/python3.10/site-packages/cookiecutter/main.py", line 116, in cookiecutter
    ).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Steps to reproduce

  1. Install latest cookiecutter: python -m pip install -U cookiecutter==2.2.0
  2. Run briefcase new --no-input

Expected behavior

The template is rolled out properly without an error.

Screenshots

No response

Environment

  • Operating System: pop os 22.04
  • Python version: 3.10.12
  • Software versions:
    • Briefcase: 0.3.14 and 0.3.15.dev385+g5ed30106.d20230706

Logs

0.3.14
briefcase.2023_07_06-13_37_09.new.log

0.3.15.dev385+g5ed30106.d20230706
briefcase.2023_07_06-13_39_17.new.log

Additional context

It isn't at least immediately clear to me if cookiecutter considered existing uses of template in a context; however, I am also not particularly sure if Briefcase's use of cookiecutter is especially different from intended use cases.

Nonetheless, it doesn't look like Briefcase's use of template in context should be accommodated in cookiecutter....and instead, we should just change template to template_source or something.

This also means any new installation of Briefcase will encounter this exception. A new release is probably necessary to mitigate this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA crash or error in behavior.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions