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: install to a proper libdir prefix #599

Merged
merged 11 commits into from
Jun 4, 2024
Merged

Conversation

veprbl
Copy link
Contributor

@veprbl veprbl commented May 8, 2024

Currently, the libraries are installed to $PREFIX/python, which is a non-standard prefix. Standard prefix looks more like $PREFIX/lib/python3.XX/site-packages.

BEGINRELEASENOTES

  • The Python library is installed to lib/python3.XX/site-packages instead of python by default. This is a more standard prefix for python packages
    • Use the podio_PYTHON_INSTALLDIR cmake variable to change this.
  • Move python setup and compatibility checks with ROOT python version into a dedicated cmake macro (podio_python_setup)

ENDRELEASENOTES

veprbl added 2 commits May 8, 2024 19:05
Currently, the libraries are installed to `$PREFIX/python`, which is a non-standard prefix. Standard prefix looks more like `$PREFIX/lib/python3.XX/site-packages`.
@tmadlener
Copy link
Collaborator

Linking key4hep/EDM4hep#220 just to have a consistent way of setting this for both. Maybe @andresailer has a preference of the exact technicalities of how we achieve effectively the same path?

python/CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

@andresailer any more comments?

@andresailer
Copy link
Member

I think we need to harmonise a few places where we install python things?

  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages/podio_class_generator.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages/podio_schema_evolution.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/reading.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/__init__.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/base_reader.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/frame_iterator.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/pythonizations
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/pythonizations/__init__.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/pythonizations/collection_subscript.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/pythonizations/utils
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/pythonizations/utils/__init__.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/pythonizations/utils/pythonizer.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/base_writer.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/sio_io.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/frame.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/__version__.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio/root_io.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages/podio_version.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio_gen
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio_gen/__init__.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio_gen/cpp_generator.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio_gen/generator_utils.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio_gen/julia_generator.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio_gen/podio_config_reader.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//podio_gen/generator_base.py
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/selection.xml.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/MutableStruct.jl.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/SIOBlock.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Obj.cc.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Object.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Object.cc.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Collection.cc.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Obj.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/CollectionData.cc.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/CollectionData.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/MutableObject.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Component.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Data.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/DatamodelDefinition.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Interface.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/sioblocks.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/interface.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/utils.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/collections.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/julia_helpers.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/implementations.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/iterator.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/macros/declarations.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/CMakeLists.txt
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/ParentModule.jl.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/SIOBlock.cc.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Component.cc.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/MutableObject.cc.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/Collection.h.jinja2
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/schemaevolution
  -- Installing: /home/runner/work/podio/podio/install/lib64/python3.10/site-packages//templates/schemaevolution/EvolvePOD.h.jinja2

@tmadlener
Copy link
Collaborator

I think most of this is OK? And since EDM4hep builds downstream with this at least what we install and offer via CMake to downstream is consistent.

What would you place differently?

@andresailer
Copy link
Member

I would put everything under site-packages/podio. Probably would mean some site-packages/podio/podio ?

@tmadlener
Copy link
Collaborator

Ah yes, that would make sense I think. Or maybe put the templates into podio_gen? That would then only leave

  • podio_version.py
  • podio_class_generator.py
  • podio_schema_evolution.py

at the top level directory.

@hegner
Copy link
Collaborator

hegner commented May 17, 2024

sounds like a better convention to me

@andresailer
Copy link
Member

Rename podio_gen to gen, and place inside podio/gen Change imports to start with from podio. ?

@tmadlener
Copy link
Collaborator

And then still install to <the-rest>/site-packages/podio? I.e. still having site-packages/podio/podio?

Regardless, I would move the templates into podio_gen (or podio/gen).

@hegner
Copy link
Collaborator

hegner commented May 17, 2024

Yes, podio/gen would be best

@tmadlener
Copy link
Collaborator

I think I just remembered why we have podio_gen and not podio/gen, see #511 @jmcarcell bringing podio_gen back into podio/gen would mean quite a bit of slow down for the generation, right?

@hegner
Copy link
Collaborator

hegner commented May 17, 2024

Damn. Indeed that would be a bit awful...

@andresailer
Copy link
Member

Let's leave it as is then.

@jmcarcell
Copy link
Member

jmcarcell commented May 21, 2024

Keeping podio_gen separated from the rest lets us run without loading anything related generation and generate without loading the rest of podio so I think it's fine as it is.

Indeed we have many repos that use python that we may also want to change:

