The Python programming language
Go to file
Miss Islington (bot) a6e61fd9d8
[3.13] Improve `pathname2url()` and `url2pathname()` docs (GH-127125) (#127232)
Improve `pathname2url()` and `url2pathname()` docs (GH-127125)

These functions have long sown confusion among Python developers. The
existing documentation says they deal with URL path components, but that
doesn't fit the evidence on Windows:

    >>> pathname2url(r'C:\foo')
    '///C:/foo'
    >>> pathname2url(r'\\server\share')
    '////server/share'  # or '//server/share' as of quite recently

If these were URL path components, they would imply complete URLs like
`file://///C:/foo` and `file://////server/share`. Clearly this isn't right.
Yet the implementation in `nturl2path` is deliberate, and the
`url2pathname()` function correctly inverts it.

On non-Windows platforms, the behaviour until quite recently is to simply
quote/unquote the path without adding or removing any leading slashes. This
behaviour is compatible with *both* interpretations -- 1) the value is a
URL path component (existing docs), and 2) the value is everything
following `file:` (this commit)

The conclusion I draw is that these functions operate on everything after
the `file:` prefix, which may include an authority section. This is the
only explanation that fits both the  Windows and non-Windows behaviour.
It's also a better match for the function names.
(cherry picked from commit 307c633586)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
2024-11-24 17:46:54 +00:00
.azure-pipelines [3.13] gh-122544: Change OS image in Azure pipeline to Ubuntu 24.04 (GH-125344) (#126479) 2024-11-06 10:24:55 +00:00
.devcontainer [3.13] GH-122578: update to WASI SDK 24 (GH-122960) (GH-122961) 2024-10-10 17:46:01 +00:00
.github [3.13] Enable aarch64 Ubuntu CI jobs (GH-125786) (GH-127170) 2024-11-23 10:40:25 +01:00
Android [3.13] gh-125940: Android: support 16 KB pages (GH-125941) (#125948) 2024-10-25 08:37:38 +08:00
Doc [3.13] Improve `pathname2url()` and `url2pathname()` docs (GH-127125) (#127232) 2024-11-24 17:46:54 +00:00
Grammar
Include [3.13] gh-126688: Reinit import lock after fork (GH-126692) (GH-126765) 2024-11-12 22:00:42 +00:00
InternalDocs [3.13] gh-122291: Intern latin-1 one-byte strings at startup (GH-122303) (GH-122347) 2024-07-27 08:51:02 +00:00
Lib [3.13] gh-109413: Enable mypy's `disallow_any_generics` setting when checking `libregrtest` (GH-127033) (#127034) 2024-11-24 08:40:14 +00:00
Mac [3.13] gh-124448: Update bundled Tcl/Tk in macOS installer to 8.6.15. (GH-125801) 2024-11-13 23:28:22 -05:00
Misc [3.13] Fix a few typos found in the docs (GH-127126) (GH-127181) 2024-11-23 00:09:35 +00:00
Modules [3.13] gh-109746: Make _thread.start_new_thread delete state of new thread on its startup failure (GH-109761) (GH-127171) 2024-11-22 19:55:44 +00:00
Objects [3.13] gh-127020: Make `PyCode_GetCode` thread-safe for free threading (GH-127043) (GH-127107) 2024-11-21 16:27:36 +00:00
PC [3.13] gh-126433: Fix compiler warnings on 32-bit Windows (#126444) (#126827) 2024-11-14 13:21:27 +01:00
PCbuild gh-126084: Fix venvwlauncher.exe to run pythonw.exe (GH-126088) 2024-10-29 20:20:05 +00:00
Parser [3.13] gh-126240: handle `NULL` returned by `_Py_asdl_expr_seq_new` (GH-126241) (#126243) 2024-10-31 14:57:11 +00:00
Programs [3.13] bpo-34206: Improve docs and test coverage for pre-init functions (GH-8023) (#125092) 2024-10-08 09:30:06 +00:00
Python [3.13] gh-109746: Make _thread.start_new_thread delete state of new thread on its startup failure (GH-109761) (GH-127171) 2024-11-22 19:55:44 +00:00
Tools gh-118973: Add _tkinter to freethreaded MSI (GH-126768) 2024-11-15 13:10:07 +00:00
iOS [3.13] gh-126167: Modify iOS Testbed to read arguments from Info.plist (GH-126169) (#126940) 2024-11-18 08:50:54 +08:00
.coveragerc
.editorconfig
.gitattributes [3.13] gh-121735: Fix module-adjacent references in zip files (GH-123037) (#123986) 2024-09-29 18:17:16 -07:00
.gitignore [3.13] Add the Python 3.13 abidump, and enable the ABI check. (#122583) 2024-08-02 13:18:49 +02:00
.mailmap
.pre-commit-config.yaml [3.13] Bump Ruff to 0.6.7 (#124384) (#124389) 2024-09-29 18:04:56 -07:00
.readthedocs.yml [3.13] gh-122544: Change OS image in readthedocs.yml to ubuntu-24.04 (GH-122568) (#122593) 2024-08-02 09:45:03 +03:00
LICENSE
Makefile.pre.in [3.13] gh-126413: Add translation tests for getopt and optparse (GH-126698) (GH-126755) 2024-11-15 13:06:54 +02:00
README.rst [3.13] Fix "useable" typo in docs (GH-127200) (#127207) 2024-11-23 17:50:06 -05:00
aclocal.m4 [3.13] gh-89640: harden float word ordering (#125571 and #126387) (#126429) 2024-11-05 23:18:55 +01:00
config.guess
config.sub
configure [3.13] GH-123877: make `wasm32-wasip1` the target triple for WASI (#126561) 2024-11-07 16:16:12 -08:00
configure.ac [3.13] GH-123877: make `wasm32-wasip1` the target triple for WASI (#126561) 2024-11-07 16:16:12 -08:00
install-sh
pyconfig.h.in [3.13] gh-89640: harden float word ordering (#125571 and #126387) (#126429) 2024-11-05 23:18:55 +01:00

README.rst

This is Python version 3.13.0
=============================

.. image:: https://github.com/python/cpython/workflows/Tests/badge.svg
   :alt: CPython build status on GitHub Actions
   :target: https://github.com/python/cpython/actions

.. image:: https://dev.azure.com/python/cpython/_apis/build/status/Azure%20Pipelines%20CI?branchName=main
   :alt: CPython build status on Azure DevOps
   :target: https://dev.azure.com/python/cpython/_build/latest?definitionId=4&branchName=main

.. image:: https://img.shields.io/badge/discourse-join_chat-brightgreen.svg
   :alt: Python Discourse chat
   :target: https://discuss.python.org/


Copyright © 2001-2024 Python Software Foundation.  All rights reserved.

See the end of this file for further copyright and license information.

.. contents::

General Information
-------------------

- Website: https://www.python.org
- Source code: https://github.com/python/cpython
- Issue tracker: https://github.com/python/cpython/issues
- Documentation: https://docs.python.org
- Developer's Guide: https://devguide.python.org/

Contributing to CPython
-----------------------

For more complete instructions on contributing to CPython development,
see the `Developer Guide`_.

.. _Developer Guide: https://devguide.python.org/

Using Python
------------

Installable Python kits, and information about using Python, are available at
`python.org`_.

.. _python.org: https://www.python.org/

Build Instructions
------------------

On Unix, Linux, BSD, macOS, and Cygwin::

    ./configure
    make
    make test
    sudo make install

This will install Python as ``python3``.

You can pass many options to the configure script; run ``./configure --help``
to find out more.  On macOS case-insensitive file systems and on Cygwin,
the executable is called ``python.exe``; elsewhere it's just ``python``.

Building a complete Python installation requires the use of various
additional third-party libraries, depending on your build platform and
configure options.  Not all standard library modules are buildable or
usable on all platforms.  Refer to the
`Install dependencies <https://devguide.python.org/getting-started/setup-building.html#build-dependencies>`_
section of the `Developer Guide`_ for current detailed information on
dependencies for various Linux distributions and macOS.

On macOS, there are additional configure and build options related
to macOS framework and universal builds.  Refer to `Mac/README.rst
<https://github.com/python/cpython/blob/main/Mac/README.rst>`_.

On Windows, see `PCbuild/readme.txt
<https://github.com/python/cpython/blob/main/PCbuild/readme.txt>`_.

To build Windows installer, see `Tools/msi/README.txt
<https://github.com/python/cpython/blob/main/Tools/msi/README.txt>`_.

If you wish, you can create a subdirectory and invoke configure from there.
For example::

    mkdir debug
    cd debug
    ../configure --with-pydebug
    make
    make test

(This will fail if you *also* built at the top-level directory.  You should do
a ``make clean`` at the top-level first.)

To get an optimized build of Python, ``configure --enable-optimizations``
before you run ``make``.  This sets the default make targets up to enable
Profile Guided Optimization (PGO) and may be used to auto-enable Link Time
Optimization (LTO) on some platforms.  For more details, see the sections
below.

Profile Guided Optimization
^^^^^^^^^^^^^^^^^^^^^^^^^^^

PGO takes advantage of recent versions of the GCC or Clang compilers.  If used,
either via ``configure --enable-optimizations`` or by manually running
``make profile-opt`` regardless of configure flags, the optimized build
process will perform the following steps:

The entire Python directory is cleaned of temporary files that may have
resulted from a previous compilation.

An instrumented version of the interpreter is built, using suitable compiler
flags for each flavor. Note that this is just an intermediary step.  The
binary resulting from this step is not good for real-life workloads as it has
profiling instructions embedded inside.

After the instrumented interpreter is built, the Makefile will run a training
workload.  This is necessary in order to profile the interpreter's execution.
Note also that any output, both stdout and stderr, that may appear at this step
is suppressed.

The final step is to build the actual interpreter, using the information
collected from the instrumented one.  The end result will be a Python binary
that is optimized; suitable for distribution or production installation.


Link Time Optimization
^^^^^^^^^^^^^^^^^^^^^^

Enabled via configure's ``--with-lto`` flag.  LTO takes advantage of the
ability of recent compiler toolchains to optimize across the otherwise
arbitrary ``.o`` file boundary when building final executables or shared
libraries for additional performance gains.


What's New
----------

We have a comprehensive overview of the changes in the `What's New in Python
3.13 <https://docs.python.org/3.13/whatsnew/3.13.html>`_ document.  For a more
detailed change log, read `Misc/NEWS
<https://github.com/python/cpython/tree/main/Misc/NEWS.d>`_, but a full
accounting of changes can only be gleaned from the `commit history
<https://github.com/python/cpython/commits/main>`_.

If you want to install multiple versions of Python, see the section below
entitled "Installing multiple versions".


Documentation
-------------

`Documentation for Python 3.13 <https://docs.python.org/3.13/>`_ is online,
updated daily.

It can also be downloaded in many formats for faster access.  The documentation
is downloadable in HTML, PDF, and reStructuredText formats; the latter version
is primarily for documentation authors, translators, and people with special
formatting requirements.

For information about building Python's documentation, refer to `Doc/README.rst
<https://github.com/python/cpython/blob/main/Doc/README.rst>`_.


Testing
-------

To test the interpreter, type ``make test`` in the top-level directory.  The
test set produces some output.  You can generally ignore the messages about
skipped tests due to optional features which can't be imported.  If a message
is printed about a failed test or a traceback or core dump is produced,
something is wrong.

By default, tests are prevented from overusing resources like disk space and
memory.  To enable these tests, run ``make buildbottest``.

If any tests fail, you can re-run the failing test(s) in verbose mode.  For
example, if ``test_os`` and ``test_gdb`` failed, you can run::

    make test TESTOPTS="-v test_os test_gdb"

If the failure persists and appears to be a problem with Python rather than
your environment, you can `file a bug report
<https://github.com/python/cpython/issues>`_ and include relevant output from
that command to show the issue.

See `Running & Writing Tests <https://devguide.python.org/testing/run-write-tests.html>`_
for more on running tests.

Installing multiple versions
----------------------------

On Unix and Mac systems if you intend to install multiple versions of Python
using the same installation prefix (``--prefix`` argument to the configure
script) you must take care that your primary python executable is not
overwritten by the installation of a different version.  All files and
directories installed using ``make altinstall`` contain the major and minor
version and can thus live side-by-side.  ``make install`` also creates
``${prefix}/bin/python3`` which refers to ``${prefix}/bin/python3.X``.  If you
intend to install multiple versions using the same prefix you must decide which
version (if any) is your "primary" version.  Install that version using
``make install``.  Install all other versions using ``make altinstall``.

For example, if you want to install Python 2.7, 3.6, and 3.13 with 3.13 being the
primary version, you would execute ``make install`` in your 3.13 build directory
and ``make altinstall`` in the others.


Release Schedule
----------------

See :pep:`719` for Python 3.13 release details.


Copyright and License Information
---------------------------------


Copyright © 2001-2024 Python Software Foundation.  All rights reserved.

Copyright © 2000 BeOpen.com.  All rights reserved.

Copyright © 1995-2001 Corporation for National Research Initiatives.  All
rights reserved.

Copyright © 1991-1995 Stichting Mathematisch Centrum.  All rights reserved.

See the `LICENSE <https://github.com/python/cpython/blob/main/LICENSE>`_ for
information on the history of this software, terms & conditions for usage, and a
DISCLAIMER OF ALL WARRANTIES.

This Python distribution contains *no* GNU General Public License (GPL) code,
so it may be used in proprietary projects.  There are interfaces to some GNU
code but these are entirely optional.

All trademarks referenced herein are property of their respective holders.