From a05e0457ccfc17f9340366e23fc210fb54ac86a7 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 10 Oct 2023 10:56:00 +0200 Subject: [PATCH 1/2] Use importlib.metadata instead of pkg_resources --- .github/workflows/main.yml | 2 +- jupyverse_api/jupyverse_api/cli.py | 10 ++++++++-- jupyverse_api/pyproject.toml | 1 + plugins/lab/fps_lab/routes.py | 12 +++++++++--- plugins/lab/pyproject.toml | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4f9f584d..93e36d1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-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: - name: Checkout diff --git a/jupyverse_api/jupyverse_api/cli.py b/jupyverse_api/jupyverse_api/cli.py index 3a10f5cc..410241b0 100644 --- a/jupyverse_api/jupyverse_api/cli.py +++ b/jupyverse_api/jupyverse_api/cli.py @@ -1,6 +1,11 @@ -import pkg_resources +import sys from typing import List, Tuple +if sys.version_info >= (3, 10): + from importlib.metadata import entry_points +else: + from importlib_metadata import entry_points + import rich_click as click from asphalt.core.cli import run @@ -70,9 +75,10 @@ def main( def get_config(disable: Tuple[str, ...]) -> str: + group = entry_points().select(group="jupyverse.components") jupyverse_components = [ ep.name - for ep in pkg_resources.iter_entry_points(group="jupyverse.components") + for ep in group if ep.name not in disable ] diff --git a/jupyverse_api/pyproject.toml b/jupyverse_api/pyproject.toml index bb4d0e43..d0101033 100644 --- a/jupyverse_api/pyproject.toml +++ b/jupyverse_api/pyproject.toml @@ -29,6 +29,7 @@ dependencies = [ "rich-click >=1.6.1,<2", "asphalt >=4.11.0,<5", "asphalt-web[fastapi] >=1.1.0,<2", + "importlib_metadata >= 4.4; python_version < '3.10'", ] dynamic = ["version"] diff --git a/plugins/lab/fps_lab/routes.py b/plugins/lab/fps_lab/routes.py index 00aefc8d..737ac128 100644 --- a/plugins/lab/fps_lab/routes.py +++ b/plugins/lab/fps_lab/routes.py @@ -1,13 +1,17 @@ import json import logging import os +import sys from glob import glob from http import HTTPStatus from pathlib import Path from typing import List, Optional, Tuple import json5 # type: ignore -import pkg_resources +if sys.version_info >= (3, 10): + from importlib.metadata import entry_points +else: + from importlib_metadata import entry_points from babel import Locale from fastapi import Response, status from fastapi.responses import FileResponse, RedirectResponse @@ -80,7 +84,8 @@ async def get_translations(self, user: User): "nativeName": native_name, } } - for ep in pkg_resources.iter_entry_points(group="jupyterlab.languagepack"): + group = entry_points().select(group="jupyterlab.languagepack") + for ep in group: locale = Locale.parse(ep.name) data[ep.name] = { "displayName": display_name, @@ -97,7 +102,8 @@ async def get_translation( self.locale = language return {} - for ep in pkg_resources.iter_entry_points(group="jupyterlab.languagepack"): + group = entry_points().select(group="jupyterlab.languagepack") + for ep in group: if ep.name == language: break else: diff --git a/plugins/lab/pyproject.toml b/plugins/lab/pyproject.toml index a68240be..2d447b26 100644 --- a/plugins/lab/pyproject.toml +++ b/plugins/lab/pyproject.toml @@ -11,6 +11,7 @@ dependencies = [ "babel", "json5", "jupyverse-api >=0.1.2,<1", + "importlib_metadata >= 4.4; python_version < '3.10'", ] dynamic = [ "version",] [[project.authors]] From 152100653ae96dc1d948e1fcce072dbf9e18bc77 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 08:58:59 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jupyverse_api/jupyverse_api/cli.py | 6 +----- plugins/lab/fps_lab/routes.py | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/jupyverse_api/jupyverse_api/cli.py b/jupyverse_api/jupyverse_api/cli.py index 410241b0..b2246f5b 100644 --- a/jupyverse_api/jupyverse_api/cli.py +++ b/jupyverse_api/jupyverse_api/cli.py @@ -76,11 +76,7 @@ def main( def get_config(disable: Tuple[str, ...]) -> str: group = entry_points().select(group="jupyverse.components") - jupyverse_components = [ - ep.name - for ep in group - if ep.name not in disable - ] + jupyverse_components = [ep.name for ep in group if ep.name not in disable] config = ["component:\n type: jupyverse\n components:\n"] for component in jupyverse_components: diff --git a/plugins/lab/fps_lab/routes.py b/plugins/lab/fps_lab/routes.py index 737ac128..46656df3 100644 --- a/plugins/lab/fps_lab/routes.py +++ b/plugins/lab/fps_lab/routes.py @@ -8,6 +8,7 @@ from typing import List, Optional, Tuple import json5 # type: ignore + if sys.version_info >= (3, 10): from importlib.metadata import entry_points else: