From a7ae27404f2ab7f04af6863cec8151801b323b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Sun, 17 Dec 2023 20:59:48 +0100 Subject: [PATCH 1/2] Replace pkg_resources.parse_version by packaging.version.Version --- elpy/blackutil.py | 4 +++- elpy/jedibackend.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/elpy/blackutil.py b/elpy/blackutil.py index e09ed417..cef08b2e 100644 --- a/elpy/blackutil.py +++ b/elpy/blackutil.py @@ -7,8 +7,10 @@ from elpy.rpc import Fault # in case pkg_resources is not properly installed # (see https://github.com/jorgenschaefer/elpy/issues/1674). +# in case pkg_resources is not properly installed +# (see https://github.com/jorgenschaefer/elpy/issues/1674). try: - from pkg_resources import parse_version + from packaging.version import Version as parse_version except ImportError: # pragma: no cover def parse_version(*arg, **kwargs): raise Fault("`pkg_resources` could not be imported, " diff --git a/elpy/jedibackend.py b/elpy/jedibackend.py index 96b75502..a4aa0c7e 100644 --- a/elpy/jedibackend.py +++ b/elpy/jedibackend.py @@ -18,7 +18,7 @@ # in case pkg_resources is not properly installed # (see https://github.com/jorgenschaefer/elpy/issues/1674). try: - from pkg_resources import parse_version + from packaging.version import Version as parse_version except ImportError: # pragma: no cover def parse_version(*arg, **kwargs): raise Fault("`pkg_resources` could not be imported, " From 6a6655e489a35fc979f269d180fc15f629dececd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Sun, 17 Dec 2023 23:05:32 +0100 Subject: [PATCH 2/2] Use pkg_resources as fallback for parse_version --- elpy/blackutil.py | 11 +++++++---- elpy/jedibackend.py | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/elpy/blackutil.py b/elpy/blackutil.py index cef08b2e..667d6e48 100644 --- a/elpy/blackutil.py +++ b/elpy/blackutil.py @@ -12,10 +12,13 @@ try: from packaging.version import Version as parse_version except ImportError: # pragma: no cover - def parse_version(*arg, **kwargs): - raise Fault("`pkg_resources` could not be imported, " - "please reinstall Elpy RPC virtualenv with" - " `M-x elpy-rpc-reinstall-virtualenv`", code=400) + try: + from pkg_resources import parse_version + except ImportError: # pragma: no cover + def parse_version(*arg, **kwargs): + raise Fault("`pkg_resources` could not be imported, " + "please reinstall Elpy RPC virtualenv with" + " `M-x elpy-rpc-reinstall-virtualenv`", code=400) import os diff --git a/elpy/jedibackend.py b/elpy/jedibackend.py index a4aa0c7e..fdc11737 100644 --- a/elpy/jedibackend.py +++ b/elpy/jedibackend.py @@ -20,10 +20,13 @@ try: from packaging.version import Version as parse_version except ImportError: # pragma: no cover - def parse_version(*arg, **kwargs): - raise Fault("`pkg_resources` could not be imported, " - "please reinstall Elpy RPC virtualenv with" - " `M-x elpy-rpc-reinstall-virtualenv`", code=400) + try: + from pkg_resources import parse_version + except ImportError: # pragma: no cover + def parse_version(*arg, **kwargs): + raise Fault("`pkg_resources` could not be imported, " + "please reinstall Elpy RPC virtualenv with" + " `M-x elpy-rpc-reinstall-virtualenv`", code=400) JEDISUP17 = parse_version(jedi.__version__) >= parse_version("0.17.0") JEDISUP18 = parse_version(jedi.__version__) >= parse_version("0.18.0")