Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop usage of distutils #355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -31,7 +31,6 @@
higher priority.
"""

import distutils.util
import os
import re
import urllib.parse
Expand All @@ -42,7 +41,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
Expand Down Expand Up @@ -213,7 +212,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(
Expand Down
5 changes: 2 additions & 3 deletions did/plugins/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

"""

import distutils.util
from time import sleep

import dateutil
Expand All @@ -32,7 +31,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
Expand Down Expand Up @@ -381,7 +380,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
Expand Down
7 changes: 3 additions & 4 deletions did/plugins/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
Other values are ``basic`` and ``token``.
"""

import distutils.util
import os
import re
import urllib.parse
Expand All @@ -89,7 +88,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
Expand Down Expand Up @@ -344,7 +343,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(
Expand All @@ -355,7 +354,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
Expand Down
24 changes: 24 additions & 0 deletions did/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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
lukaszachy marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down
Loading