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

modules/python: detect debian distutils missing and show an error #9335

Closed
wants to merge 1 commit into from

Conversation

FFY00
Copy link
Member

@FFY00 FFY00 commented Oct 1, 2021

Signed-off-by: Filipe Laíns [email protected]

@FFY00 FFY00 requested a review from jpakkane as a code owner October 1, 2021 11:45
@FFY00
Copy link
Member Author

FFY00 commented Oct 1, 2021

cc @eli-schwartz

@FFY00 FFY00 force-pushed the better-debian-distutils-error branch from 27130d0 to 7cc10b4 Compare October 1, 2021 11:47
@codecov
Copy link

codecov bot commented Oct 1, 2021

Codecov Report

Merging #9335 (2c368b4) into master (88d9646) will decrease coverage by 0.00%.
The diff coverage is 92.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9335      +/-   ##
==========================================
- Coverage   67.29%   67.29%   -0.01%     
==========================================
  Files         396      396              
  Lines       85410    85420      +10     
  Branches    17481    17485       +4     
==========================================
+ Hits        57474    57480       +6     
- Misses      23246    23248       +2     
- Partials     4690     4692       +2     
Impacted Files Coverage Δ
mesonbuild/modules/python.py 65.92% <92.30%> (+0.17%) ⬆️
mesonbuild/scripts/vcstagger.py 87.50% <0.00%> (-4.17%) ⬇️
mesonlib/universal.py 75.76% <0.00%> (-0.09%) ⬇️
modules/python.py 63.43% <0.00%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88d9646...2c368b4. Read the comment docs.

@FFY00 FFY00 force-pushed the better-debian-distutils-error branch from 7cc10b4 to 9fff908 Compare October 1, 2021 12:31
Copy link
Member

@eli-schwartz eli-schwartz left a comment

Choose a reason for hiding this comment

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

In general I like the look of this. But I'm not sure we should be logging an error directly in the Python ExternalProgram constructor, since it may be requested with required: false and hence not be an error after all.

It should probably either:

  • be logged as mlog.log and rely on the later checks for sanity() return value to promote to an error
  • set an attribute on self and look that up later to raise the error message as mlog.error

if info is not None:
if 'error' in info:
assert isinstance(info['error'], str)
mlog.error('Python interpreter introspection failed: %s' % info['error'])
Copy link
Member

Choose a reason for hiding this comment

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

Please use f-strings (or, when the complexity penalty is too great, the str.format() method).

The assert doesn't seem to be performing any debug sanity checks, so it can probably be dropped.

Copy link
Member Author

Choose a reason for hiding this comment

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

The assert is to make sure the nobody screw up when editing the introspection script, but I can remove it if you want.

Copy link
Member

Choose a reason for hiding this comment

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

Actually that may speak to a greater need: adding a test case that actually tries to trigger this code path and testing that it produces the correct error message.

On the other hand -- if it's not a string what will it be? It is loaded as json there are only so many options...

Copy link
Member

Choose a reason for hiding this comment

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

I don't have strong opinions on the assert, but as a project standard we have purged percent formatting in favor of f-strings wherever it doesn't have major readability costs (now that we require a minimum python which supports f-strings) and the .format() method otherwise.

Copy link
Member Author

@FFY00 FFY00 Oct 1, 2021

Choose a reason for hiding this comment

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

Actually that may speak to a greater need: adding a test case that actually tries to trigger this code path and testing that it produces the correct error message.

We would have to keep the tests updated to make sure they cover all code paths in the introspection command, which kind of defeats the purpose. I have already added a test that triggers the code path from the Meson side, just not the introspection script.

On the other hand -- if it's not a string what will it be? It is loaded as json there are only so many options...

Could be anything. I just put the assert there as a sanity check to avoid obscure error. Yes, this is me being preventive, but it's cheap, so...

I don't have strong opinions on the assert, but as a project standard we have purged percent formatting in favor of f-strings wherever it doesn't have major readability costs (now that we require a minimum python which supports f-strings) and the .format() method otherwise.

Of course. I don't like nesting quotes in f-strings, so I went with % as that's what the neighboring code did, but I can definitely change.

Copy link
Member

@eli-schwartz eli-schwartz Oct 1, 2021

Choose a reason for hiding this comment

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

Nesting quotes? Do you mean like f'{some string!r}' to guarantee that the printed content itself has quote characters?

Edit: oh sorry, I'm dumb. You meant the single quotes for the dictionary key. Yeah, that can be a bit annoying.

Copy link
Member Author

Choose a reason for hiding this comment

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

f'something: {info["error"]}'

Copy link
Member

Choose a reason for hiding this comment

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

Also it is true we do have some percent formatted strings still... I would like to get rid of all of them but I mainly drove the upgrade using pyupgrade which is pretty good but still heuristics based and thus not perfect. The vast majority were changed though. :D

Copy link
Member Author

@FFY00 FFY00 Oct 1, 2021

Choose a reason for hiding this comment

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

Anyway, I changed to str.format, let me know if you'd like me to change to an f-string.

