Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up support for Python 3.12 #1290

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1290.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The test suite is now compatible with Python 3.12.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ no-cover-if-is-macos = "'darwin' == os_environ.get('COVERAGE_PLATFORM', sys_plat
no-cover-if-not-macos = "'darwin' != os_environ.get('COVERAGE_PLATFORM', sys_platform) and os_environ.get('COVERAGE_EXCLUDE_PLATFORM') != 'disable'"
no-cover-if-is-windows = "'win32' == os_environ.get('COVERAGE_PLATFORM', sys_platform) and os_environ.get('COVERAGE_EXCLUDE_PLATFORM') != 'disable'"
no-cover-if-not-windows = "'win32' != os_environ.get('COVERAGE_PLATFORM', sys_platform) and os_environ.get('COVERAGE_EXCLUDE_PLATFORM') != 'disable'"
no-cover-if-is-py312 = "python_version == '3.12' and os_environ.get('COVERAGE_EXCLUDE_PYTHON_VERSION') != 'disable'"
no-cover-if-lt-py312 = "sys_version_info < (3, 12) and os_environ.get('COVERAGE_EXCLUDE_PYTHON_VERSION') != 'disable'"
no-cover-if-is-py310 = "python_version == '3.10' and os_environ.get('COVERAGE_EXCLUDE_PYTHON_VERSION') != 'disable'"
no-cover-if-lt-py310 = "sys_version_info < (3, 10) and os_environ.get('COVERAGE_EXCLUDE_PYTHON_VERSION') != 'disable'"
no-cover-if-gte-py310 = "sys_version_info > (3, 10) and os_environ.get('COVERAGE_EXCLUDE_PYTHON_VERSION') != 'disable'"
Expand All @@ -51,6 +53,8 @@ multi_line_output = 3
testpaths = ["tests"]
filterwarnings = [
"error",
# suppress until python-dateutil>2.8.2 is released (https://github.com/dateutil/dateutil/issues/1284)
"ignore:.*datetime.utcfromtimestamp\\(\\) is deprecated.*:DeprecationWarning:",
]

# need to ensure build directories aren't excluded from recursion
Expand Down
10 changes: 10 additions & 0 deletions src/briefcase/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,22 @@ def _unpack_support_package(self, support_file_path, support_path):
:param support_file_path: The path to the support file to be unpacked.
:param support_path: The path where support files should be unpacked.
"""
# Additional protections for unpacking tar files were introduced in Python 3.12.
# This enables the behavior that will be the default in Python 3.14.
# However, the protections can only be enabled for tar files...not zip files.
is_zip = support_file_path.name.endswith("zip")
if sys.version_info >= (3, 12) and not is_zip: # pragma: no-cover-if-lt-py312
tarfile_kwargs = {"filter": "data"}
else:
tarfile_kwargs = {}

try:
with self.input.wait_bar("Unpacking support package..."):
support_path.mkdir(parents=True, exist_ok=True)
self.tools.shutil.unpack_archive(
support_file_path,
extract_dir=support_path,
**tarfile_kwargs,
)
except (shutil.ReadError, EOFError) as e:
raise InvalidSupportPackage(support_file_path) from e
Expand Down
7 changes: 6 additions & 1 deletion src/briefcase/integrations/android_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shlex
import shutil
import subprocess
import sys
import time
from contextlib import suppress
from datetime import datetime
Expand Down Expand Up @@ -806,7 +807,11 @@ def verify_emulator_skin(self, skin: str):
# Unpack skin archive
with self.tools.input.wait_bar("Installing device skin..."):
try:
self.tools.shutil.unpack_archive(skin_tgz_path, extract_dir=skin_path)
self.tools.shutil.unpack_archive(
skin_tgz_path,
extract_dir=skin_path,
**({"filter": "data"} if sys.version_info >= (3, 12) else {}),
)
except (shutil.ReadError, EOFError) as err:
raise BriefcaseCommandError(
f"Unable to unpack {skin} device skin."
Expand Down
3 changes: 2 additions & 1 deletion src/briefcase/platforms/macOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ def notarize(self, filename, team_id):
finally:
# Clean up house; we don't need the archive anymore.
if archive_filename != filename:
self.tools.os.unlink(archive_filename)
# coverage exclusion required for https://github.com/python/cpython/issues/105658
self.tools.os.unlink(archive_filename) # no-cover-if-is-py312

try:
self.logger.info()
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/create/test_install_app_support_package.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import sys
from unittest import mock

import pytest
Expand Down Expand Up @@ -55,6 +56,7 @@ def test_install_app_support_package(
create_command.tools.shutil.unpack_archive.assert_called_with(
tmp_path / "data" / "support" / "Python-3.X-tester-support.b37.tar.gz",
extract_dir=support_path,
**({"filter": "data"} if sys.version_info >= (3, 12) else {}),
)

# Confirm that the full path to the support file
Expand Down Expand Up @@ -100,6 +102,7 @@ def test_install_pinned_app_support_package(
create_command.tools.shutil.unpack_archive.assert_called_with(
tmp_path / "data" / "support" / "Python-3.X-Tester-support.b42.tar.gz",
extract_dir=support_path,
**({"filter": "data"} if sys.version_info >= (3, 12) else {}),
)

# Confirm that the full path to the support file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from pathlib import Path
from unittest.mock import MagicMock

Expand Down Expand Up @@ -40,6 +41,7 @@ def test_new_skin(mock_tools, android_sdk):
mock_tools.shutil.unpack_archive.assert_called_once_with(
skin_tgz_path,
extract_dir=android_sdk.root_path / "skins" / "pixel_X",
**({"filter": "data"} if sys.version_info >= (3, 12) else {}),
)

# Original file was deleted.
Expand Down Expand Up @@ -102,6 +104,7 @@ def test_unpack_failure(mock_tools, android_sdk, tmp_path):
mock_tools.shutil.unpack_archive.assert_called_once_with(
skin_tgz_path,
extract_dir=android_sdk.root_path / "skins" / "pixel_X",
**({"filter": "data"} if sys.version_info >= (3, 12) else {}),
)

# Original file wasn't deleted.
Expand Down