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

distutils is deprecated. distutils.util.strtobool needs replacement. #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

itzwam
Copy link

@itzwam itzwam commented Oct 16, 2023

Fixes #278

As seen here: https://github.com/pypa/setuptools/blob/2384d915088b960999ca74fb81ce70bffd17b082/setuptools/dist.py#L23C6-L23C21, setuptools.dist is calling distutils.strtobool


As of Python 3.10, distutils has been deprecated, which results in this DeprecationWarning when using simple_settings:

lib/python3.10/site-packages/simple_settings/special_settings.py:5: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    from distutils.util import strtobool

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

@sohorx
Copy link
Contributor

sohorx commented Oct 23, 2023

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

distutils is deprecated. distutils.util.strtobool needs replacement.
2 participants