pypa / pypa/packaging.python.org

Expand documentation on building for the Limited API

Offen
#1,376 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

component: guides type: enhancement
Vorherrschende Sprache
Python
Sterne
1.7k
Forks
1.7k
Ø Merge
3 T. 12 Std.
Gemergte PRs (30 T.)
4

Beschreibung

PyPUG has a small section on extension module API compatibility, which links to Python's nice Limited API documentation. The Python docs imply that the Limited API can be used simply by setting Py_LIMITED_API and auditing API calls in the code, but there are some packaging concerns as well. As far as I can tell, enabling the Limited API requires setting three separate knobs:

  1. Py_LIMITED_API, to hide non-stabilized symbols and potentially replace some macros with functions.
  2. The setuptools Extension(..., py_limited_api=True) flag, to use the correct filename for the extension module.
  3. The wheel py-limited-api option, to correctly ABI tag the wheel. See also: https://github.com/pypa/setuptools/issues/4741

These knobs are distributed across the ecosystem and there doesn't seem to be any unified documentation for them. This blog post was helpful for general understanding, but doesn't provide fully actionable advice. A concrete guide would really help.

In addition, perhaps the docs could mention how to conditionally disable the Limited API when building for older Python releases. Packages may want to continue shipping version-specific wheels for releases that haven't stabilized all of the C functions they need. I used setup.py code like this:

_abi3 = sys.version_info >= (3, 11)
setup(
    ext_modules=[
        Extension(
            'fizzbuzz', ['fizzbuzz.c'],
            define_macros=[('Py_LIMITED_API', '0x030b0000')] if _abi3 else [],
            py_limited_api=_abi3,
        ),
    ],
    options={'bdist_wheel': {'py_limited_api': 'cp311'} if _abi3 else {}},
)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit dem bestehenden Abschnitt zur PyPUG-ABI-Kompatibilität und der verlinkten Dokumentation zur Python Limited API. Sehen Sie sich anschließend die im Issue beschriebenen Belange von setuptools und wheel an. Als abgeschlossen gilt die Arbeit, wenn ein konkreter, einheitlicher Leitfaden vorliegt, der die drei Konfigurationsoptionen abdeckt und erklärt, wie die Limited API für ältere Python-Versionen bedingt deaktiviert werden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
build-system, documentation
Issue-Typ
Dokumentation
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.