Skip to content

Commit

Permalink
globally replace pkg_resources.parse_version with non-aliased class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eli-schwartz authored and felixonmars committed Feb 2, 2024
1 parent 2718481 commit 16a22f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pifpaf/drivers/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
import uuid

import pkg_resources
import packaging

from pifpaf import drivers

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)")
Expand All @@ -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"])
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ install_requires =
click
jinja2
fixtures
packaging
psutil
xattr ; sys_platform != 'win32'

Expand Down

0 comments on commit 16a22f6

Please sign in to comment.