Skip to content

Commit

Permalink
Fix removed importlib.resources.read_binary in Python 3.13 (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Dec 19, 2023
1 parent 6d4cf83 commit b23f89b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
os: [Windows, Ubuntu, MacOS]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
include:
# Only run PyPy jobs, on Ubuntu.
- os: Ubuntu
Expand All @@ -30,9 +30,10 @@ jobs:
- uses: actions/checkout@v3

# Get Python to test against
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

# Setup pip's cache
- name: Save date (for cache)
Expand Down
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def lint(session):
session.run("pre-commit", "run", "--all-files", *args)


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3"])
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3"])
def test(session):
session.install(".")
session.install("-r", "tests/requirements.txt")
Expand All @@ -42,7 +42,7 @@ def test(session):
)


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3"])
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3"])
def doctest(session):
session.install(".")
session.install("-r", "docs/requirements.txt")
Expand Down
14 changes: 12 additions & 2 deletions src/installer/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
import io
import os
import shlex
import sys
import zipfile
from importlib.resources import read_binary
from typing import TYPE_CHECKING, Mapping, Optional, Tuple
from types import ModuleType
from typing import TYPE_CHECKING, Mapping, Optional, Tuple, Union

if sys.version_info >= (3, 9): # pragma: no cover
from importlib.resources import files

def read_binary(package: Union[str, ModuleType], file_path: str) -> bytes:
return (files(package) / file_path).read_bytes()

else: # pragma: no cover
from importlib.resources import read_binary

from installer import _scripts

Expand Down

0 comments on commit b23f89b

Please sign in to comment.