-
-
Notifications
You must be signed in to change notification settings - Fork 640
Open
Labels
Good first issueA good first issue for people looking to contributeA good first issue for people looking to contribute
Description
Right now, py_binary has an implicit output ({name}.zip}) and output group (python_zip_file) that builds a zip file of the py_binary. This zip file is a "zipapp", basically a zip file with a top-level __main__.py file. See https://peps.python.org/pep-0441/ and https://docs.python.org/3/library/zipapp.html for details.
If the Bazel builtin flag --build_python_zip is set, then the zip output changes slightly: it is turned into a self-executable zip file by prepending some shell code to the zip file.
Having this part of py_binary itself is problematic for four main reasons:
- It makes maintaining py_binary harder. The logic for creating the zip is subtle and introduces several branches on code that is otherwise straight forward.
- A zipapp is just one of many ways to create a "distributable" py_binary. It doesn't make sense to bake one directly into py_binary.
- A zipapp only works if it's pure-python code. If there are C library dependencies, then the zip must be extracted, which then breaks the logic for handling zipapp-based startup.
- A zip file doesn't have native support for symlinks. This makes it incompatible with bootstrap=script and how it creates a venv with symlinks to the desired python interpreter. Working around this requires hacks being applied at runtime with their own problems.
What to do:
- Create a
py_zipapprule. As input, they take apy_binaryorpy_test. As output, they produce a zipapp zip file. - Create a
py_zipapp_binaryandpy_zipapp_testrule. As input, they take apy_zipapptarget. As output, they produce a self-executable zip file. - As part of the above: create a tool to generate zip files that contain symlinks. Use
File.is_symlinkto detect if inputs should be symlinks or not. For a python-based implementation, how to create a symlink: https://stackoverflow.com/questions/35782941/archiving-symlinks-with-python-zipfile . It doesn't necessairily have to be implemented in Python. Another language is fine, however, if it's a compiled language, then we'll need to update rules_python handle building and consuming prebuilt artifacts.
I'll note that there are rule sets, e.g. rules_pkg that support somewhat arbitrary creation of zip files. Using one of those would also be fine.
groodt, arrdem, mering and phstgroodtJeroenSchmidt
Metadata
Metadata
Assignees
Labels
Good first issueA good first issue for people looking to contributeA good first issue for people looking to contribute