ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
794 stars 46 forks source link

Fix distutils deprecation #98

Closed ionelmc closed 3 years ago

ionelmc commented 3 years ago

Ref #97

ionelmc commented 3 years ago

Dooh! 🤦‍♂️

The-Compiler commented 3 years ago

I just found site.getsitepackages() and wonder if it does what you want?

$ python3.10 -Wall
Python 3.10.0b1 (default, May  4 2021, 14:26:39) [GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.sysconfig import get_python_lib
<stdin>:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
<stdin>:1: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
>>> get_python_lib()
'/usr/lib/python3.10/site-packages'
>>> from site import getsitepackages
>>> getsitepackages()
['/usr/lib/python3.10/site-packages']

seems to work on e.g. Ubuntu 20.04 too:

>>> import site
>>> site.getsitepackages()
['/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']
ionelmc commented 3 years ago

Yes, I know about it - it's actually used:

if hasattr(site, 'getsitepackages'):
    SITE_PACKAGES_PATHS.update(site.getsitepackages())

But I have chosen to not solely rely on it because everyone messes with that site.py file (distro customizations, virtualenv implementing workarounds or whatever). It wouldn't include distro-packages for sure.