Running `briefcase create linux system` using a version of Python that doesn't match the system creates an unusable project
- Dominant language
- Python
- Stars
- 3.3k
- Forks
- 549
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 40
Description
### Describe the bug
If the version of Python doesn't match the system's Python, Briefcase rolls out the template first, then informs the user of the version mismatch.
```console
❯ briefcase run linux system
[font_size] Finalizing application configuration...
Targeting pop:jammy (Vendor base debian)
Determining glibc version... done
Targeting glibc 2.35
Targeting Python3.11
[font_size] Generating application template...
Using app template: https://github.com/beeware/briefcase-linux-system-template.git, branch v0.3.15
Template branch v0.3.15 not found; falling back to development template
Using existing template (sha acf08d44f5a573000a3cf6d22c0b97b9807c7310, updated Wed Apr 26 14:54:14 2023)
[font_size] Installing support package...
No support package required.
The version of Python being used to run Briefcase (3.11) is not the system python3 (3.10).
```
Given this, a user is likely to switch to the matching Python version and try again. However, the template has already been laid out for the other Python version and the command fails as though you are missing the `python3-dev` package.
```console
❯ briefcase run linux system
[font_size] Finalizing application configuration...
Targeting pop:jammy (Vendor base debian)
Determining glibc version... done
Targeting glibc 2.35
Targeting Python3.10
[font_size] Building application...
Build bootstrap binary...
make: Entering directory '/home/russell/github/beeware/toga/examples/font_size/build/font_size/pop/jammy/bootstrap'
python3.11 -c "import sys; print(f'#define PY_TAG \"{sys.version_info.major}.{sys.version_info.minor}\"')" > pyversion.h
make: /usr/bin/python3.11-config: No such file or directory
make: /usr/bin/python3.11-config: No such file or directory
gcc -o font_size main.c pyversion.h -fPIE
main.c:9:10: fatal error: Python.h: No such file or directory
9 | #include
| ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:10: font_size] Error 1
make: Leaving directory '/home/russell/github/beeware/toga/examples/font_size/build/font_size/pop/jammy/bootstrap'
Building bootstrap binary...
Error building bootstrap binary for font_size.
```
I suppose the worst case scenario is if the user has the Python header file installed for the non-system Python. Because then the build actually succeeds and now the stub app is linked against a header file that won't be required for it when installed on other systems.
### Steps to reproduce
1. Use a Python newer than the system to create a project
2. Then use the system python to try to build that project
### Expected behavior
Ideally, the template wouldn't even be rolled out if the Python versions are mismatched.
The order of events may be difficult here, though; so, deleting the project or at least telling the user to delete the project may be next best.
### Screenshots
_No response_
### Environment
- Operating System: pop os 22.04
- Python version: 3.11.4
- Software versions:
- Briefcase: `0.3.15.dev361+g02f412be.d20230620`
### Logs
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start with the `briefcase create linux system` and `briefcase run linux system` command flow, focusing on when the Python-version check occurs relative to template generation. Reproduce the mismatch using the commands shown and verify that a failed check no longer leaves an unusable template, or clearly tells the user what to remove before retrying.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100