|
| 1 | +PEP: 775 |
| 2 | +Title: Make zlib required to build CPython |
| 3 | +Author: Gregory P. Smith < [email protected]>, |
| 4 | + |
| 5 | + |
| 6 | +Discussions-To: https://discuss.python.org/t/23062 |
| 7 | +Status: Draft |
| 8 | +Type: Standards Track |
| 9 | +Created: 24-Feb-2025 |
| 10 | +Python-Version: 3.14 |
| 11 | +Post-History: `23-Jan-2023 <https://discuss.python.org/t/23062>`__ |
| 12 | + |
| 13 | + |
| 14 | +Abstract |
| 15 | +======== |
| 16 | + |
| 17 | +Building CPython without the `zlib <https://zlib.net>`_ compression library |
| 18 | +will no be longer supported, and the :mod:`zlib` module will be required in |
| 19 | +the standard library. |
| 20 | +The only exception is `WASI <https://wasi.dev>`_, as zlib is not currently |
| 21 | +supported in CPython on WASI. |
| 22 | +Building the interpreter without zlib may still be possible, |
| 23 | +but formally unsupported. |
| 24 | + |
| 25 | + |
| 26 | +Motivation |
| 27 | +========== |
| 28 | + |
| 29 | +The zlib library, which powers the :mod:`!zlib` Python module, |
| 30 | +is available on all supported systems except WASI. |
| 31 | + |
| 32 | +Many wheels on PyPI, including the :pypi:`pip` installer, require zlib. |
| 33 | +Users of pip would consider CPython without zlib to be broken, |
| 34 | +but mostly don't notice because all major builds of CPython include zlib. |
| 35 | + |
| 36 | +CPython developers don't really notice either. It turns out that at the time |
| 37 | +of writing, at least one CPython test fails without zlib (the "skip" |
| 38 | +decorator in ``test_peg_generator.test_c_parser`` is applied too late), |
| 39 | +but our CI didn't catch this. |
| 40 | + |
| 41 | +This PEP treats this as an issue in documentation and messaging. |
| 42 | +In practice, we already don't support building CPython without zlib; we |
| 43 | +should just say so. |
| 44 | + |
| 45 | + |
| 46 | +Rationale |
| 47 | +========= |
| 48 | + |
| 49 | +There are possible use cases for zlib-less builds, such as embedding and |
| 50 | +bootstrapping, as well as unforeseen ones. |
| 51 | +Therefore, we don't *remove* support for zlib-less systems; we mark them |
| 52 | +unsupported and invite affected users to do their own testing, or to share |
| 53 | +use cases that can make us reconsider this decision. |
| 54 | + |
| 55 | +zlib is not yet used by default on the WASI platform -- mostly because |
| 56 | +adding it hasn't yet been a priority there. (Note that `Pyodide`_, the main |
| 57 | +"real-world" CPython distribution for WASI, does include zlib.) |
| 58 | +We take this as an opportunity to continue testing a platform without |
| 59 | +zlib, so that we don't unintentionally break unsupported builds yet. |
| 60 | + |
| 61 | +.. _Pyodide: https://pyodide.org |
| 62 | + |
| 63 | + |
| 64 | +Specification |
| 65 | +============= |
| 66 | + |
| 67 | +In standard library modules that use zlib for optional functionality, |
| 68 | +that functionality will raise ``ImportError`` when used. |
| 69 | +Code to generate more "friendly" error messages, or to pre-check whether |
| 70 | +zlib is available, will be removed. |
| 71 | +All functionality unrelated to zlib will still be usable if zlib is |
| 72 | +missing. |
| 73 | + |
| 74 | +This affects the following modules, and more that depend on these |
| 75 | +transitively: |
| 76 | + |
| 77 | +* :mod:`shutil` (``gztar`` and ``zip`` archive formats) |
| 78 | +* :mod:`tarfile`, :mod:`zipfile`, :mod:`zipimport`, |
| 79 | + :mod:`zipapp` (archive compression) |
| 80 | +* :mod:`codecs` (``zlib_codec``) |
| 81 | + |
| 82 | +``shutil.get_archive_formats()`` will always include ``zip`` and ``gztar`` |
| 83 | +as registered formats, even if they are unusable due to missing zlib. |
| 84 | + |
| 85 | +The ``configure`` script will issue a warning when zlib is not found on |
| 86 | +platforms other than WASI. |
| 87 | + |
| 88 | +``test_zlib`` will fail on platforms other than WASI. |
| 89 | +All other tests will continue to be skipped -- that is, uses of |
| 90 | +``@test.support.requires_zlib`` will be kept in place -- for the benefit |
| 91 | +of WASI, unsupported builds, and any possible reverts. |
| 92 | + |
| 93 | +:pep:`11` will be adjusted to mark "Systems without zlib, except WASI" as |
| 94 | +unsupported. |
| 95 | + |
| 96 | + |
| 97 | +Backwards Compatibility |
| 98 | +======================= |
| 99 | + |
| 100 | +In practice, nothing major changes, except in error cases -- for example, |
| 101 | +attempts to use tar compression without zlib available will raise |
| 102 | +``ImportError`` and not ``CompressionError``. |
| 103 | + |
| 104 | + |
| 105 | +Security Implications |
| 106 | +===================== |
| 107 | + |
| 108 | +None known. |
| 109 | + |
| 110 | + |
| 111 | +How to Teach This |
| 112 | +================= |
| 113 | + |
| 114 | +We don't expect that any instructions will need to change, as zlib is |
| 115 | +already available in all relevant contexts. |
| 116 | + |
| 117 | + |
| 118 | +Reference Implementation |
| 119 | +======================== |
| 120 | + |
| 121 | +A reference implementation may be found in a pull request to the CPython |
| 122 | +repository, `python/cpython#130297 |
| 123 | +<https://github.com/python/cpython/pull/130297>`_ |
| 124 | + |
| 125 | + |
| 126 | +Future work |
| 127 | +=========== |
| 128 | + |
| 129 | +In the future, if no use cases for zlib-less builds are found, |
| 130 | +zlib may be made fully required. |
| 131 | +The main changes needed for that would be making the ``configure`` script |
| 132 | +raise a hard error, and removing ``@test.support.requires_zlib``. |
| 133 | + |
| 134 | + |
| 135 | +Copyright |
| 136 | +========= |
| 137 | + |
| 138 | +This document is placed in the public domain or under the |
| 139 | +CC0-1.0-Universal license, whichever is more permissive. |
0 commit comments