Skip to content

prereq-build: clean up python check and narrow down its version whitelist - #11747

Closed
dhewg wants to merge 3 commits into
openwrt:mainfrom
dhewg:pycheck
Closed

dhewg wants to merge 3 commits into
openwrt:mainfrom
dhewg:pycheck

Conversation

@dhewg

@dhewg dhewg commented Jan 9, 2023 •

Copy link
Copy Markdown
Contributor

Just a couple of minor improvements.

The second patch effectively reverts #10398, so cc @tymscar.
I'm not sure what the reason was to whitelist v3.* instead of a single new version, but as the upcoming v3.12 shows there can be breaking changes - see the 3rd patch.

For a new version we need to add the pythonX.Y interpreter name anyway, bumping a single digit on top doesn't seem too unreasonable.

This doesn't whitelist v3.12 yet as that's still in alpha stage and distros probably not shipping it yet (?).
Someone already on v3.12 needs to check most/all packages for compatibility, based on past issues it's known that quite some packages and/or buildsystems utilize the distutils module.

@github-actions github-actions Bot added the build/scripts/tools pull request/issues for build, scripts and tools related changes label Jan 9, 2023
@mcprat

mcprat commented Jan 15, 2023

Copy link
Copy Markdown
Contributor

I don't like the first commit, I've been trying to work on reducing the presence of makefile rules in prereq-build

I don't see a particular problem with letting the regex be a catch-all, it removes the need to edit this when testing an unreleased version

in my opinion, issues with python should be fixed by means other than version control, hopefully before the version in question gets released. and if someone has a beta version installed they should already know to not expect perfect behavior from it.

the real question is, how much in Openwrt relies on having distutils as a separate module if at all, or is it just the presence of a function that was needed

I don't remember the situation. @neheb I would like to know your opinion. do you think this strengthens the idea of building our own python or is it an easy fix?

@neheb

neheb commented Jan 15, 2023 •

Copy link
Copy Markdown
Contributor

distutils are used by meson. Not needed with newer python versions though. I think @eli-schwartz known more.

@eli-schwartz

Copy link
Copy Markdown

Meson still relies on distutils without exception, even on Python 3.12 -- this is not the end of the world since that is still in alpha, and a third of a year away from merely reaching the first beta. Work is in progress to have Meson stop needing that, but it's not merged yet.

My expectation is that, probably, Meson will require distutils on python 3.10.2 and under, mostly because we need to check if the python is a Debian version of python and this is only knowable using distutils. If not for that, we would only need distutils on python 3.7 and under. (Also, if not for Debian I would have been motivated to solve this a year ago and we would not be having this discussion today.)

Yay, Debian...

@eli-schwartz

Copy link
Copy Markdown

Personally, I am not worried about people running an alpha release of python. They can pip install setuptools which provides distutils regardless of whether there is a copy of distutils in the stdlib, which means any software that relies on distutils for whatever reason will probably work.

... probably. Because setuptools has an, uhm, "evolving" API. (Meson does not do anything complex enough to ever hit that. numpy.distutils, among others, is so unstable that their official recommendation is to pin setuptools 59 and never upgrade.)

@dhewg

dhewg commented Jan 15, 2023 •

Copy link
Copy Markdown
Contributor Author

I don't like the first commit, I've been trying to work on reducing the presence of makefile rules in prereq-build

Okay, but running the very same thing twice just for another shortcut doesn't seem optimal either. Any suggestions? Maybe we can even drop the python one because python3 is now used everywhere anyway, but I didn't want to risk regressing anything.

I don't see a particular problem with letting the regex be a catch-all, it removes the need to edit this when testing an unreleased version

True, I don't particularly like to limit a user's option either. But what I don't like even more are reoccurring reports that something doesn't work, when it's known to not work. That's just a waste of everybody's time and it gets really annoying. And that's where 60af8d7 came from, where we got reports like every other week ("x fails to build"). And most of the time that was because of debian's weird python packaging. With that commit those reports stopped.

I can vaguely see that happening again with 3.12

@dhewg

dhewg commented Jan 15, 2023 •

Copy link
Copy Markdown
Contributor Author

They can pip install setuptools which provides distutils regardless of whether there is a copy of distutils in the stdlib, which means any software that relies on distutils for whatever reason will probably work.

But you'd have to change import distutils to from setuptools import distutils, right? As simple as that may be, every user of that package has to be adapted to it. Yay

@eli-schwartz

eli-schwartz commented Jan 15, 2023 •

Copy link
Copy Markdown

But you'd have to change import distutils to from setuptools import distutils, right? As simple as that may be, every user of that package has to be adapted to it. Yay

