aristocratos / bpytop

Linux/OSX/FreeBSD resource monitor
Apache License 2.0
10.07k stars 397 forks source link

Python error on Fedora 35 #364

Closed shamblett closed 2 years ago

shamblett commented 2 years ago

The utility works great on stock Fedora 35 however when I exit I get this message -

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
RCristiano commented 2 years ago

+1

AbrarSL commented 2 years ago

Seeing this on Arch as well.

etiennepellegrini commented 2 years ago

Seeing this on macOS 11.6.1, with bpytop 1.0.67 installed through Homebrew. The problem comes from distutils.utils, from which strtobool is imported and used only once.

Per PEP 632:

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.util.strtobool

The solution is to implement the functionality described here. Something like:

def strtobool(val):
    try:
        if val.lower() in ['y', 'yes', 't', 'true', 'on', '1']:
            return True
        elif val.lower() in ['n', 'no', 'f', 'false', 'off', '0']:
            return False
    except:
        raise ValueError(f"invalid type {type(val)} for truth value {val}")
    else:
        raise ValueError(f"invalid truth value {val}")

(note that the .lower() is not documented, but strtobool does accept the capitalized versions of the flags as True or False, and throws an error when called on something else than a str)

UmarJ commented 2 years ago

You can see how it's implemented in the source here.