From 16a22f67b993f0bb392877f76934bdc3ba463e2c Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 29 Jan 2024 14:40:39 -0500 Subject: [PATCH] globally replace pkg_resources.parse_version with non-aliased class For a long time now, pkg_resources has depended on a (possibly vendored) copy of the packaging module, and imports `Version` as `parse_version`. Use the original class directly. Add a direct dependency on packaging to make sure it's visibly required. pkg_resources is deprecated and the recommended replacement is to directly use packaging where relevant. The result is faster to load, and more guaranteed to work e.g. in environments where setuptools isn't installed by default. --- pifpaf/drivers/ceph.py | 14 +++++++------- setup.cfg | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pifpaf/drivers/ceph.py b/pifpaf/drivers/ceph.py index d082982..c275959 100644 --- a/pifpaf/drivers/ceph.py +++ b/pifpaf/drivers/ceph.py @@ -14,7 +14,7 @@ import os import uuid -import pkg_resources +import packaging from pifpaf import drivers @@ -51,9 +51,9 @@ def _setUp(self): _, version = self._exec(["ceph", "--version"], stdout=True) version = version.decode("ascii").split()[2] - version = pkg_resources.parse_version(version) + version = packaging.version.Version(version) - if version < pkg_resources.parse_version("12.0.0"): + if version < packaging.version.Version("12.0.0"): extra = """ mon_osd_nearfull_ratio = 1 mon_osd_full_ratio = 1 @@ -66,7 +66,7 @@ def _setUp(self): """ # Enable msgrv2 protocol if Nautilus or later. - if version >= pkg_resources.parse_version("14.0.0"): + if version >= packaging.version.Version("14.0.0"): msgrv2_extra = """ mon_host = v2:127.0.0.1:%(port)d/0 """ % dict(port=self.port) @@ -156,7 +156,7 @@ def _setUp(self): wait_for_line=r"mon.a@0\(leader\).mds e1 print_map") # Start manager - if version >= pkg_resources.parse_version("12.0.0"): + if version >= packaging.version.Version("12.0.0"): self._exec( mgr_opts, wait_for_line="(mgr send_beacon active|waiting for OSDs)") @@ -166,13 +166,13 @@ def _setUp(self): self._exec(ceph_opts + ["osd", "crush", "add", "osd.0", "1", "root=default"]) self._exec(osd_opts + ["--mkfs", "--mkjournal"]) - if version < pkg_resources.parse_version("0.94.0"): + if version < packaging.version.Version("0.94.0"): wait_for_line = "journal close" else: wait_for_line = "done with init" osd, _ = self._exec(osd_opts, wait_for_line=wait_for_line) - if version >= pkg_resources.parse_version("12.0.0"): + if version >= packaging.version.Version("12.0.0"): self._exec(ceph_opts + ["osd", "set-full-ratio", "0.95"]) self._exec(ceph_opts + ["osd", "set-backfillfull-ratio", "0.95"]) self._exec(ceph_opts + ["osd", "set-nearfull-ratio", "0.95"]) diff --git a/setup.cfg b/setup.cfg index 0480538..907feeb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,7 @@ install_requires = click jinja2 fixtures + packaging psutil xattr ; sys_platform != 'win32'