distutils is deprecated. distutils.util.strtobool needs replacement.#279
distutils is deprecated. distutils.util.strtobool needs replacement.#279itzwam wants to merge 1 commit intoCumulusNetworks:masterfrom
distutils is deprecated. distutils.util.strtobool needs replacement.#279Conversation
|
Hi, @itzwam , I think you're mismatching informations here. Let me try to clarify and tell me if I'm wrong. First of I believe the issue in #278 with the current code base should not be possible as we're getting strtobool from setuptools and not directly from distutils (which is deprecated and removed from 3.12). I did miss the recommendation of reimplementing strtobool for this use case so I'm not invalidating your point, but, what I understand is that, setuptools includes its own version of distutils in its package and the import you're seeing is an import of their own version made possible through a hack.
I do not know what the setuptools devs will do but I did try the 2nd release candidate of 3.12.0 and installed setuptools with pip. The current import seems to work fine for now. If we wish to replace this import to follow the pep advice, I would recommend to just copy/paste the actual source code into our own utils module: def strtobool(val):
"""Convert a string representation of truth to true (1) or false (0).
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 = 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))Side-note:
|
Fixes #278
As seen here: https://github.com/pypa/setuptools/blob/2384d915088b960999ca74fb81ce70bffd17b082/setuptools/dist.py#L23C6-L23C21, setuptools.dist is calling
distutils.strtoboolAs of Python 3.10, distutils has been deprecated, which results in this DeprecationWarning when using simple_settings:
To eliminate this warning, PEP 632 recomends copying the implementation into your own code, or reimplementing:
https://www.python.org/dev/peps/pep-0632/#migration-advice
An alternative is to use str2bool from PyPI:
https://github.com/symonsoft/str2bool