Repository: beeware/briefcase
Pull request #1276 (2023-05-16 16:37:07)

Pass the Briefcase version to cookiecutter from `NewCommand`
## Changes
- `briefcase new` now passes `briefcase.__version__` as `briefcase_version` to cookiecutter so `pyproject.toml` contains the Briefcase version instead of `Unknown`

## PR Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
- [x] All new features have been tested
- [x] All new features have been documented
- [x] I have read the **CONTRIBUTING.md** file
- [x] I will abide by the code of conduct



Patch:
diff --git a/changes/1273.misc.rst b/changes/1273.misc.rst
deleted file mode 100644
index 276556ea..00000000
--- a/changes/1273.misc.rst
+++ /dev/null
@@ -1,1 +0,0 @@
-Updated pytest-xdist from 3.2.1 to 3.3.0.
diff --git a/changes/1276.bugfix.rst b/changes/1276.bugfix.rst
new file mode 100644
index 00000000..ad171f04
--- /dev/null
+++ b/changes/1276.bugfix.rst
@@ -0,0 +1,1 @@
+When creating a new Briefcase project, the header line in ``pyproject.toml`` now contains the version of Briefcase instead of "Unknown".
diff --git a/setup.cfg b/setup.cfg
index 45cc3481..c1f396a6 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -92,7 +92,7 @@ dev =
     coverage-conditional-plugin == 0.8.0
     pre-commit == 3.3.1
     pytest == 7.3.1
-    pytest-xdist == 3.3.0
+    pytest-xdist == 3.2.1
     setuptools_scm[toml] == 7.1.0
     tox == 4.5.1
 docs =
diff --git a/src/briefcase/commands/new.py b/src/briefcase/commands/new.py
index 701e05f6..41fea96e 100644
--- a/src/briefcase/commands/new.py
+++ b/src/briefcase/commands/new.py
@@ -467,10 +467,15 @@ What GUI toolkit do you want to use for this project?""",
                 f"A directory named '{context['app_name']}' already exists."
             )
 
-        # This is to have briefcase template file
-        # mentioning extra context on which template/branch
-        # the project was generated from.
-        context.update({"template": template, "branch": branch})
+        # Additional context for the Briefcase template pyproject.toml header to
+        # include the version of Briefcase as well as the source of the template.
+        context.update(
+            {
+                "template": template,
+                "branch": branch,
+                "briefcase_version": briefcase.__version__,
+            }
+        )
 
         try:
             self.logger.info(f"Using app template: {template}, branch {branch}")


Test patch:
diff --git a/tests/commands/new/test_new_app.py b/tests/commands/new/test_new_app.py
index c78b6030..eb5e8faf 100644
--- a/tests/commands/new/test_new_app.py
+++ b/tests/commands/new/test_new_app.py
@@ -78,6 +78,7 @@ def test_new_app(
             # default template and branch
             "template": "https://github.com/beeware/briefcase-template",
             "branch": expected_branch,
+            "briefcase_version": briefcase_version,
         },
     )
 
@@ -130,6 +131,7 @@ def test_new_app_missing_template(monkeypatch, new_command, tmp_path):
             # default template and branch
             "template": "https://github.com/beeware/briefcase-template",
             "branch": "v37.42.7",
+            "briefcase_version": "37.42.7",
         },
     )
 
@@ -196,6 +198,7 @@ def test_new_app_dev(monkeypatch, new_command, tmp_path, briefcase_version):
                     # default template and branch
                     "template": "https://github.com/beeware/briefcase-template",
                     "branch": "v37.42.7",
+                    "briefcase_version": briefcase_version,
                 },
             ),
             mock.call(
@@ -212,6 +215,7 @@ def test_new_app_dev(monkeypatch, new_command, tmp_path, briefcase_version):
                     # default template and branch
                     "template": "https://github.com/beeware/briefcase-template",
                     "branch": "v37.42.7",
+                    "briefcase_version": briefcase_version,
                 },
             ),
         ]
@@ -259,6 +263,7 @@ def test_new_app_with_template(monkeypatch, new_command, tmp_path):
             # template and branch
             "template": "https://example.com/other.git",
             "branch": "v37.42.7",
+            "briefcase_version": "37.42.7",
         },
     )
 
@@ -310,6 +315,7 @@ def test_new_app_with_invalid_template(monkeypatch, new_command, tmp_path):
             # template and branch
             "template": "https://example.com/other.git",
             "branch": "v37.42.7",
+            "briefcase_version": "37.42.7",
         },
     )
 
@@ -364,6 +370,7 @@ def test_new_app_with_invalid_template_branch(monkeypatch, new_command, tmp_path
             # template and branch
             "template": "https://example.com/other.git",
             "branch": "v37.42.7",
+            "briefcase_version": "37.42.7",
         },
     )
 
@@ -409,6 +416,7 @@ def test_new_app_with_branch(monkeypatch, new_command, tmp_path):
             # template and branch
             "template": "https://github.com/beeware/briefcase-template",
             "branch": "experimental",
+            "briefcase_version": "37.42.7",
         },
     )