Provide option for PYC-only distribution
- Dominant language
- Python
- Stars
- 3.3k
- Forks
- 549
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 40
Description
### What is the problem or limitation you are having?
Briefcase currently purges all `__pycache__` folders as part of the build process and enables the `PYTHONDONTWRITEBYTECODE` setting on stub binaries. The latter is needed to protect the integrity of code signed bundles; but the process of in-memory PYC compilation can be a non-trivial component of process startup time.
### Describe the solution you'd like
It should be possible to configure Briefcase to:
1. *Not* strip `__pycache__` folders as part of a build
2. *Guarantee* the compilation of PYC files as part of a build
3. *Only* ship PYC files as part of a packaged app.
### Describe alternatives you've considered
* Do nothing - the current "source only" approach works.
* Remove `__pycache__` stripping entirely.
### Additional context
Shipping *only* PYC files could be considered a light form of obfuscation (see #1865).
Ideally, the current hard-coded "PYC cleanup" strategy should be a pluggable API providing three options out of the box:
1. Full PY and PYC distribution
2. PY only distribution
3. PYC only distribution
with an API that would allow third parties to define their own approach that performs other obfuscation methods. (2) is the current default; moving to (1) as a new default would be worth considering.
We should also ensure that PYC files are fully compiled as part of options (2) and (3). `compileall` may be useful here. The support packages may also need to be modified to ensure that they provide pre-compiled PYC content (or the build process modified to include PYC compilation of the standard library)
[PEP 3147](https://peps.python.org/pep-3147/) requires that when in "`.pyc` only" mode, `__pycache__` folders aren't used. This will require some post-processing after compilation to move `.pyc` files into their parent directory.
Contributor guide
Research direction
Start by tracing Briefcase's build step that purges __pycache__, then review the support packages and the compileall and PEP 3147 requirements mentioned here. Done means a configurable policy supports full PY/PYC, PY-only, and PYC-only distributions, guarantees compilation, and handles the PYC-only layout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100