Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Comment thread
StanFromIreland marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ peps/pep-0771.rst @pradyunsg
peps/pep-0772.rst @warsaw @pradyunsg
peps/pep-0773.rst @zooba
peps/pep-0774.rst @savannahostrowski
peps/pep-0775.rst @stanfromireland @encukou
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
# ...
peps/pep-0777.rst @warsaw
# ...
Expand Down
134 changes: 134 additions & 0 deletions peps/pep-0775.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
PEP: 775
Title: Make zlib required to build Python
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
Author: Stan Ulbrych <stanulbrych@gmail.com>,
Petr Viktorin <encukou@gmail.com>
Discussions-To: https://discuss.python.org/t/lets-make-zlib-required-rather-than-optional-to-build-cpython/23062
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
Status: Draft
Type: Standards Track
Comment thread
StanFromIreland marked this conversation as resolved.
Created: 20-Feb-2025
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
Python-Version: 3.14
Post-History: `23-Jan-2023 <https://discuss.python.org/t/23062>`__

Comment thread
StanFromIreland marked this conversation as resolved.
Abstract
========

Building CPython on systems without the ``zlib`` compression library, except WASI,
is no longer supported.

The ``zlib`` module is made a required part of the standard library,
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
except on WASI.

Builds without ``zlib`` will still be possible, but formally unsupported.
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated


Motivation
==========

The ``zlib`` library, which powers the ``zlib`` Python module,
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
is available on virtually all systems.

Many wheels on PyPI, including the `pip`_ installer, require ``zlib``.
Users of *pip* would consider CPython without ``zlib`` to be broken,
but mostly don't notice because all major builds of CPython include ``zlib``.

.. _pip: https://pypi.org/project/pip/
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated

CPython developers don't really notice either. It turns out that at the time
of this writing, at least one CPython test fails without ``zlib`` (the “skip”
decorator in ``test_peg_generator.test_c_parser`` is applied too late),
but our CI didn't catch this.
Comment thread
StanFromIreland marked this conversation as resolved.

This PEP treats this as an issue in documentation and messaging.
In practice, we already don't support building CPython without ``zlib``; we
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
should just say so.


Rationale
=========

There are possible use cases for zlib-less builds, such as embedding and
bootstrapping, as well as unforeseen ones.
Therefore, we don't *remove* support for zlib-less systems; we mark them
unsupported and invite affected users to do their own testing, or to share
use cases that can make us reconsider this decision.

``zlib`` is not yet used by default on the WASI platform -- mostly because
adding it hasn't yet been a priority there. (Note that `Pyodide`_, the main
“real-world” CPython distribution for WASI, does include ``zlib``.)
We take this as an opportunity to continue testing a platform without
``zlib``, so that we don't unintentionally break unsupported builds yet.
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated

Comment thread
StanFromIreland marked this conversation as resolved.

Specification
=============

In standard library modules that use ``zlib`` for optional functionality,
that functionality will raise ``ImportError`` when used.
Code to generate more “friendly” error messages, or to pre-check whether
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
``zlib`` is available, will be removed.
All non-``zlib``-related functionality will still be usable if ``zlib`` is
missing.
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated

This affects the following modules, and more that depend on these
transitively:

* ``shutil`` (``gztar`` and ``zip`` archive formats)
* ``tarfile``, ``zipfile``, ``zipimport``, ``zipapp`` (archive compression)
* ``codecs`` (``zlib_codec``)
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated

``shutil.get_archive_formats()`` will always include ``zip`` and ``gztar``
as registered formats, even if they are unusable due to missing ``zlib``.

The ``configure`` script will issue a warning when `zlib`_ is not found on
platforms other than WASI.

``test_zlib`` will fail on platforms other than WASI.
All other tests will continue to be skipped -- that is, uses of
``@test.support.requires_zlib`` will be kept in place -- for the benefit
of WASI, unsupported builds, and any possible reverts.

PEP 11 will be adjusted to mark "Systems without zlib, except WASI" as
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
unsupported.


Backwards Compatibility
=======================

In practice, nothing major changes, except in error cases -- for example,
attempts to use tar compression withoutt ``zlib`` available will raise
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
``ImportError`` and not ``CompressionError``.


Security Implications
=====================

None known.


How to Teach This
=================

We don't expect that any instructions will need to change, as ``zlib`` is
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
already available in all relevant contexts.


Reference Implementation
========================

https://github.com/python/cpython/pull/130297
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated


Future work
===========

In the future, if no use cases for ``zlib``-less builds are found,
``zlib`` may be made fully required.
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
The main changes needed for that would be making the ``configure`` script
raise a hard error, and removing ``@test.support.requires_zlib``.


Copyright
=========

This document is placed in the public domain or under the
CC0-1.0-Universal license, whichever is more permissive.