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

--[WIP][BE/Refactor/Bugfix] Remove deprecated distutils from setup and ab_test #2202

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ matplotlib
numba
numpy==1.26.4
numpy-quaternion
packaging
pillow==10.4.0
scipy>=1.10.1
tqdm
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 @@ -429,9 +441,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
Loading