From a02167b870ae31fa4a6933efcb90f08a36c76d5e Mon Sep 17 00:00:00 2001 From: Maciej Nowak Date: Mon, 15 Jan 2024 10:48:32 +0100 Subject: [PATCH] fix: Python 3.12 compatibility --- .github/workflows/tests.yml | 2 +- src/qemu_runner/make_runner/make.py | 18 ++++++++++++++---- tests/test_venv.py | 17 ++--------------- tox.ini | 3 ++- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2744404..5861206 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v1 diff --git a/src/qemu_runner/make_runner/make.py b/src/qemu_runner/make_runner/make.py index d6d4f98..22646e6 100644 --- a/src/qemu_runner/make_runner/make.py +++ b/src/qemu_runner/make_runner/make.py @@ -6,7 +6,6 @@ import zipimport from pathlib import Path from typing import IO, List, Any -import pkg_resources from qemu_runner.layer_locator import load_layer import qemu_runner @@ -19,9 +18,20 @@ def load_layers_from_all_search_paths(layer_names: List[str]) -> List[str]: packages = ['qemu_runner'] - for ep in pkg_resources.iter_entry_points('qemu_runner_layer_packages'): - ep: pkg_resources.EntryPoint - packages.append(ep.module_name) + try: + import pkg_resources + for ep in pkg_resources.iter_entry_points('qemu_runner_layer_packages'): + ep: pkg_resources.EntryPoint + packages.append(ep.module_name) + + return [load_layer(layer, packages=packages) for layer in layer_names] + except ImportError: + import importlib.metadata + + eps = importlib.metadata.entry_points(group='qemu_runner_layer_packages') + + for ep in eps: + packages.append(ep.module_name) return [load_layer(layer, packages=packages) for layer in layer_names] diff --git a/tests/test_venv.py b/tests/test_venv.py index b156a8d..f2e01b3 100644 --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -28,20 +28,7 @@ def install_script(builder: venv.EnvBuilder, context, name, url): def install_setuptools(builder: venv.EnvBuilder, context): - """ - Install setuptools in the virtual environment. - - :param context: The information for the virtual environment - creation request being processed. - """ - url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py' - install_script(builder, context, 'setuptools', url) - # clear up the setuptools archive which gets downloaded - pred = lambda o: o.startswith('setuptools-') and o.endswith('.tar.gz') - files = filter(pred, os.listdir(context.bin_path)) - for f in files: - f = os.path.join(context.bin_path, f) - os.unlink(f) + subprocess.run([context.env_exe, '-m', 'pip', 'install', 'setuptools'], check=True) @pytest.fixture() @@ -56,7 +43,7 @@ def create_venv(venv_dir: Path): ctx = builder.ensure_directories(venv_dir) # builder.create_configuration(ctx) # builder.setup_python(ctx) - # install_setuptools(builder, ctx) + install_setuptools(builder, ctx) return Path(ctx.env_exe) diff --git a/tox.ini b/tox.ini index 420db35..b76fbe8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 3.4.0 -envlist = py38,py39,py310,py311 +envlist = py38,py39,py310,py311,py312 [gh-actions] python = @@ -9,6 +9,7 @@ python = 3.9: py39 3.10: py310, mypy 3.11: py311, mypy + 3.12: py312, mypy [testenv] ;download = true