You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python 3.12 is no longer bundled with pkg_resources [1], and this creates an import error when getting package resources. The user-side fix is that if you pip install setuptools this fixes the error, so it is tempting to include setuptools as a run-time dependency in requirements.txt. However, pip flags adding setuptools as a dependency to be 'unsafe.'
The modern alternative to pkg_resources is importlib.resources and this would obviate any import or unsafe issues. But the problem is, that is is Python 3.9+
So it is likely I either need to bound above 3.9 (and switch to importlib) or below 3.12 (and keep pkg_resources)
What is the solution?
The robust way to handle this is to have a function like get_package_resources that will try to use pkg_resources but upon import error switch to using importlib. Then, when reading ANES data or the YAML instruction file---the places where we need package data---we just call get_package_resources so it can handle both.
Add tests to make sure we ca read files both using pkg_resources and mocking an import error to fallback to importlib
The text was updated successfully, but these errors were encountered:
What is the problem?
pip install setuptools
this fixes the error, so it is tempting to includesetuptools
as a run-time dependency inrequirements.txt
. However, pip flags adding setuptools as a dependency to be 'unsafe.'[1] mu-editor/mu#2485
The modern alternative to
pkg_resources
isimportlib.resources
and this would obviate any import or unsafe issues. But the problem is, that is is Python 3.9+So it is likely I either need to bound above 3.9 (and switch to importlib) or below 3.12 (and keep pkg_resources)
What is the solution?
The robust way to handle this is to have a function like
get_package_resources
that will try to usepkg_resources
but upon import error switch to usingimportlib
. Then, when reading ANES data or the YAML instruction file---the places where we need package data---we just callget_package_resources
so it can handle both.Add tests to make sure we ca read files both using pkg_resources and mocking an import error to fallback to importlib
The text was updated successfully, but these errors were encountered: