Repository: beeware/briefcase

Issue:
Using `template` as a key in the cookiecutter `context` has special meaning in versions >=2.2.0
### 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](https://github.com/beeware/briefcase/blob/73148bfa6012356ffa23f6a0c0e719e8113e795f/src/briefcase/commands/new.py#L471) 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](https://github.com/beeware/briefcase/files/11970740/briefcase.2023_07_06-13_37_09.new.log)

0.3.15.dev385+g5ed30106.d20230706
[briefcase.2023_07_06-13_39_17.new.log](https://github.com/beeware/briefcase/files/11970755/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.

Comments:

Patch:
diff --git a/changes/1347.bugfix.rst b/changes/1347.bugfix.rst
new file mode 100644
index 00000000..46493e9f
--- /dev/null
+++ b/changes/1347.bugfix.rst
@@ -0,0 +1,1 @@
+An error no longer occurs when creating a new Briefcase project while ``cookiecutter>=2.2.0`` is installed.
diff --git a/src/briefcase/commands/new.py b/src/briefcase/commands/new.py
index c0993059..aa24ce22 100644
--- a/src/briefcase/commands/new.py
+++ b/src/briefcase/commands/new.py
@@ -468,8 +468,8 @@ What GUI toolkit do you want to use for this project?""",
         # include the version of Briefcase as well as the source of the template.
         context.update(
             {
-                "template": template,
-                "branch": branch,
+                "template_source": template,
+                "template_branch": branch,
                 "briefcase_version": briefcase.__version__,
             }
         )


Test patch:
diff --git a/tests/commands/new/test_new_app.py b/tests/commands/new/test_new_app.py
index eb5e8faf..5d8b3803 100644
--- a/tests/commands/new/test_new_app.py
+++ b/tests/commands/new/test_new_app.py
@@ -76,8 +76,8 @@ def test_new_app(
             # The expected app context
             # should now also contain the
             # default template and branch
-            "template": "https://github.com/beeware/briefcase-template",
-            "branch": expected_branch,
+            "template_source": "https://github.com/beeware/briefcase-template",
+            "template_branch": expected_branch,
             "briefcase_version": briefcase_version,
         },
     )
@@ -129,8 +129,8 @@ def test_new_app_missing_template(monkeypatch, new_command, tmp_path):
             # The expected app context
             # should now also contain the
             # default template and branch
-            "template": "https://github.com/beeware/briefcase-template",
-            "branch": "v37.42.7",
+            "template_source": "https://github.com/beeware/briefcase-template",
+            "template_branch": "v37.42.7",
             "briefcase_version": "37.42.7",
         },
     )
@@ -196,8 +196,8 @@ def test_new_app_dev(monkeypatch, new_command, tmp_path, briefcase_version):
                     # The expected app context
                     # should now also contain the
                     # default template and branch
-                    "template": "https://github.com/beeware/briefcase-template",
-                    "branch": "v37.42.7",
+                    "template_source": "https://github.com/beeware/briefcase-template",
+                    "template_branch": "v37.42.7",
                     "briefcase_version": briefcase_version,
                 },
             ),
@@ -213,8 +213,8 @@ def test_new_app_dev(monkeypatch, new_command, tmp_path, briefcase_version):
                     # The expected app context
                     # should now also contain the
                     # default template and branch
-                    "template": "https://github.com/beeware/briefcase-template",
-                    "branch": "v37.42.7",
+                    "template_source": "https://github.com/beeware/briefcase-template",
+                    "template_branch": "v37.42.7",
                     "briefcase_version": briefcase_version,
                 },
             ),
@@ -261,8 +261,8 @@ def test_new_app_with_template(monkeypatch, new_command, tmp_path):
             # The expected app context
             # should now also contain the
             # template and branch
-            "template": "https://example.com/other.git",
-            "branch": "v37.42.7",
+            "template_source": "https://example.com/other.git",
+            "template_branch": "v37.42.7",
             "briefcase_version": "37.42.7",
         },
     )
@@ -313,8 +313,8 @@ def test_new_app_with_invalid_template(monkeypatch, new_command, tmp_path):
             # The expected app context
             # should now also contain the
             # template and branch
-            "template": "https://example.com/other.git",
-            "branch": "v37.42.7",
+            "template_source": "https://example.com/other.git",
+            "template_branch": "v37.42.7",
             "briefcase_version": "37.42.7",
         },
     )
@@ -368,8 +368,8 @@ def test_new_app_with_invalid_template_branch(monkeypatch, new_command, tmp_path
             # The expected app context
             # should now also contain the
             # template and branch
-            "template": "https://example.com/other.git",
-            "branch": "v37.42.7",
+            "template_source": "https://example.com/other.git",
+            "template_branch": "v37.42.7",
             "briefcase_version": "37.42.7",
         },
     )
@@ -414,8 +414,8 @@ def test_new_app_with_branch(monkeypatch, new_command, tmp_path):
             # The expected app context
             # should now also contain the
             # template and branch
-            "template": "https://github.com/beeware/briefcase-template",
-            "branch": "experimental",
+            "template_source": "https://github.com/beeware/briefcase-template",
+            "template_branch": "experimental",
             "briefcase_version": "37.42.7",
         },
     )