|
| 1 | +From b23f89b10cf5d179bd6b0bad195ee36f43a5fb9e Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= |
| 3 | + <16805946+edgarrmondragon@users.noreply.github.com> |
| 4 | +Date: Tue, 19 Dec 2023 06:09:41 -0600 |
| 5 | +Subject: [PATCH] Fix removed `importlib.resources.read_binary` in Python 3.13 |
| 6 | + (#201) |
| 7 | + |
| 8 | +diff --git a/noxfile.py b/noxfile.py |
| 9 | +index a690c59..6a69cce 100644 |
| 10 | +--- a/noxfile.py |
| 11 | ++++ b/noxfile.py |
| 12 | +@@ -22,7 +22,7 @@ def lint(session): |
| 13 | + session.run("pre-commit", "run", "--all-files", *args) |
| 14 | + |
| 15 | + |
| 16 | +-@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3"]) |
| 17 | ++@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3"]) |
| 18 | + def test(session): |
| 19 | + session.install(".") |
| 20 | + session.install("-r", "tests/requirements.txt") |
| 21 | +@@ -42,7 +42,7 @@ def test(session): |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | +-@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3"]) |
| 26 | ++@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3"]) |
| 27 | + def doctest(session): |
| 28 | + session.install(".") |
| 29 | + session.install("-r", "docs/requirements.txt") |
| 30 | +diff --git a/src/installer/scripts.py b/src/installer/scripts.py |
| 31 | +index d18060b..c9f96b4 100644 |
| 32 | +--- a/src/installer/scripts.py |
| 33 | ++++ b/src/installer/scripts.py |
| 34 | +@@ -3,9 +3,19 @@ |
| 35 | + import io |
| 36 | + import os |
| 37 | + import shlex |
| 38 | ++import sys |
| 39 | + import zipfile |
| 40 | +-from importlib.resources import read_binary |
| 41 | +-from typing import TYPE_CHECKING, Mapping, Optional, Tuple |
| 42 | ++from types import ModuleType |
| 43 | ++from typing import TYPE_CHECKING, Mapping, Optional, Tuple, Union |
| 44 | ++ |
| 45 | ++if sys.version_info >= (3, 9): # pragma: no cover |
| 46 | ++ from importlib.resources import files |
| 47 | ++ |
| 48 | ++ def read_binary(package: Union[str, ModuleType], file_path: str) -> bytes: |
| 49 | ++ return (files(package) / file_path).read_bytes() |
| 50 | ++ |
| 51 | ++else: # pragma: no cover |
| 52 | ++ from importlib.resources import read_binary |
| 53 | + |
| 54 | + from installer import _scripts |
| 55 | + |
0 commit comments