cfpb / django-flags

Feature flags for Django projects
https://cfpb.github.io/django-flags/
Creative Commons Zero v1.0 Universal
256 stars 31 forks source link

Fix distutils deprecation #98

Closed edomora97 closed 2 years ago

edomora97 commented 2 years ago

The distutils package will be removed soon. This patch removes its uses, and replaces the only function involved with an identical implementation.

The implementation of strtobool is copied from the cpython implementation at: https://github.com/python/cpython/blob/755be9b1505af591b9f2ee424a6525b6c2b65ce9/Lib/distutils/util.py#L308

The DeprecationWarning produced before the patch:

../usr/local/lib/python3.10/site-packages/flags/conditions/conditions.py:2
  /usr/local/lib/python3.10/site-packages/flags/conditions/conditions.py:2: 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

PEP 632 (https://peps.python.org/pep-0632/) suggests to reimplement this function:

For these functions, and any others not mentioned here, you will need to reimplement the functionality yourself. The legacy documentation can be found at https://docs.python.org/3.9/distutils/apiref.html

distutils.dir_util.create_tree distutils.util.change_root distutils.util.strtobool