@FFY00
Copy link
Member Author

FFY00 commented Oct 1, 2021

be logged as mlog.log and rely on the later checks for sanity() return value to promote to an error

I would prefer this. If my Python interpreter is bad and consequently the Python specific bits of the project gets disabled, I want to know why.

@FFY00 FFY00 force-pushed the better-debian-distutils-error branch from 9fff908 to 539f3a6 Compare October 1, 2021 15:10
@eli-schwartz
Copy link
Member

That's a reasonable perspective and I think I agree.

@FFY00 FFY00 force-pushed the better-debian-distutils-error branch from 539f3a6 to df77112 Compare October 1, 2021 15:20
@cclauss
Copy link
Contributor

cclauss commented Oct 2, 2021

Python 3.10 (scheduled to be released on Monday) deprecates ditsutils and Python 3.12 drops support for distutils as discussed in https://www.python.org/dev/peps/pep-0632/

@FFY00
Copy link
Member Author

FFY00 commented Oct 2, 2021

Yes, we are aware, but unfortunately we don't have a migration plan right now due to Debian patching the interpreter, but not sysconfig. As distutils will only be removed in 3.12 we still have some time to coordinate and update the code.

@eli-schwartz
Copy link
Member

The deprecation of distutils is unrelated to this PR as we already depended on distutils for entirely unrelated reasons. For a long time, meson has considered the lack of distutils to be a fatal error. This PR merely changes the formatting of the error message that is used when meson fatally exits.

Please take all discussion of distutils deprecation to #7702.

And distutils is not deprecated right now! It is only deprecated in python 3.10! This is important, because it means we have an awful long time before it is actually removed, which means that Debian's failure to have a legitimate python is not a valid reason for us to make meson not work on Debian in order to punish ordinary Debian users for the fact that Debian developers do not comply with the PEP.

It's not a bug to rely on deprecated things. It is a concern, yes, but that just means we need to balance the pros and cons of need vs. consequences.

@FFY00 FFY00 force-pushed the better-debian-distutils-error branch from df77112 to 9f5cb9d Compare October 7, 2021 15:20
@FFY00 FFY00 requested a review from eli-schwartz October 7, 2021 15:20
@eli-schwartz
Copy link
Member

Let's see if restarting the CI job fixes that macOS failure. It looks pretty irrelevant anyway...

def test_introspection_error(self, mlog_log, Popen_safe):
python = PythonExternalProgram('some-python', ['some-python'])

assert not python.sanity()
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, shouldn't this be a unittest assertFalse, not a regular assert?

Copy link
Contributor

@cclauss cclauss Oct 8, 2021

Choose a reason for hiding this comment

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

When tests are run with pytest, either is acceptable. In fact, this simplicity without loss of debugging information is pytest's number one feature.

Copy link
Member

Choose a reason for hiding this comment

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

Well yes, but if you don't have both pytest and pytest-xdist then the tests get run without pytest, just unittest, and that is a supported configuration...

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the same thing in this case, these functions just exist to provide a nicer error output. pytest rewrites the bytecode to replace the asserts with something similar in order to achieve that. It makes sense when you are comparing lists for eg, but as we are just checking a bool, is pretty much the same.

Copy link
Member

Choose a reason for hiding this comment

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

I know what pytest does, thanks.

Again, my point is that we don't depend on pytest (even if we do automatically use it some of the time).

Copy link
Member

Choose a reason for hiding this comment

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

If it's "pretty much the same thing" to you, it shouldn't be a problem to use unittest asserts for the sake of those odd people using unittest instead of pytest to run this testsuite :)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's pretty much the same thing because we are just checking a bool, which does not show any extra information, unlike comparing lists for eg.
I just used an assert because that's what I am used to, but I can change it if you want. Though I am not home right now, and have an appointment afterwards, so it might be a couple hours.

@eli-schwartz
Copy link
Member

eli-schwartz commented Oct 8, 2021

Due to the previous PR which I just merged, this now ⚔️ conflicts.

Other than that and the assert nit, I approve this PR.

@jpakkane
Copy link
Member

⚔️ conflicts.

@eli-schwartz
Copy link
Member

Urgent ping.

0.60 rc1 is due today and we're trying to merge things we think are ready ASAP beforehand.

I would love to see this make it in!

@FFY00
Copy link
Member Author

FFY00 commented Oct 10, 2021

I will update it tomorrow when I am on working hours, unless it cannot wait until then. I will also try to send a patch for ev-br/mc_lib#45 ASAP.

@eli-schwartz
Copy link
Member

Seems like the rc is being delayed until tomorrow anyway due to time constraints. :) Looking forward to the update for this PR which should still make it in.

@FFY00 FFY00 force-pushed the better-debian-distutils-error branch from 9f5cb9d to 2c368b4 Compare October 11, 2021 12:57
@FFY00
Copy link
Member Author

FFY00 commented Oct 11, 2021

@eli-schwartz rebased on master.

@eli-schwartz
Copy link
Member

What happened?

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.

5 participants