RustPython / RustPython/RustPython

[RFC] Bundle frozen modules

Abierto
#4,204 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

RFC
Lenguaje dominante
Rust
Estrellas
22.4k
Forks
1.5k
Merge medio
16 h 33 min
PR fusionados (30 d)
165

Descripción

Summary

Right now my understanding is that freezing (such as with py_freeze) just takes a file or directory as input and naively freezes all .py files found, basically speaking. I suggest that freezing follow static imports to automatically find and freeze modules located on the user's machine.

Detailed Explanation

While building Kybra we have come across the very basic need to include all of our user's Python code into a final Wasm binary to deploy to our decentralized cloud environment (the Internet Computer). We currently freeze all of the user's modules at compile time, and we use py_freeze to achieve this. Unfortunately py_freeze just takes a file or directory as input. But we want to be able to freeze a user's entire Python application, which would include all imported modules, and the transitive imports of those imported modules.

We have experimented with our own module bundler based on modulegraph to achieve something like this. It is working rather well during our initial prototyping. But it would be even better to not have to build and maintain this tool outside of RustPython. It would also be nice for RustPython to include tree shaking and/or dead code elimination as discussed in this RFC.

Drawbacks, Rationale, and Alternatives

This type of module bundling would only work for static imports, so anything dynamically imported would have to be included in other ways. The alternative I've been using is to create my own bundler. To me it seems obvious that py_freeze would be able to freeze a module and all of its dependencies, without requiring them to all be in the same directory.

Unresolved Questions

If there's a better way to achieve this then that would be great, but I think the idea is pretty simple. When freezing follow the imports and freeze all transitive modules.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en el punto de entrada py_freeze y rastrea cómo descubre actualmente los archivos; después compara el recorrido propuesto de imports estáticos con el enfoque de modulegraph mencionado en el issue. Se considera terminado cuando el congelado sigue los imports transitivamente a través de módulos fuera del directorio inicial; los módulos importados dinámicamente quedan fuera de este alcance.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python, rust, wasm
Área
build-system, compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.