Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop usage of distutils
Browse files Browse the repository at this point in the history
Replace `distutils.util.strtobool` with a local copy
of the function following the
[Migration advice](https://peps.python.org/pep-0632/#migration-advice)
due to `distutils` module deprecation.

Signed-off-by: Sandro Bonazzola <[email protected]>
sandrobonazzola committed Sep 2, 2024
1 parent c068154 commit 84e3733
Showing 5 changed files with 48 additions and 10 deletions.
17 changes: 17 additions & 0 deletions MIT_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
5 changes: 2 additions & 3 deletions did/plugins/confluence.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@
higher priority.
"""

import distutils.util
import os
import re
import urllib.parse
@@ -43,7 +42,7 @@

from did.base import Config, ReportError
from did.stats import Stats, StatsGroup
from did.utils import listed, log, pretty
from did.utils import listed, log, pretty, strtobool

# Maximum number of results fetched at once
MAX_RESULTS = 100
@@ -214,7 +213,7 @@ def __init__(self, option, name=None, parent=None, user=None):
# SSL verification
if "ssl_verify" in config:
try:
self.ssl_verify = distutils.util.strtobool(
self.ssl_verify = strtobool(
config["ssl_verify"])
except Exception as error:
raise ReportError(
5 changes: 2 additions & 3 deletions did/plugins/gitlab.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
"""

import distutils.util
from time import sleep

import dateutil
@@ -33,7 +32,7 @@

from did.base import Config, ReportError, get_token
from did.stats import Stats, StatsGroup
from did.utils import listed, log, pretty
from did.utils import listed, log, pretty, strtobool

GITLAB_SSL_VERIFY = True
GITLAB_API = 4
@@ -382,7 +381,7 @@ def __init__(self, option, name=None, parent=None, user=None):
"No GitLab token set in the [{0}] section".format(option))
# Check SSL verification
try:
self.ssl_verify = bool(distutils.util.strtobool(
self.ssl_verify = bool(strtobool(
config["ssl_verify"]))
except KeyError:
self.ssl_verify = GITLAB_SSL_VERIFY
7 changes: 3 additions & 4 deletions did/plugins/jira.py
Original file line number Diff line number Diff line change
@@ -78,7 +78,6 @@
Other values are ``basic`` and ``token``.
"""

import distutils.util
import os
import re
import urllib.parse
@@ -90,7 +89,7 @@

from did.base import Config, ReportError, get_token
from did.stats import Stats, StatsGroup
from did.utils import listed, log, pretty
from did.utils import listed, log, pretty, strtobool

# Maximum number of results fetched at once
MAX_RESULTS = 1000
@@ -345,7 +344,7 @@ def __init__(self, option, name=None, parent=None, user=None):
# SSL verification
if "ssl_verify" in config:
try:
self.ssl_verify = distutils.util.strtobool(
self.ssl_verify = strtobool(
config["ssl_verify"])
except Exception as error:
raise ReportError(
@@ -356,7 +355,7 @@ def __init__(self, option, name=None, parent=None, user=None):
# Make sure we have project set
self.project = config.get("project", None)
if "use_scriptrunner" in config:
self.use_scriptrunner = distutils.util.strtobool(
self.use_scriptrunner = strtobool(
config["use_scriptrunner"])
else:
self.use_scriptrunner = True
24 changes: 24 additions & 0 deletions did/utils.py
Original file line number Diff line number Diff line change
@@ -187,6 +187,30 @@ def shorted(text, width=MAX_WIDTH):
return "\n".join(lines)


def strtobool(val):
"""
Convert a string representation of truth to true (1) or false (0).
Reimplemented following instructions at
https://peps.python.org/pep-0632/#migration-advice
This is a copy of
https://github.com/pypa/distutils/blob/ee021a1c58b43607ccc75447159bd90f502c6bea/distutils/util.py#L340
Which is under MIT license.
Returns:
1 if val is within 'y', 'yes', 't', 'true', 'on', and '1'.
0 if val is within 'n', 'no', 'f', 'false', 'off', and '0'.
Raises:
ValueError if 'val' is anything else.
"""
val = val.lower()
if val in ('y', 'yes', 't', 'true', 'on', '1'):
return 1
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
return 0
else:
raise ValueError("invalid truth value {!r}".format(val))


def item(text, level=0, options=None):
""" Print indented item. """
# Extra line before in each section (unless brief)

0 comments on commit 84e3733

Please sign in to comment.