Skip to content

Commit 438bdc8

Browse files
committed
Replace use of distulils.util.strtobool
This module has been deprecated since python 3.9 and removed in 3.12.
1 parent ddcdb8a commit 438bdc8

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
@@ -3,7 +3,6 @@
33
import os
44
import os.path
55
import tarfile
6-
from distutils.util import strtobool
76
from gettext import gettext as _
87
from glob import glob
98
from pathlib import Path
@@ -43,6 +42,21 @@ def __init__(self):
4342
super().__init__(_("Cannot export artifacts that haven't been downloaded."))
4443

4544

45+
def _ensure_bool(value):
46+
if isinstance(value, bool):
47+
return value
48+
if isinstance(value, str):
49+
if value.tolower() in ["yes", "y", "true", "t", "on", "1"]:
50+
return True
51+
if value.tolower() in ["no", "n", "false", "f", "off", "0"]:
52+
return False
53+
if value == 1:
54+
return True
55+
if value == 0:
56+
return False
57+
raise ValueError("Value {value:r} does not describe a boolean.")
58+
59+
4660
def _validate_fs_export(content_artifacts):
4761
"""
4862
Args:
@@ -346,9 +360,7 @@ def _version_match(curr_versions, prev_versions):
346360
def _incremental_requested(the_export):
347361
"""Figure out that a) an incremental is requested, and b) it's possible."""
348362
the_exporter = the_export.exporter
349-
full = the_export.params.get("full", True)
350-
if isinstance(full, str):
351-
full = bool(strtobool(full))
363+
full = _ensure_bool(the_export.params.get("full", True))
352364
starting_versions_provided = len(the_export.params.get("start_versions", [])) > 0
353365
last_exists = the_exporter.last_export
354366
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
@@ -290,3 +290,7 @@ extend-select = [
290290
# This section is managed by the plugin template. Do not edit manually.
291291
sections = { second-party = ["pulpcore"] }
292292
section-order = ["future", "standard-library", "third-party", "second-party", "first-party", "local-folder"]
293+
294+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
295+
# TODO Add this to the plugin template
296+
"distutils".msg = "The 'distutils' module has been deprecated since Python 3.9."

0 commit comments

Comments
 (0)