Debian Codegraph @

subprojects/pythoncapi-compat/README.rst

raw
1 ++++++++++++++++++++++++++
2 Python C API compatibility
3 ++++++++++++++++++++++++++
4
5 .. image:: https://github.com/python/pythoncapi-compat/actions/workflows/build.yml/badge.svg
6 :alt: Build status of pythoncapi-compat on GitHub Actions
7 :target: https://github.com/python/pythoncapi-compat/actions
8
9 The ``pythoncapi-compat`` project can be used to write a C or C++ extension
10 supporting a wide range of Python versions with a single code base. It is made
11 of the ``pythoncapi_compat.h`` header file and the ``upgrade_pythoncapi.py``
12 script.
13
14 ``upgrade_pythoncapi.py`` requires Python 3.6 or newer.
15
16 See the `documentation at ReadTheDocs
17 <https://pythoncapi-compat.readthedocs.io/en/latest/>`_
18 for more details.
19
20 Getting started
21 ===============
22
23 To upgrade a specific file::
24
25 python3 upgrade_pythoncapi.py module.c
26
27 To upgrade all C/C++ files in a directory::
28
29 python3 upgrade_pythoncapi.py src/
30
31 Select operations
32 -----------------
33
34 To only replace ``op->ob_type`` with ``Py_TYPE(op)``, select the ``Py_TYPE``
35 operation with::
36
37 python3 upgrade_pythoncapi.py -o Py_TYPE module.c
38
39 Or the opposite, to apply all operations but leave ``op->ob_type`` unchanged,
40 deselect the ``Py_TYPE`` operation with::
41
42 python3 upgrade_pythoncapi.py -o all,-Py_TYPE module.c
43
44 Download pythoncapi_compat.h
45 ----------------------------
46
47 If you want to ``pythoncapi_compat.h`` to your code base, use the
48 ``upgrade_pythoncapi.py`` tool to fetch it::
49
50 python3 upgrade_pythoncapi.py --download PATH
51
52
53 This project is distributed under the `Zero Clause BSD (0BSD) license
54 <https://opensource.org/licenses/0BSD>`_ and is covered by the `PSF Code of
55 Conduct <https://www.python.org/psf/codeofconduct/>`_.