Skip to content
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

python module: stop using distutils on sufficiently new python #12237

Closed
wants to merge 3 commits into from

Conversation

dnicolodi
Copy link
Member

This is a rebase of #11133 on current master. @eli-schwartz I took the freedom of updating this PR of yours that haven't seen activity since quite a while. With the Python 3.12 release approaching it makes sense to push this across the finish line sooner rather than later.

@dnicolodi dnicolodi requested a review from jpakkane as a code owner September 8, 2023 15:57
@dnicolodi dnicolodi force-pushed the rm-distutils branch 2 times, most recently from 0056182 to 5403061 Compare September 8, 2023 16:19
If the found program happens to be sys.executable, we can do an
optimization and get the function return value instead of communicating
via subprocess + json. The results are identical either way.
Since 3.10.3, Debian finally started patching sysconfig with custom
paths, instead of just distutils. This means we can now go use that
instead. It reduces our reliance on the deprecated distutils module.

Partial fix for mesonbuild#7702.
Disagreement between distutils and sysconfig have been resolved for
Python 3.12, see python/cpython#100356 and
python/cpython#100967

This is the other half of the fix for mesonbuild#7702.
@eli-schwartz
Copy link
Member

Or you can ask me to rebase. I was already planning on doing it!!!

@dnicolodi
Copy link
Member Author

I did #11133 (comment) But I did not receive an answer. The rebase is not trivial. Feel free to use these commits if you like. I actually don't see the need to close this, as the commits all preserve the original metadata... but whatever.

@dnicolodi
Copy link
Member Author

FWIW this passes all the meson-python tests mesonbuild/meson-python#492

@eli-schwartz
Copy link
Member

eli-schwartz commented Sep 8, 2023

I did #11133 (comment) But I did not receive an answer. The rebase is not trivial.

Apologies for not publicly responding. Though in general I'd appreciate in such a situation if you asked first for my schedule and made it clear you were considering to copy it into a new PR if necessary to fit some timeframe of your own, as I was very startled by this... FWIW there is some context here on the lag-- I'd originally planned to try getting this in back in February but due to harassment I got burnt out from it. It has always been my plan to get this done in time for python 3.12, and 6 months later I am in fact feeling a bit better about doing so...

The rebase isn't a problem, at least. I have had the patches in my local worktree all this time -- I haven't worked on it or sanity checked it, but I have rebased it along with everything else I have as local patches -- I have followed the same general workflow as described here, since probably 2015: https://drewdevault.com/2020/04/06/My-weird-branchless-git-workflow.html

In terms of the rebase you have done, there are also tweaks that I don't really understand but which differ from what I have done. e.g. I'm not sure whether to keep using distutils on python 3.11 is the best choice? (I had an explicit rationale for choosing 3.8, and my concern was less about fixing CPython than about declaring a certain behavior canonical.)

I'm also regretting the fourth patch and have an alternative patch that obsoletes it.

@dnicolodi
Copy link
Member Author

Apologies for not publicly responding. Though in general I'd appreciate in such a situation if you asked first for my schedule

That is what I exactly did. Knowing the backstory a bit I thought that insisting in getting a reply from you was counterproductive. I don't think that publishing a PR with a rebase of some patches is the big deal that you seem to be making of it. I thought that help could be appreciated, I didn't want to step on anyone's toes.

In terms of the rebase you have done, there are also tweaks that I don't really understand but which differ from what I have done.

I probably misremember, but I purposely introduced only three changes to the patches. I'll mark them in the diff with my reasoning for them.

I'm not sure whether to keep using distutils on python 3.11 is the best choice? (I had an explicit rationale for choosing 3.8, and my concern was less about fixing CPython than about declaring a certain behavior canonical.)

I based that on the fact that your fixes for CPython (PRs linked in the commit message) AFAIK have been merged only for Python 3.12.

I'm also regretting the fourth patch and have an alternative patch that obsoletes it.

After rebasing there are only three patches. I think you mean the one running the introspection in-process? I've included that mainly to minimize the deviations from your original series as it does not affect functionality.

else:
import importlib.resources
with importlib.resources.path('mesonbuild.scripts', 'python_info.py') as f:
cmd = self.get_command() + [os.fspath(f)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I've added the os.fspath(). It is needed because on Python 3.7 it is not possible to use a pathlib.Path as returned from importlib.resources.path() as a command array element for subprocess.run() and friends (which I believe bake the implementation of mesonlib.Popen_safe()). mypy complains if the os.fspath() is not present.

cmd.ensure_finalized()
return bool(cmd.get_libraries(Extension('dummy', [])))
# on versions supporting python-embed.pc, this is the non-embed lib
if sys.version_info >= (3, 12):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this from (3, 8) (I think) to (3, 12). I've already explained the reason.

# on versions supporting python-embed.pc, this is the non-embed lib
if sys.version_info >= (3, 12):
variables = sysconfig.get_config_vars()
return bool(variables.get('LIBPYTHON', True))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this to this form from

return bool(variables.get('LIBPYTHON', 'yes'))

because the yes there always makes me pause and wonder if someone expects LIBPYTHON to be set to no and have bool() return false in that case. It is clearly not the case, but True avoids the mental overhead.

@dnicolodi
Copy link
Member Author

BTW, the "Arch / PyPy" failure looks very much related.

@dnicolodi
Copy link
Member Author

I've extended the test matrix for meson-python and more failures popped up https://github.com/mesonbuild/meson-python/actions/runs/6130666589/job/16639969639?pr=492

@dnicolodi
Copy link
Member Author

BTW, the "Arch / PyPy" failure looks very much related.

It was caused by a rebase error. It should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants