### Install and Build Emscripten CPython Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Installs the Emscripten SDK and builds CPython for Emscripten. Assumes NVM is installed and on PATH. The EMSDK_CACHE variable specifies the SDK location. ```sh export EMSDK_CACHE=$PWD/cross-build/emsdk python3 Platforms/emscripten install-emscripten python3 Platforms/emscripten build all ``` -------------------------------- ### Install Documentation Requirements Source: https://github.com/python/devguide/blob/main/documentation/start-documenting.rst Install the necessary Python packages for building documentation using pip. ```shell python -m pip install --upgrade -r requirements.txt ``` -------------------------------- ### Example build output for missing modules Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Example output indicating which optional modules could not be built due to missing dependencies. Consult configure.ac and config.log for details. ```none The necessary bits to build these optional modules were not found: _gdbm To find the necessary bits, look in configure.ac and config.log. Checked 106 modules (31 built-in, 74 shared, 0 n/a on macosx-13.4-arm64, 0 disabled, 1 missing, 0 failed on import) ``` -------------------------------- ### Verify coverage.py Installation Source: https://github.com/python/devguide/blob/main/testing/coverage.rst Run this command to verify your coverage.py installation. Substitute COVERAGEDIR with the path to your clone. ```shell ./python COVERAGEDIR ``` -------------------------------- ### Install Buildbot Worker (FreeBSD) Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Installs the buildbot-worker package on FreeBSD using pkg. ```bash pkg install devel/py-buildbot-worker ``` -------------------------------- ### Install coverage.py on Windows Source: https://github.com/python/devguide/blob/main/testing/coverage.rst Installs the coverage.py package using pip within a virtual environment on Windows. This involves using batch scripts for environment setup. ```dosbatch python.bat -m venv ..\cpython-venv ..\cpython-venv\Scripts\activate.bat pip install coverage ``` -------------------------------- ### Install Buildbot Worker (OpenBSD) Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Installs the buildbot-worker package on OpenBSD using pkg_add. ```bash pkg_add buildbot-worker ``` -------------------------------- ### Configure and Start Buildbot Worker Service (FreeBSD) Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Configures and starts the Buildbot worker service on FreeBSD using sysrc and the service command. ```bash sysrc buildbot_worker_enable=YES sysrc buildbot_worker_profiles="myworker" sysrc buildbot_worker_myworker_enable=YES sysrc buildbot_worker_myworker_basedir=/var/db/buildbot/workers/WORKERNAME service buildbot-worker start ``` -------------------------------- ### Install Buildbot Worker (Debian/Ubuntu) Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Installs the buildbot-worker package using apt. ```bash apt install buildbot-worker ``` -------------------------------- ### Clone the Devguide Repository Source: https://github.com/python/devguide/blob/main/documentation/devguide.rst Clone the devguide repository to your GitHub account to start making contributions. Ensure you have forked the repository first. ```shell git clone https://github.com//devguide ``` -------------------------------- ### Install coverage.py on macOS Source: https://github.com/python/devguide/blob/main/testing/coverage.rst Installs the coverage.py package using pip within a virtual environment on macOS. This is similar to the Unix installation. ```shell ./python.exe -m venv ../cpython-venv source ../cpython-venv/bin/activate pip install coverage ``` -------------------------------- ### Install macOS Developer Tools Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Installs the command-line developer tools on macOS, which includes necessary headers and compilers for building software. ```bash $ xcode-select --install ``` -------------------------------- ### Enable and Start Buildbot Worker Service (Linux) Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Commands to enable and start the Buildbot worker service using rcctl on Linux. This assumes a single worker setup. ```bash rcctl enable buildbot_worker rcctl start buildbot_worker ``` -------------------------------- ### Build Devguide Documentation (Windows) Source: https://github.com/python/devguide/blob/main/documentation/devguide.rst Build the HTML documentation for the Developer's Guide on Windows systems. The generated files will be located in the '_build/html' directory. ```dosbatch .\make html ``` -------------------------------- ### Configure Built-in Extension Module in Setup.bootstrap.in Source: https://github.com/python/devguide/blob/main/developer-workflow/extension-modules.rst Adds an extension module to be built as a built-in module. This line should be added after the '*static*' marker in the setup file. ```text *static* ... _foo _foo/_foomodule.c _foo/helper.c ... ``` -------------------------------- ### Install Buildbot Worker (pip) Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Installs the buildbot-worker package using pip. ```bash pip install buildbot-worker ``` -------------------------------- ### Example of availability directive Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Document the platforms on which a module or feature is available. ```rst .. availability:: Unix, not WASI, not Android. ``` ```rst .. availability:: Linux >= 3.0 with glibc >= 2.14. ``` -------------------------------- ### Install coverage.py on Unix Source: https://github.com/python/devguide/blob/main/testing/coverage.rst Installs the coverage.py package using pip within a virtual environment on Unix-like systems. Ensure you have a virtual environment activated. ```shell ./python -m venv ../cpython-venv source ../cpython-venv/bin/activate pip install coverage ``` -------------------------------- ### Example of PEP reference Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Reference a Python Enhancement Proposal. This generates an index entry and an HTML hyperlink. ```rst :pep:`8` ``` -------------------------------- ### Install Fedora/RHEL/CentOS Build Dependencies Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Installs essential build tools and dependencies for Python on Fedora, RHEL, and CentOS systems using dnf. ```bash $ sudo dnf install git pkg-config $ sudo dnf install dnf-plugins-core # install this to use 'dnf builddep' $ sudo dnf builddep python3 ``` ```bash $ sudo dnf install \ gcc gcc-c++ gdb lzma glibc-devel libstdc++-devel openssl-devel \ readline-devel zlib-devel libzstd-devel libffi-devel bzip2-devel \ xz-devel sqlite sqlite-devel sqlite-libs libuuid-devel gdbm-libs \ perf expat expat-devel mpdecimal python3-pip ``` -------------------------------- ### Manual Buildbot Worker Start Command Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst A command to start the Buildbot worker manually for initial testing if not using a service manager. Ensure to use the absolute path to the worker directory. ```bash buildbot-worker start /path/to/workerdir ``` -------------------------------- ### Get help for check_warnings.py script Source: https://github.com/python/devguide/blob/main/development-tools/warnings.rst Run this command to display the help message for the check_warnings.py script, showing available options and usage. ```bash python Tools/build/check_warnings.py --help ``` -------------------------------- ### Enable and Start Buildbot Worker Service (Debian/Ubuntu) Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Enables and starts the Buildbot worker service using systemd. Ensure WORKERNAME is replaced with your worker's name. ```bash systemctl enable --now buildbot-worker@WORKERNAME.service ``` -------------------------------- ### Footnote Example Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Illustrates how to create footnotes using '[#]_' for markers and defining the footnote body under a 'Footnotes' rubric. ```rst Lorem ipsum [#]_ dolor sit amet ... [#]_ .. rubric:: Footnotes .. [#] Text of the first footnote. .. [#] Text of the second footnote. ``` -------------------------------- ### Argument Clinic CLI Usage Example Source: https://github.com/python/devguide/blob/main/development-tools/clinic/index.rst Demonstrates how to use the Argument Clinic command-line interface to process a single C source file. ```shell-session python3 ./Tools/clinic/clinic.py foo.c ``` -------------------------------- ### Good Commit Message Example Source: https://github.com/python/devguide/blob/main/getting-started/git-boot-camp.rst Follow this format for clear and informative commit messages, especially for backporting changes. ```text gh-12345: Improve the spam module (GH-777) * Add method A to the spam module * Update the documentation of the spam module ``` -------------------------------- ### Example of _pickle.Pickler.dump Implementation with Argument Clinic Source: https://github.com/python/devguide/blob/main/development-tools/clinic/tutorial.rst An example of a C implementation for a Python method, generated with Argument Clinic. It includes a check for proper initialization and buffer clearing. Developers must ensure their implementation matches the generated signature and handles potential errors. ```c /*[clinic input] module _pickle class _pickle.Pickler "PicklerObject *" "&Pickler_Type" [clinic start generated code]*/ /*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ /*[clinic input] _pickle.Pickler.dump obj: 'O' The object to be pickled. / Write a pickled representation of obj to the open file. [clinic start generated code]*/ PyDoc_STRVAR(__pickle_Pickler_dump__doc__, "Write a pickled representation of obj to the open file.\n" "\n" ... static PyObject * _pickle_Pickler_dump_impl(PicklerObject *self, PyObject *obj) /*[clinic end generated code: checksum=3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/ { /* Check whether the Pickler was initialized correctly (issue3664). Developers often forget to call __init__() in their subclasses, which would trigger a segfault without this check. */ if (self->write == NULL) { PyErr_Format(PicklingError, "Pickler.__init__() was not called by %s.__init__()", Py_TYPE(self)->tp_name); return NULL; } if (_Pickler_ClearBuffer(self) < 0) { return NULL; } ... ``` -------------------------------- ### Example of note directive Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Highlight especially important information about an API that users should be aware of. ```rst .. note:: This function is not suitable for sending spam e-mails. ``` -------------------------------- ### Install Debian/Ubuntu Build Dependencies Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Installs build dependencies for Python on Debian/Ubuntu systems using apt. Includes essential build tools and libraries for optional modules. ```bash $ sudo apt-get update $ sudo apt-get build-dep python3 $ sudo apt-get install pkg-config ``` ```bash $ sudo apt-get install build-essential gdb lcov pkg-config \ libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \ libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \ lzma lzma-dev tk-dev uuid-dev zlib1g-dev libmpdec-dev libzstd-dev \ inetutils-inetd ``` -------------------------------- ### Commit Message Structure Example Source: https://github.com/python/devguide/blob/main/getting-started/pull-request-lifecycle.rst An example demonstrating the recommended structure for Git commit messages, including a concise imperative subject line and an optional detailed body. ```git Make the spam module more spammy The spam module sporadically came up short on spam. This change raises the amount of spam in the module by making it more spammy. ``` -------------------------------- ### Example Test Sequence for Bisecting Failures Source: https://github.com/python/devguide/blob/main/testing/buildbots.rst This is an example of a trimmed test sequence that can be used with the '--fromfile' option to bisect ordering-dependent failures. Note that parallel testing ('-j') cannot be used when diagnosing these issues. ```none [ 1/500] test_colorsys [ 2/500] test_float [ 3/500] test.test_io.test_memoryio [ 6/500] test_zipimport ``` ```none [ 4/500] test_profile [ 5/500] test_picklebuffer [ 6/500] test_zipimport ``` -------------------------------- ### Enabling and Starting Buildbot Worker Service with Systemd Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Commands to reload systemd configuration and enable/start a specific Buildbot worker service instance. ```bash systemctl daemon-reload systemctl enable --now buildbot-worker@WORKERNAME.service ``` -------------------------------- ### Add Module to Setup.stdlib.in (Standard) Source: https://github.com/python/devguide/blob/main/developer-workflow/extension-modules.rst Add this line to Modules/Setup.stdlib.in after the *@MODULE_BUILDTYPE@* marker and before the *shared* marker to include a new extension module. ```text *@MODULE_BUILDTYPE@* ... @MODULE__FOO_TRUE@_foo _foo/_foomodule.c _foo/helper.c ... ``` -------------------------------- ### Run coverage.py as a Module Source: https://github.com/python/devguide/blob/main/testing/coverage.rst Alternative command to run coverage.py if it's installed. This assumes a built copy of Python, such as from venv. ```shell ./python -m coverage ``` -------------------------------- ### Example of menuselection markup Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use this markup to denote menu selections. Separate individual selections with '-->'. ```rst :menuselection:`Start --> Programs` ``` -------------------------------- ### Configure Python with Optimizations Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Use this command to configure Python for an optimized build, enabling Profile Guided Optimization (PGO) and Link Time Optimization (LTO). ```console $ ./configure --enable-optimizations --with-lto ``` -------------------------------- ### Render CPython Devguide to HTML Source: https://github.com/python/devguide/blob/main/README.rst Run this command to render the devguide documentation to HTML format in the \'_build/html\' directory. Ensure you are in the project's root directory. ```shell make html ``` -------------------------------- ### Argument Clinic Input Block Example Source: https://github.com/python/devguide/blob/main/development-tools/clinic/index.rst This shows the structure of an Argument Clinic input block, including the start line, input content, and end line. ```none /*[clinic input] [clinic start generated code]*/ ``` -------------------------------- ### Example of CVE link Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Link to a Common Vulnerabilities and Exposures entry. You can link to a specific section using '#anchor'. ```rst :cve:`CVE-2023-1234` ``` -------------------------------- ### Inline Markup Examples Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Illustrates standard reStructuredText inline markup for emphasis, strong emphasis, and code/literals. Ensure content does not start or end with whitespace and is separated from surrounding text by non-word characters. ```rst *text* ``` ```rst **text** ``` ```rst `text` ``` -------------------------------- ### Add Module to Setup.stdlib.in (Shared) Source: https://github.com/python/devguide/blob/main/developer-workflow/extension-modules.rst If the extension module should be built as a shared module, place this line after the *shared* marker in Modules/Setup.stdlib.in. ```text ... *shared* ... @MODULE__FOO_TRUE@_foo _foo/_foomodule.c _foo/helper.c ``` -------------------------------- ### Argument Clinic Full Block Example Source: https://github.com/python/devguide/blob/main/development-tools/clinic/index.rst This illustrates a complete Argument Clinic block, encompassing the input, generated output, and checksum line. ```none /*[clinic input] ... clinic input goes here ... [clinic start generated code]*/ ... clinic output goes here ... /*[clinic end generated code: ...]*/ ``` -------------------------------- ### Install pre-commit Git hook Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Installs pre-commit as a Git hook to automatically lint code on commit. Ensure pre-commit is installed in your environment. ```bash $ pre-commit install --allow-missing-config ``` -------------------------------- ### Render and View CPython Devguide HTML Source: https://github.com/python/devguide/blob/main/README.rst Execute this command to render the devguide to HTML and automatically open the result in your default web browser. This is useful for immediate review. ```shell make htmlview ``` -------------------------------- ### Build Documentation Translation with Make Source: https://github.com/python/devguide/blob/main/documentation/translations/translating.rst Builds the HTML format of a documentation translation using the 'make' command with specified language options. ```bash make SPHINXOPTS="-D language=pl" html ``` -------------------------------- ### Creating a See Also Section Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use the `seealso` directive to list references to related documentation or external resources. The content should be a reST definition list. ```rst .. seealso:: Module :mod:`zipfile` Documentation of the :mod:`zipfile` standard module. ``` -------------------------------- ### Maintain Live HTML View of CPython Devguide Source: https://github.com/python/devguide/blob/main/README.rst Use this command to render the devguide to HTML and maintain a live view that updates automatically as you save edits. This streamlines the documentation development process. ```shell make htmllive ``` -------------------------------- ### Install Homebrew Dependencies Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Installs dependencies managed by Homebrew using a Brewfile. This is typically used on macOS. ```bash $ brew bundle --file=Misc/Brewfile ``` -------------------------------- ### Documenting Command Line Options Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use `option` for Python command line options. Enclose option argument names in angle brackets. Example shows running a module as a script. ```rst .. option:: -m Run a module as a script. ``` -------------------------------- ### Install macOS Dependencies with MacPorts Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Installs necessary development dependencies for building Python on macOS using MacPorts. ```bash $ sudo port install pkgconfig openssl xz gdbm tk +quartz mpdecimal zstd ``` -------------------------------- ### Create and Switch to New Branch (Alternative) Source: https://github.com/python/devguide/blob/main/getting-started/git-boot-camp.rst This is an alternative two-step process to create a new branch from 'main' and then switch to it. ```bash # create a new branch from main git branch main # switch to the new branch git switch ``` -------------------------------- ### Install pomerge Tool Source: https://github.com/python/devguide/blob/main/documentation/translations/translating.rst Install the pomerge package using pip. This tool is used for merging translations between PO files. ```bash pip install pomerge ``` -------------------------------- ### Checkout and Apply Patch Source: https://github.com/python/devguide/blob/main/security/psrt.rst Use these commands to create a new branch and apply a security patch. ```bash git checkout -b branch-name git apply ./ghsa-abcd-efgh-ijkl.patch git push origin branch-name ``` -------------------------------- ### Argument Clinic: pickle.Pickler.dump Example Source: https://github.com/python/devguide/blob/main/development-tools/clinic/howto.rst This is an example of how pickle.Pickler.dump is defined using Argument Clinic converters. It shows the object parameter and its description. ```python /*[clinic input] pickle.Pickler.dump obj: object The object to be pickled. / Write a pickled representation of obj to the open file. [clinic start generated code]*/ ``` -------------------------------- ### Example warning ignore file format Source: https://github.com/python/devguide/blob/main/development-tools/warnings.rst Illustrates the format of platform-specific warning ignore files, including file paths, explicit warning counts, and wildcard usage for files and directories. ```text Modules/_ctypes/_ctypes_test_generated.c.h * Objects/longobject.c 46 Objects/methodobject.c 1 Objects/mimalloc/ * ``` -------------------------------- ### Install buildbot-worker on CentOS Stream 9/10 Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Install the buildbot-worker package on CentOS Stream 9 or 10, enabling the CRB and EPEL repositories. ```bash dnf config-manager --set-enabled crb dnf install epel-release epel-next-release dnf install buildbot-worker ``` -------------------------------- ### Install buildbot-worker on RHEL 9 Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Install the buildbot-worker package on RHEL 9, ensuring EPEL repository is enabled and the CodeReady Builder repository is configured. ```bash subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm dnf install buildbot-worker ``` -------------------------------- ### Install buildbot-worker on RHEL 8 Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Install the buildbot-worker package on RHEL 8, ensuring EPEL repository is enabled and the CodeReady Builder repository is configured. ```bash subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm dnf install buildbot-worker ``` -------------------------------- ### Build Documentation with Sphinx Directly Source: https://github.com/python/devguide/blob/main/documentation/start-documenting.rst Invoke Sphinx directly to build HTML documentation, passing builder, source directory, and output directory as arguments. ```shell python -m sphinx -b html . build/html ``` -------------------------------- ### Bad Backport Commit Message Example Source: https://github.com/python/devguide/blob/main/getting-started/git-boot-camp.rst This example shows an incorrect format for a backport commit message, including a custom title and unnecessary details. ```text gh-XXXXX: Custom title (GH-XXXXX) (#XXXXX) * Custom message ``` -------------------------------- ### Example NEWS Entry Source: https://github.com/python/devguide/blob/main/getting-started/pull-request-lifecycle.rst This is an example of a NEWS entry, which should be written in valid reStructuredText and adhere to an 80-character column width. It describes the user-visible effects of a change succinctly. ```rst Added a new feature to the `json` module that allows for more flexible parsing of JSON strings. This change improves the usability of the module for developers working with complex JSON data. ``` -------------------------------- ### Documenting Bytecode Instructions Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use `opcode` to describe a Python bytecode instruction. Link using the `:term:` role for 'bytecode'. ```rst .. describe:: opcode ``` -------------------------------- ### Example of Sanitizer Failure Output Source: https://github.com/python/devguide/blob/main/development-tools/clang.rst This is an example of the diagnostic output produced when a sanitizer detects an error during runtime. It includes the type of error, location, and a stack trace. ```none Objects/longobject.c:39:42: runtime error: index -1 out of bounds for type 'PyLongObject [262]' Objects/tupleobject.c:188:13: runtime error: member access within misaligned address 0x2b76be018078 for type 'PyGC_Head' (aka 'union _gc_head'), which requires 16 byte alignment 0x2b76be018078: note: pointer points here 00 00 00 00 40 53 5a b6 76 2b 00 00 60 52 5a b6 ... ^ ...make: *** [pybuilddir.txt] Error 1 ``` -------------------------------- ### Compile CPython Project with Make Source: https://github.com/python/devguide/blob/main/developer-workflow/extension-modules.rst Execute the standard make commands to regenerate configuration scripts, configure the build, and compile the entire CPython project, including new extension modules. ```shell make regen-configure ./configure make regen-all make regen-stdlib-module-names make ``` -------------------------------- ### Importing C extension with Python fallback Source: https://github.com/python/devguide/blob/main/developer-workflow/extension-modules.rst Demonstrates how to attempt importing a C extension function and fall back to a pure Python implementation if the import fails. This is a common pattern for accelerator modules. ```python try: # use the C implementation if possible from _foo import greet except ImportError: # fallback to the pure Python implementation def greet(): return "Hello World!" ``` -------------------------------- ### Install buildbot-worker on Fedora/RHEL/CentOS Source: https://github.com/python/devguide/blob/main/testing/new-buildbot-worker.rst Use the system's package manager to install the buildbot-worker package. This command is suitable for Fedora, RHEL 8, RHEL 9, and CentOS Stream. ```bash dnf install buildbot-worker ``` -------------------------------- ### Update MSVC Project Files for Extension Module Source: https://github.com/python/devguide/blob/main/developer-workflow/extension-modules.rst Modify PC/config.c to register the new extension module's entry point. Ensure the `_PyImport_Inittab` array includes the module name and its corresponding `PyInit_*` function. ```c ... // add the entry point prototype extern PyObject* PyInit__foo(void); ... // update the entry points table struct _inittab _PyImport_Inittab[] = { ... {"_foo", PyInit__foo}, ... {0, 0} }; ... ``` -------------------------------- ### Configure and Build Python for iOS Simulator (Python 3.13) Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst For Python 3.13, explicitly invoke configure and make for each platform. This example shows building for the ARM64 simulator. Ensure your PATH is minimal and specify paths to pre-compiled dependencies. ```shell $ export PATH="$(pwd)/iOS/Resources/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin" $ ./configure \ LIBLZMA_CFLAGS="-Ipath/to/xz/include" \ LIBLZMA_LIBS="-Lpath/to/xz/lib -llzma" \ BZIP2_CFLAGS="-Ipath/to/bzip2/include" \ BZIP2_LIBS="-Lpath/to/bzip2/lib -lbz2" \ LIBFFI_CFLAGS="-Ipath/to/libffi/include" \ LIBFFI_LIBS="-Lpath/to/libffi/lib -lffi" \ --with-openssl="path/to/openssl" \ --host=arm64-apple-ios-simulator \ --build=arm64-apple-darwin \ --with-build-python=path/to/python3.13 \ --enable-framework $ make -j4 all $ make install ``` -------------------------------- ### Configure Python with both ASan and UBSan Source: https://github.com/python/devguide/blob/main/development-tools/clang.rst Enable both the Address Sanitizer and Undefined Behavior Sanitizer during Python's configuration. ```bash ./configure --with-address-sanitizer --with-undefined-behavior-sanitizer --without-pymalloc ``` -------------------------------- ### Argument Clinic override signature example Source: https://github.com/python/devguide/blob/main/development-tools/clinic/howto.rst This example demonstrates how to use the @text_signature directive to override the default generated signature in the docstring. It's useful for complex signatures that Argument Clinic cannot automatically handle. ```c /*[clinic input] @text_signature "($self, /, **changes)" code.replace * co_argcount: int(c_default="self->co_argcount") = unchanged co_posonlyargcount: int(c_default="self->co_posonlyargcount") = unchanged # etc ... Return a copy of the code object with new values for the specified fields. [clinic start generated output]*/ ``` -------------------------------- ### Configure and build Python on Unix Source: https://github.com/python/devguide/blob/main/getting-started/quick-reference.rst Configure the build with debug symbols and build Python using parallel jobs. Adjust the number of jobs based on your system's processor count. ```shell ./configure --config-cache --with-pydebug && make -j $(nproc) ``` -------------------------------- ### Define Grammar Productions with productionlist Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use the 'productionlist' directive to define grammar productions. Each production is on a single line, starting with a name and a colon. Continuation lines must also start with a colon at the same column. ```rst .. productionlist:: try_stmt: try1_stmt | try2_stmt try1_stmt: "try" ":" `suite` : ("except" [`expression` ["," `target`]] ":" `suite`)+ : ["else" ":" `suite`] : ["finally" ":" `suite`] try2_stmt: "try" ":" `suite` : "finally" ":" `suite` ``` -------------------------------- ### Argument Clinic Python file preprocessing example Source: https://github.com/python/devguide/blob/main/development-tools/clinic/howto.rst This example shows how Argument Clinic can be used to preprocess Python files. Argument Clinic blocks embedded in Python files use Python comment syntax. ```python3 #/*[python input] #print("def foo(): pass") #[python start generated code]*/ def foo(): pass #/*[python checksum:...]*/ ``` -------------------------------- ### Translate Code Example Values Source: https://github.com/python/devguide/blob/main/documentation/translations/translating.rst When translating code examples, focus on translating string literals and comments. Do not translate keywords, variable names, function names, class names, argument names, or attribute names. ```python def cheeseshop(kind, *arguments, **keywords): print("-- Czy jest może", kind, "?") print("-- Przykro mi, nie mamy już sera", kind) for arg in arguments: print(arg) print("-" * 40) for kw in keywords: print(kw, ":", keywords[kw]) ``` -------------------------------- ### Build CPython for WASI (Python 3.15+) Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Use this command to configure and build both the build Python and the WASI build in a single step. Requires Python 3.11 or newer. ```shell python Platforms/WASI build --quiet -- --config-cache --with-pydebug ``` -------------------------------- ### Documenting Environment Variables Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use `envvar` to describe environment variables. ```rst .. describe:: envvar ``` -------------------------------- ### Run CPython Dev Container with Podman Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Launches a CPython development container using Podman, mounting the current directory as a workspace and setting the working directory. Assumes a Unix-like environment with Podman installed. ```bash podman run -it --rm --volume $PWD:/workspace:Z --workdir /workspace ghcr.io/python/devcontainer:latest ``` -------------------------------- ### Verify Python Version Source: https://github.com/python/devguide/blob/main/documentation/start-documenting.rst Check if your installed Python version meets the minimum requirement of 3.11. ```shell python --version ``` -------------------------------- ### Build Documentation Translation with Sphinx Source: https://github.com/python/devguide/blob/main/documentation/translations/translating.rst Builds the HTML format of a documentation translation directly using the Sphinx command-line interface with specified language options. ```bash python -m sphinx -b html . build/html -D language=ro ``` -------------------------------- ### Example of regexp markup Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use this markup for regular expressions. Do not include quotes within the markup. ```rst :regexp:`[a-z]+` ``` -------------------------------- ### Clinic Input Boilerplate Source: https://github.com/python/devguide/blob/main/development-tools/clinic/tutorial.rst This boilerplate is required to start the Argument Clinic input block for a function. ```c /*[clinic input] [clinic start generated code]*/ ``` -------------------------------- ### Example of cross-referencing with link text Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Reference any label, not just section titles, by providing custom link text. ```rst :ref:`link text ` ``` -------------------------------- ### Documenting Classes Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Use `class` to describe a class. The signature can include constructor arguments in parentheses. ```rst .. describe:: class ``` -------------------------------- ### Example of cross-referencing a section Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Reference arbitrary sections in the documentation using the ':ref:' role with a label name. ```rst .. _my-reference-label: Section to cross-reference -------------------------- This is the text of the section. It refers to the section itself, see :ref:`my-reference-label`. ``` -------------------------------- ### Example of RFC reference Source: https://github.com/python/devguide/blob/main/documentation/markup.rst Reference an Internet Request for Comments. This generates an index entry and an HTML hyperlink. ```rst :rfc:`2822` ``` -------------------------------- ### Run Built CPython Dev Container with Podman Source: https://github.com/python/devguide/blob/main/getting-started/setup-building.rst Launches a CPython development container using Podman after it has been built locally. Mounts the current directory as a workspace and sets the working directory. ```shell podman run -it --rm --volume $PWD:/workspace:Z --workdir /workspace cpython-dev bash ``` -------------------------------- ### List Remote Repositories Source: https://github.com/python/devguide/blob/main/getting-started/git-boot-camp.rst View configured remote repositories and their URLs. This helps verify that 'origin' points to your fork and 'upstream' points to the official repository. ```bash git remote -v ```