Nope! Setuptools installs a global hook that runs as soon as you start the python binary. It causes all attempts to import distutils to instead import setuptools._distutils (it has an underscore BTW, it's an internal implementation detail) and return that as the imported "distutils" module. You cannot (trivially) import the standard library one at all.

@dhewg

dhewg commented Jan 15, 2023

Copy link
Copy Markdown
Contributor Author

Sneaky!

But alright, as per your expectation, I'll keep the distutils patch here as-is then. Which is to limit the OpenWrt's distutils check to <3.12 and don't check for any substitute for >=3.12, yet.

@dhewg

dhewg commented Jan 15, 2023

Copy link
Copy Markdown
Contributor Author

And that in return means we should probably start checking for setuputils on >=3.12. Because we use meson v0.61.x, which uses distutils, which then is only available via setuputils. Unless a future meson point release backports mesonbuild/meson#11133

But I'm not blindly adding that here, someone on 3.12 needs to verify and check that of course

@Ansuel

Ansuel commented May 15, 2023

Copy link
Copy Markdown
Member

@dhewg hi... this came up #12610

in short... package manager update the python version and the link still point to the old version that now it's not there anymore...
I was proposing a solution where we link for python3 directly instead of the version... and i remember there was already a version for this...

We have 2 solution...

  • one build python ourself... (we also have a python
  • link to python3 instead of the direct version and fix bugs as new version of python gets released...

@eli-schwartz

Copy link
Copy Markdown

Linking to python3 without the .10 at the end, is unlikely to actually make things work. You'll just get errors that modules aren't installed, because the module directory is versioned and so are .so compiled extensions.

Actually rebuilding against the new version is the best approach.

@Ansuel

Ansuel commented May 15, 2023

Copy link
Copy Markdown
Member

Linking to python3 without the .10 at the end, is unlikely to actually make things work. You'll just get errors that modules aren't installed, because the module directory is versioned and so are .so compiled extensions.

i see good point... yep i think just compiling python might be a good idea... but it's a real PITA...

@dhewg

dhewg commented May 15, 2023 via email

Copy link
Copy Markdown
Contributor Author

@mcprat

mcprat commented May 16, 2023

Copy link
Copy Markdown
Contributor

I have in my RFC pull request some commits to handle the general stale symlink situation

I'll split it into a new PR

@mcprat

mcprat commented May 16, 2023

Copy link
Copy Markdown
Contributor

also I have #10800

I was going to update it to use a config option but I didn't do so yet, so it's a little stale

@mcprat

mcprat commented May 16, 2023

Copy link
Copy Markdown
Contributor

#12617 for the general symlink case

dhewg added 3 commits May 22, 2023 13:43
Instead of running the python check twice, run it once and
create a python->python3 symbolic link.

Signed-off-by: Andre Heider <a.heider@gmail.com>
That's guaranteed to fail at some point in time, as python itself can
contain breaking changes - like the upcoming v3.12 release, which doesn't
have the distutils module any longer.

Signed-off-by: Andre Heider <a.heider@gmail.com>
v3.12 won't have it anymore.

Signed-off-by: Andre Heider <a.heider@gmail.com>
@dhewg

dhewg commented May 22, 2023

Copy link
Copy Markdown
Contributor Author

Rebased, and reworked the first commit, in case this is still of interest

Comment thread include/prereq-build.mk
python3 -V 2>&1 | grep -E 'Python 3\.([7-9]|[0-9][0-9])\.?'))

$(eval $(call SetupHostCommand,python3,Please install Python >= 3.7, \
python3.11 -V 2>&1 | grep 'Python 3', \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This lacks a check for python3.12

Comment thread include/prereq-build.mk
python3.8 -V 2>&1 | grep 'Python 3', \
python3.7 -V 2>&1 | grep 'Python 3', \
python3 -V 2>&1 | grep -E 'Python 3\.([7-9]|[0-9][0-9])\.?'))
python3 -V 2>&1 | grep -E 'Python 3\.([7-9]|1[0-1])\.?'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only matches Python 3.7-3.11 but not 3.12.

@dhewg

dhewg commented Apr 23, 2024

Copy link
Copy Markdown
Contributor Author

This lacks a check for python3.12

Because this issue is 15 month old.
By now it's safe to assume that this doesn't go any further, so let's just close this (although I still consider the idea behind the patches a good idea)

@dhewg dhewg closed this Apr 23, 2024
@hardfalcon

Copy link
Copy Markdown
Contributor

Because this issue is 15 month old.

Oops. Sorry for the noise, that wasn't intentional. 🙈

@mcprat

mcprat commented Apr 23, 2024

Copy link
Copy Markdown
Contributor

I recommend you reopen and then have only the last commit presented. that's the one that we need and I think everyone would agree with

hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request Apr 23, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
robimarko pushed a commit to hardfalcon/openwrt that referenced this pull request Apr 27, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request Apr 27, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request Apr 27, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request May 1, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request May 1, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request May 1, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request May 1, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
hardfalcon added a commit to hardfalcon/openwrt that referenced this pull request May 2, 2024
After distutils had already been deprecated in Python 3.10 and 3.11, it
has been removed in Python 3.12: https://peps.python.org/pep-0632/

Therefore, limit the python distutils check to Python versions <v3.12.

This commit is mostly just a combination of reverted
commit 7ceb76c "prereq-build: add
Python 3.12 support"
and
commit 8e3a1e2 "prereq-build: limit
python distutils check to <v3.12"
from openwrt#11747

I have merely added the `-e` parameter to the `echo` command in the
fixed distutils check.

Note: This does NOT magically fix code that still relies on distutils.

Co-authored-by: Rosen Penev <rosenp@gmail.com>
Co-authored-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Pascal Ernster <git@hardfalcon.net>
@dhewg
dhewg deleted the pycheck branch June 25, 2024 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build/scripts/tools pull request/issues for build, scripts and tools related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants