Skip to content

Adress Python 3.12 pkg_resources change #52

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

Closed
josh-ashkinaze opened this issue Dec 22, 2024 · 0 comments
Closed

Adress Python 3.12 pkg_resources change #52

josh-ashkinaze opened this issue Dec 22, 2024 · 0 comments
Assignees
Labels
refactor Refactor codebase

Comments

@josh-ashkinaze
Copy link
Owner

josh-ashkinaze commented Dec 22, 2024

What is the problem?

  • 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.'

[1] mu-editor/mu#2485

  • 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

@josh-ashkinaze josh-ashkinaze added the refactor Refactor codebase label Dec 22, 2024
@josh-ashkinaze josh-ashkinaze self-assigned this Dec 22, 2024
@josh-ashkinaze josh-ashkinaze changed the title Swap importlib resources in place of pkg_resources Adress Python 3.12 pkg_resources change Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor codebase
Projects
None yet
Development

No branches or pull requests

1 participant