Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide option for PYC-only distribution #2073

Open
freakboy3742 opened this issue Dec 3, 2024 · 0 comments
Open

Provide option for PYC-only distribution #2073

freakboy3742 opened this issue Dec 3, 2024 · 0 comments
Labels
enhancement New features, or improvements to existing features.

Comments

@freakboy3742
Copy link
Member

freakboy3742 commented Dec 3, 2024

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 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.

@freakboy3742 freakboy3742 added the enhancement New features, or improvements to existing features. label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

1 participant