aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-08-29 09:41:21 +0100
committerfanquake <fanquake@gmail.com>2023-08-29 09:42:31 +0100
commitab42b2ebdbf61225e636e4c00068fd29b2790d41 (patch)
treefad1c6f06147db1f5a5c3addf71743f5030f1bf7
parent5175ae482ebc88101d4fe572fb935ff1e9d8f40d (diff)
parent6c008a20067eb8574f4bd94acdd1d18ff7110d91 (diff)
downloadbitcoin-ab42b2ebdbf61225e636e4c00068fd29b2790d41.tar.xz
Merge bitcoin/bitcoin#28347: lint: replace deprecated pkg_resources with importlib.metadata
6c008a20067eb8574f4bd94acdd1d18ff7110d91 script: replace deprecated pkg_resources with importlib.metadata (Jon Atack) Pull request description: Running our python linter with a recent python and the latest release of setuptools [v68.1.2](https://setuptools.pypa.io/en/stable/history.html): ``` $ python3 --version Python 3.11.5 $ ./test/lint/lint-python.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html import pkg_resources ``` Using `pkg_resources` was [deprecated](https://github.com/pypa/setuptools/pull/3843) earlier in [v67.5.0](https://setuptools.pypa.io/en/stable/history.html#id55): "Although pkg_resources has been discouraged for use, some projects still consider pkg_resources viable for usage. This change makes it clear that pkg_resources should not be used, emitting a DeprecationWarning when imported." The `importlib.metadata` library requires Python 3.8, which is currently our minimum-supported Python version. For more details about `importlib.metadata` and the two methods imported and used here, see: - https://docs.python.org/3/library/importlib.metadata.html - https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.metadata - https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.PackageNotFoundError ACKs for top commit: MarcoFalke: lgtm ACK 6c008a20067eb8574f4bd94acdd1d18ff7110d91 (review only, did not test) Tree-SHA512: f5258d37043fcc9744f85641a60a3395ad43822c72d030dea8c39fa7f48ec3d7790cdeeb832f96e8f38046adb7c62fbc577c975ef0c77c8047c0c8f2353ce540
-rwxr-xr-xtest/lint/lint-python.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/test/lint/lint-python.py b/test/lint/lint-python.py
index 539d0acb5d..6010c787cb 100755
--- a/test/lint/lint-python.py
+++ b/test/lint/lint-python.py
@@ -9,10 +9,12 @@ Check for specified flake8 and mypy warnings in python files.
"""
import os
-import pkg_resources
import subprocess
import sys
+from importlib.metadata import metadata, PackageNotFoundError
+
+
DEPS = ['flake8', 'lief', 'mypy', 'pyzmq']
MYPY_CACHE_DIR = f"{os.getenv('BASE_ROOT_DIR', '')}/test/.mypy_cache"
@@ -99,10 +101,10 @@ ENABLED = (
def check_dependencies():
- working_set = {pkg.key for pkg in pkg_resources.working_set}
-
for dep in DEPS:
- if dep not in working_set:
+ try:
+ metadata(dep)
+ except PackageNotFoundError:
print(f"Skipping Python linting since {dep} is not installed.")
exit(0)