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

use python_DISTLIB #1023

Merged
merged 8 commits into from
Apr 25, 2023
Merged

use python_DISTLIB #1023

merged 8 commits into from
Apr 25, 2023

Conversation

huangminghuang
Copy link
Contributor

@huangminghuang huangminghuang commented Apr 12, 2023

This PR

  • uses ${Python_DISTLIB} as the location for installing python modules,
  • add CI package installation test for TestHarness.

Resolves #839

@heifner heifner added the OCI Work exclusive to OCI team label Apr 12, 2023
Copy link
Contributor

@oschwaldp-oci oschwaldp-oci left a comment

Choose a reason for hiding this comment

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

In light of comment: #818 (comment), the use of FindPackage(Python) at build time verses the discovery and setting of Python_SITELIB at installation time - The reason for the decision to opt for the installation time choice was to more accurately reflect and support the use case where build machine and install machine could be different and the location on the installation machine is what is important here.

@heifner heifner added this to the Leap v5.0.0-rc1 milestone Apr 13, 2023
@heifner heifner requested a review from ScottBailey April 13, 2023 21:14
@@ -1,13 +1,11 @@
#!/bin/sh

set -e
Python_SITELIB=$(python3 -c "from distutils import sysconfig;print(sysconfig.get_python_lib(plat_specific=False,standard_lib=False))")
Copy link
Contributor

Choose a reason for hiding this comment

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

As of python 3.10 (in Ubuntu 22), distutils is deprecated. It will be removed in 3.12. Additionall pain: distutils must be installed before use!

I'm not 100% certain this suggestion works in non Debian derived environments, but it works in my Debain Python 3.11 environment as well as a mostly vanilla Ubuntu 18 environment. Here is the documentation on Debian dist-packages.

Suggested change
Python_SITELIB=$(python3 -c "from distutils import sysconfig;print(sysconfig.get_python_lib(plat_specific=False,standard_lib=False))")
Python_SITELIB=$(python3 -c "import sysconfig; print(sysconfig.get_path('stdlib'))")/dist-packages

If this is not the solution, we should find a better solution than distutils.

Copy link
Member

Choose a reason for hiding this comment

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

I couldn't get that to work in Ubuntu nor Debian

# ls $(python3 -c "import sysconfig; print(sysconfig.get_path('stdlib'))")/dist-packages
ls: cannot access '/usr/lib/python3.8/dist-packages': No such file or directory

Copy link
Member

Choose a reason for hiding this comment

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

I think you want platlib

# python3 -c "import sysconfig;  print(sysconfig.get_path('platlib'))"
/usr/lib/python3.9/site-packages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, it is implemented with python3 -c "import sysconfig; print(sysconfig.get_path('purelib'))" as described in https://cmake.org/cmake/help/latest/module/FindPython3.html

Copy link
Contributor

Choose a reason for hiding this comment

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

According to that link, dist-packages seem to be the correct path. I wonder if we need to mkdir -p to ensure it exists. @spoonincode This worked for me in Debian 11/12 and Ubuntu 18.

Copy link
Contributor

Choose a reason for hiding this comment

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

purelib seems to be the correct answer. :-) Approved.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure we should be installing into site-packages?

dist-packages instead of site-packages. Third party Python software installed from Debian packages goes into dist-packages, not site-packages. This is to reduce conflict between the system Python, and any from-source Python build you might install manually.
https://wiki.debian.org/Python

# Also may have already existed, so it is acceptable to leave them in place if the rmdir fails
rmdir --ignore-fail-on-non-empty ${CMAKE_INSTALL_FULL_LIBDIR}/python3/dist-packages
rmdir --ignore-fail-on-non-empty ${CMAKE_INSTALL_FULL_LIBDIR}/python3
Python_SITELIB=$(python3 -c "from distutils import sysconfig;print(sysconfig.get_python_lib(plat_specific=False,standard_lib=False))")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue with distutils as noted in scripts/postinst.

