Skip to content

Commit

Permalink
Add support for buildPython version 3.13 (closes #1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Oct 1, 2024
1 parent 8fa0393 commit f016b23
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ runs:
3.10
3.11
3.12
3.13
allow-prereleases: true

- name: Set default Python command
id: python-default
Expand Down
7 changes: 5 additions & 2 deletions product/gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ After stable release:
use it.
* Run `gradle:testPython`.
* Update the list of Python versions in .github/actions/setup-python/action.yml.
* Build the demo app with the new version, and check for any warnings other than the
expected ones about .pyc compilation.
* Temporarily change the `buildPython` of the demo app, comment out `pyc.pip`, and check
it builds without any warnings other than the expected ones about .pyc compilation.
There's no point in running it now, as the failed compilation will break many of the
tests. We'll do this when we add runtime support for the same version (see
target/README.md).


## Removing support for a buildPython version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
The main purpose of this module is to expose LinkCollector.collect_links().
"""

import cgi
# Chaquopy: cgi was removed in Python 3.13 - replaced with EmailMessage.
from email.message import EmailMessage

import functools
import itertools
import logging
Expand Down Expand Up @@ -183,7 +185,11 @@ def _get_encoding_from_headers(headers):
"""Determine if we have any encoding information in our headers.
"""
if headers and "Content-Type" in headers:
content_type, params = cgi.parse_header(headers["Content-Type"])
# Chaquopy: cgi was removed in Python 3.13 - replaced with EmailMessage.
msg = EmailMessage()
msg["Content-Type"] = headers["Content-Type"]
params = msg["Content-Type"].params

if "charset" in params:
return params['charset']
return None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Download files with progress indicators.
"""
import cgi

# Chaquopy: cgi was removed in Python 3.13 - replaced with EmailMessage.
from email.message import EmailMessage

import logging
import mimetypes
import os
Expand Down Expand Up @@ -96,7 +99,11 @@ def parse_content_disposition(content_disposition, default_filename):
Parse the "filename" value from a Content-Disposition header, and
return the default filename if the result is empty.
"""
_type, params = cgi.parse_header(content_disposition)
# Chaquopy: cgi was removed in Python 3.13 - replaced with EmailMessage.
msg = EmailMessage()
msg["Content-Disposition"] = content_disposition
params = msg["Content-Disposition"].params

filename = params.get('filename')
if filename:
# We need to sanitize the filename to prevent directory traversal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def list_versions(mode):
# When updating these, consider also updating .github/actions/setup-python/action.yml.
OLD_BUILD_PYTHON_VERSION = "3.7"
MIN_BUILD_PYTHON_VERSION = "3.8"
MAX_BUILD_PYTHON_VERSION = "3.12"
MAX_BUILD_PYTHON_VERSION = "3.13"

EGG_INFO_SUFFIX = "py" + BUILD_PYTHON_VERSION + ".egg-info"
EGG_INFO_FILES = ["dependency_links.txt", "PKG-INFO", "SOURCES.txt", "top_level.txt"]
Expand Down
21 changes: 8 additions & 13 deletions target/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@ must be released under a different build number.

## Adding a Python version

Add it to Common.java.

Add it to build-all.sh.

In test_gradle_plugin.py, update the `PYTHON_VERSIONS` assertion.

Update the `MAGIC` lists in test_gradle_plugin.py and pyc.py.

Update documentation:
* "Python version" in android.rst
* "Python versions" in versions.rst

To allow running the unit tests, build any packages used by the demo app.
* First add buildPython support for the same version (see gradle-plugin/README.md).
* Add the version to Common.java.
* Add the version to build-all.sh.
* In test_gradle_plugin.py, update the `PYTHON_VERSIONS` assertion.
* Update the `MAGIC` lists in test_gradle_plugin.py and pyc.py.
* Update android.rst and versions.rst.
* Build any packages used by the demo app.
* Temporarily change the Python version of the demo app, and run all tests.

When building the other packages:

Expand Down

0 comments on commit f016b23

Please sign in to comment.