Skip to content

Commit

Permalink
--remove deprecated distutils from setup
Browse files Browse the repository at this point in the history
--packaging
  • Loading branch information
jturner65 committed Feb 13, 2024
1 parent a29fe27 commit 8fdaaf6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
22 changes: 19 additions & 3 deletions examples/ab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import argparse
import csv
import distutils

import demo_runner as dr

Expand Down Expand Up @@ -173,6 +172,23 @@ def get_csv_data(
return rows, fields


def strtobool(input_str: str) -> bool:
"""Convert a string representation of truth to 1(true) or 0(false)
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
(This code was taken directly from pre-deprecated distutils.utils.strtobool)
"""
val = input_str.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" % (val,))


args = parser.parse_args()

control_val = None
Expand All @@ -185,9 +201,9 @@ def get_csv_data(
if "control_value" in args:
control_val = float(args.control_value)
elif args.boolean:
test_val = distutils.util.strtobool(args.test_value)
test_val = strtobool(args.test_value)
if "control_value" in args:
control_val = distutils.util.strtobool(args.control_value)
control_val = strtobool(args.control_value)
elif args.string:
test_val = args.test_value
if "control_value" in args:
Expand Down
24 changes: 18 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import shutil
import subprocess
import sys
from distutils.util import strtobool
from distutils.version import StrictVersion

# from https://github.com/pypa/packaging/issues/520#issuecomment-1067119795
from packaging.version import Version
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext

Expand All @@ -39,7 +39,19 @@


def str2bool(input_str: str) -> bool:
return bool(strtobool(input_str.lower()))
"""Convert a string representation of truth to True or False
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
"""
val = input_str.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError("invalid truth value %r" % (val,))


def is_pip() -> bool:
Expand Down Expand Up @@ -438,9 +450,9 @@ def load(filename):


if __name__ == "__main__":
assert StrictVersion(
"{}.{}".format(sys.version_info[0], sys.version_info[1])
) >= StrictVersion("3.9"), "Must use python 3.9 or newer"
assert Version("{}.{}".format(sys.version_info[0], sys.version_info[1])) >= Version(
"3.9"
), "Must use python 3.9 or newer"
with open("./requirements.txt", "r") as f:
requirements = [l.strip() for l in f.readlines() if len(l.strip()) > 0]

Expand Down

0 comments on commit 8fdaaf6

Please sign in to comment.