-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Stop using the removed importlib.resources.path
on Python >=3.13
#12402
Conversation
Actually, let me also build CPython from its current HEAD to ensure they didn't remove more. EDIT: done,
so a bit more to do here. Shouldn't this have been caught by some CI check for use of deprecated features? It does warn in Python 3.11: $ python --version
Python 3.11.6
$ python -c "from importlib.resources import path; path('mesonbuild.scripts', 'python_info.py')"
<string>:1: DeprecationWarning: path is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice. |
See 9aff189 I did in fact add checks for deprecated features. It's not part of CI though, it's something you have to run manually. Use of deprecated features isn't a bug in the code so I don't want to cause CI regressions, and it's the kind of thing that you only need to run once every 18 months (but could run more often). In this case I actively stomped quite hard on this particular deprecation warning. IIRC at the time I was fairly sure the upstream plan was to have this be "eternally deprecated" especially because there's... zero cost to keeping it around, and I found the rapid deprecation and from scratch rewrites of the entire API contract of this stdlib module to be completely alarming and difficult to build stable programs on top of. |
265a09e
to
023d0b0
Compare
That seems very reasonable, thanks.
Yes, I agree. I think I got them all now, at least this gets |
023d0b0
to
c1818bb
Compare
mesondata should be robustly exercised in CI as I'm pretty sure it's integral to the working of cmake dependencies (e.g. llvm). But you wouldn't typically encounter that when working with python extensions. I'm actually to blame here because really we should have used mesondata for the places where we are currently using importlib.resources, but I was lazy and inconsistent when authoring the relevant code. Possibly I was confused by the deceptively attractive idea of "simply use the stdlib". Maybe the correct answer is to use our high level wrapper instead. This probably means admitting that we're never planning to get rid of our utility wrapper modules. I guess the answer to that is "oh well, it is what it is". |
@@ -112,8 +113,13 @@ def sanity(self) -> bool: | |||
# Sanity check, we expect to have something that at least quacks in tune | |||
|
|||
import importlib.resources | |||
if sys.version_info >= (3, 13): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not >= (3, 9)
? Why use a deprecated function when the replacement is available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't seem to matter, so just trying to make the minimal change here. If it did matter (as it has before with importlib
and traversables, it's complex machinery), I'd rather find out through 3.13 early adopters.
It's also possible that something still changes before 3.13.rc1, and this would allow dropping the if-else.
The functional API is on track to be added back into 3.13 alpha and un-deprecated, which would mean that no released version of python will have lacked it. Once it is merged into CPython I propose to close this PR. |
Great! Closing this PR when the API is added back in sounds good to me. |
The APIs have been restored in python/cpython#116609, so I'll close this. Thanks @eli-schwartz and @jaraco. |
Closes gh-12401
I've tested that
run_project_tests.py
is happy when changingif sys.version_info >= (3, 13):
to(3, 9)
instead, but decided to only change this for Python 3.13 and up to be conservative and because I saw in the CPython commit log forimportlib.resources
thatas_file
leaked a file descriptor until less than a year ago.