$ /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2024-05-09/x86_64-almalinux9-gcc11.4.1-opt# find . -maxdepth 4 -iname "python"
./dual-readout/51f9766bb3f9e80644bb032b98f1f5b1d4cb0327_develop-xnlqg4/python
./edm4hep/181745967206fa03b1c6a9aa26b947d4b74aeaf4_develop-mqna4k/python
./gaudi/38.1-kpe2ng/python
./k4clue/efbd91e8accafb95441e6106558db8f9f84639d6_develop-eupqww/python
./k4fwcore/6c55ebd2230133761edf0f45ea69e84c8434a6cd_develop-dbkcrr/python
./k4gen/bf49029a914e7f5fbd09a2954d6dc449978b0c9f_develop-jn3s52/python
./k4marlinwrapper/0493cfd4516a3f495c890160d0e45b69bc0ddeaa_develop-snuqhn/python
./k4projecttemplate/c1af0d0e4eb8d2713cb2caae3c4fe8a245274ca0_develop-3wbpbv/python
./k4reccalorimeter/255127a703c3b623bdde479ddefdf68cf90ae452_develop-q4ggwa/python
./k4rectracker/871276d03db4d1a92f600eb41ea1213220a7cdf2_develop-vrso36/python
./k4simdelphes/7370e7edeb133680772d5f534b8e88ce0c61644c_develop-l3wfci/python
./k4simgeant4/89f0ac0f510b5dd8715537e04782f70bf478ad2f_develop-w46v7x/python
./lcio/e8c5032e261708f03514379decd7375038722025_develop-rq2agf/python
./podio/a18229b9b1f1db6530dec0bd7c6e48f26a0a5f9f_develop-56qqgq/python
./python
./python/3.10.13-vrpxgy/bin/python
./fccanalyses/6d43e284688a0f33f2a5186d69f7f13544e7fb21_develop-ojqkm4/python
./fccsw/e103621518b26bb18f5b928fcc1dc8c5c8c0d737_develop-gmftmc/python

After this change the spack recipe needs to be updated (spack/spack#44291) and I think k4_local_repo also needs to be updated and that should be all if I'm not missing anything.

@haampie
Copy link

haampie commented May 21, 2024

Got here through the Spack PR.

This

${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages

looks sensible, but unclear if CMAKE_INSTALL_LIBDIR is guaranteed to be correct, since Python may use lib while CMake uses lib64 or the other way around.

The source of truth is

python3 -c "import sysconfig, sys; sys.stdout.write(sysconfig.get_path('platlib'))"

which CMake provides through Python_SITEARCH if you're using FindPython.cmake.

The issue is that this is an absolute path to the system site packages dir, idk how you get just the relative bits lib/python3.11/site-packages in a canonical way from there.

I would recommend letting users pass the Python install dir as a cmake variable, cause in Spack we expose <package prefix>/<python platdir> so users can pass it to build systems, and I can imagine that non-Spack users may still wanna choose where they put the Python package (maybe the python package goes in a venv but the rest in CMAKE_INSTALL_PREFIX?)

@veprbl
Copy link
Contributor Author

veprbl commented May 21, 2024

@haampie See also the original version. It's probably not platlib, but purelib, and would not need a multilib prefix. Python_SITEARCH is probably a bad idea, it would try to install to a system-wide python location.

@jmcarcell
Copy link
Member

jmcarcell commented May 21, 2024

Than after the comments from @haampie, I think the answer would be something like:

find_package(Python3 REQUIRED)
set(PYTHON_LIB_DIR lib)
if("${Python3_SITEARCH}" MATCHES "/lib64/")
  set(PYTHON_LIB_DIR lib64)
endif()

set(podio_PYTHON_INSTALLDIR "${CMAKE_INSTALL_PREFIX}/${PYTHON_LIB_DIR}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages")
set(podio_PYTHON_INSTALLDIR ${podio_PYTHON_INSTALLDIR} PARENT_SCOPE)

For the rest of the comment I think our users don't care where the python packages are installed as long as it works.

@tmadlener
Copy link
Collaborator

I have now implemented the following:

  • podio_PYTHON_INSTALLDIR is a configurable CMAKE variable
  • It defaults to `/lib[64]/pythonX.YY/site-packages', where
    • lib or lib64 is decided via the contents of Python3_SITEARCH as shown in the comment above
    • X.YY is taken from Python3_MAJOR_VERSION and Python3_MINOR_VERSION
  • All of this setup and the compatibility check with the python version that has been used to build ROOT now lives in the podio_python_setup macro.

@veprbl unless you have any objections, I would rebase this onto the latest master/main before we merge it.

@veprbl
Copy link
Contributor Author

veprbl commented Jun 3, 2024

Thanks for taking care of this, @tmadlener. It looks fine to me.

@tmadlener
Copy link
Collaborator

I checked that this works as expected locally with spack and extends("python"). I will open a PR shortly for picking this up there.

@tmadlener tmadlener merged commit 3637954 into AIDASoft:master Jun 4, 2024
18 checks passed
jmcarcell added a commit to jmcarcell/podio that referenced this pull request Jun 4, 2024
Changed in AIDASoft#599, but the
change is also needed in these two places
tmadlener pushed a commit that referenced this pull request Jun 4, 2024
Changed in #599, but the
change is also needed in these two places

Co-authored-by: jmcarcell <[email protected]>
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.

6 participants