Copy link
Contributor

@ScottBailey ScottBailey left a comment

Choose a reason for hiding this comment

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

See comments: distutils requires install and is deprecated.

Copy link
Member

@spoonincode spoonincode left a comment

Choose a reason for hiding this comment

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

holding

@spoonincode
Copy link
Member

When I try to install the package, I get

ln: failed to create symbolic link '/usr/lib/python3.8/site-packages/TestHarness': No such file or directory

I'm not sure if we're expected to create site-packages or what...

@spoonincode
Copy link
Member

It installs now but I don't think this location is searched by default...

# python3 -c 'from TestHarness import Cluster, TestHelper'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'TestHarness'
# ls /usr/lib/python3.8/site-packages/
TestHarness
# python3 -c 'import sys; print(sys.path)'
['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']

Don't we want this installed in to the default module search path?

@huangminghuang huangminghuang changed the title use python_SITELIB use python_DISTLIB Apr 18, 2023
Copy link
Contributor

@ScottBailey ScottBailey left a comment

Choose a reason for hiding this comment

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

I think we need to look at how official Ubuntu and Debian packages set distlib.

scripts/prerm Outdated
# Also may have already existed, so it is acceptable to leave them in place if the rmdir fails
rmdir --ignore-fail-on-non-empty ${CMAKE_INSTALL_FULL_LIBDIR}/python3/dist-packages
rmdir --ignore-fail-on-non-empty ${CMAKE_INSTALL_FULL_LIBDIR}/python3
Python_DISTLIB=$(python3 -c "import sysconfig; print(sysconfig.get_path('purelib'))" | sed 's/site-packages/dist-packages/')
Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't think this is the right answer.

Copy link
Member

Choose a reason for hiding this comment

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

I agree. Something feels wrong about the trouble we're having here and that's usually a reasonable indicator we're on the wrong path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation is based on the description of https://wiki.debian.org/Python, first point of the section Deviations from upstream. In debian/Ubuntu, using the deprecated distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False) does return the right answer /usr/lib/python3/dist-packages while using sysconfig does not. Based on the StackOverflow post

The root cause of the discrepancy is because Debian patch the distutils install layout, to correctly reflect their changes to the site, but they fail to patch the sysconfig module.

I am not sure how to move forward from here. Here are the list of solutions I can think of (I am welcome any other solutions)

  • just use /usr/lib/python3/dist-packages,
  • use distutils (at least it's still available in our supported distributions),
  • keep the current implementation.

Copy link
Member

Choose a reason for hiding this comment

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

I think my vote is to just use distutils and sort out the problem with python 3.12 + ubuntu when that actually arrives.

Copy link
Contributor

Choose a reason for hiding this comment

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

As much as I dislike using distutils, it seems like the least painful solution.

export DEBIAN_FRONTEND=noninteractive
export TZ="America/New_York"
apt install -y ./build/leap_*.deb
apt install -y ./build/leap-dev*.deb
Copy link
Member

Choose a reason for hiding this comment

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

I want to keep the workflow as concise and clutter free as possible, so two changes I'd like here:

  1. move the DEBIAN_FRONTEND and TZ to the Dockerfile
  2. combine the two installs, either as ./build/leap_*.deb ./build/leap-dev*.deb or ./build/leap*.deb or whatever

@@ -103,12 +103,21 @@ jobs:
zstdcat build.tar.zst | tar x
cd build
cpack
- name: Install dev package
run: |
apt update
Copy link
Member

Choose a reason for hiding this comment

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

Should be update && upgrade here? I'm not sure how problematic it will be on Ubuntu to have "mixed age" packages installed: the base image is cached and could have many month old packages installed alongside new packages installed here.

@huangminghuang huangminghuang merged commit 101f11f into main Apr 25, 2023
@huangminghuang huangminghuang deleted the huangminghuang/python-sitelib branch April 25, 2023 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCI Work exclusive to OCI team
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Address TestHarness installation location
5 participants