This patch does the following: 1. Add the InvalidName class (otherwise, jupyterlab 4.5.7 crashes on Slackware 15.0) 2. Replace the canonicalize_name definition (I am using the code from packaging 26.2) --- a/jupyterlab/extensions/pypi.py +++ b/jupyterlab/extensions/pypi.py @@ -19,18 +19,19 @@ from pathlib import Path from subprocess import CalledProcessError, run from tarfile import TarFile -from typing import Any, Callable, Optional, Union +from typing import Any, Callable, NewType, Optional, Union from urllib.parse import urlparse from zipfile import ZipFile import httpx import tornado from async_lru import alru_cache -from packaging.utils import InvalidName, canonicalize_name from packaging.version import InvalidVersion, Version from packaging.version import parse as parse_version from traitlets import CFloat, CInt, Unicode, config, observe +NormalizedName = NewType("NormalizedName", str) + from jupyterlab._version import __version__ from jupyterlab.extensions.manager import ( ActionResult, @@ -40,6 +41,21 @@ ) +class InvalidName(ValueError): + """ + An invalid distribution name; users should refer to the packaging user guide. + """ + + +def canonicalize_name(name: str, *, validate: bool = False) -> NormalizedName: + if validate and not _validate_regex.fullmatch(name): + raise InvalidName(f"name is invalid: {name!r}") + value = name.lower().replace("_", "-").replace(".", "-") + while "--" in value: + value = value.replace("--", "-") + return cast("NormalizedName", value) + + class ProxiedTransport(xmlrpc.client.Transport): def set_proxy(self, host, port=None, headers=None): self.proxy = host, port