Skip to content

Commit 8fb6c5b

Browse files
committed
Replace use of distulils.util.strtobool
This module has been deprecated since python 3.9 and removed in 3.12. (cherry picked from commit 438bdc8)
1 parent a221af3 commit 8fb6c5b

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

CHANGES/7571.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace use of the deprecated distutils. The module has been removed in Python 3.12 .

pulpcore/app/tasks/export.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os.path
55
import subprocess
66
import tarfile
7-
from distutils.util import strtobool
87
from gettext import gettext as _
98
from glob import glob
109
from pathlib import Path
@@ -44,6 +43,21 @@ def __init__(self):
4443
super().__init__(_("Cannot export artifacts that haven't been downloaded."))
4544

4645

46+
def _ensure_bool(value):
47+
if isinstance(value, bool):
48+
return value
49+
if isinstance(value, str):
50+
if value.tolower() in ["yes", "y", "true", "t", "on", "1"]:
51+
return True
52+
if value.tolower() in ["no", "n", "false", "f", "off", "0"]:
53+
return False
54+
if value == 1:
55+
return True
56+
if value == 0:
57+
return False
58+
raise ValueError("Value {value:r} does not describe a boolean.")
59+
60+
4761
def _validate_fs_export(content_artifacts):
4862
"""
4963
Args:
@@ -347,9 +361,7 @@ def _version_match(curr_versions, prev_versions):
347361
def _incremental_requested(the_export):
348362
"""Figure out that a) an incremental is requested, and b) it's possible."""
349363
the_exporter = the_export.exporter
350-
full = the_export.params.get("full", True)
351-
if isinstance(full, str):
352-
full = bool(strtobool(full))
364+
full = _ensure_bool(the_export.params.get("full", True))
353365
starting_versions_provided = len(the_export.params.get("start_versions", [])) > 0
354366
last_exists = the_exporter.last_export
355367
return (starting_versions_provided or last_exists) and not full

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,7 @@ extend-select = [
185185
# This section is managed by the plugin template. Do not edit manually.
186186
sections = { second-party = ["pulpcore"] }
187187
section-order = ["future", "standard-library", "third-party", "second-party", "first-party", "local-folder"]
188+
189+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
190+
# TODO Add this to the plugin template
191+
"distutils".msg = "The 'distutils' module has been deprecated since Python 3.9."

0 commit comments

Comments
 (0)