Skip to content

Conversation

casparvl
Copy link
Contributor

@casparvl casparvl commented Jul 30, 2025

This change introduces extra easyblock-specific configuration items. They allow us to define patches that should be applied conditionally if EasyBuild is configured to filter LD_LIBRARY_PATH. Since these patches (see Should be used together with: easybuilders/easybuild-easyconfigs#23499) are quite fundamental (change ctypes functions) we prefer them to only be applied in the scenario where they are really needed.

Replaces: #3798
Should be used together with: easybuilders/easybuild-easyconfigs#23499

edit: relevant EESSI support issue: https://gitlab.com/eessi/support/-/issues/154

@casparvl casparvl changed the title Use patch when filter ld library path Ptyhon: conditionally add patches when EasyBuild is configured to filter LD_LIBRARY_PATH Jul 30, 2025
@casparvl casparvl changed the title Ptyhon: conditionally add patches when EasyBuild is configured to filter LD_LIBRARY_PATH Python: conditionally add patches when EasyBuild is configured to filter LD_LIBRARY_PATH Jul 30, 2025
casparvl pushed a commit to casparvl/easybuild-easyconfigs that referenced this pull request Jul 30, 2025
casparvl and others added 2 commits July 30, 2025 14:03
Co-authored-by: ocaisa <alan.ocais@cecam.org>
@boegel boegel changed the title Python: conditionally add patches when EasyBuild is configured to filter LD_LIBRARY_PATH conditionally add patches fo Python when EasyBuild is configured to filter LD_LIBRARY_PATH Jul 30, 2025
@boegel boegel changed the title conditionally add patches fo Python when EasyBuild is configured to filter LD_LIBRARY_PATH add support to Python easyblock for conditionally adding patches when EasyBuild is configured to filter LD_LIBRARY_PATH Jul 30, 2025
@boegel boegel added this to the 5.x milestone Jul 30, 2025
@boegel
Copy link
Member

boegel commented Aug 12, 2025

Code style check still fails:

./easybuild/easyblocks/p/python.py:386:23: F541 f-string is missing placeholders
./easybuild/easyblocks/p/python.py:387:24: F541 f-string is missing placeholders
./easybuild/easyblocks/p/python.py:393:5: E303 too many blank lines (2)

@casparvl
Copy link
Contributor Author

@boegelbot please test @ jsc-zen3
EB_ARGS="Python-3.11.5-GCCcore-13.2.0.eb Python-3.12.3-GCCcore-13.3.0.eb Python-3.13.1-GCCcore-14.2.0.eb"

@boegelbot
Copy link

@casparvl: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=3860 EB_ARGS="Python-3.11.5-GCCcore-13.2.0.eb Python-3.12.3-GCCcore-13.3.0.eb Python-3.13.1-GCCcore-14.2.0.eb" EB_CONTAINER= EB_REPO=easybuild-easyblocks EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_3860 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 7768

Test results coming soon (I hope)...

- notification for comment with ID 3228197327 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@casparvl
Copy link
Contributor Author

casparvl commented Aug 27, 2025

Test report by @casparvl

Overview of tested easyconfigs (in order)

  • SUCCESS Python-3.11.5-GCCcore-13.2.0.eb
  • SUCCESS Python-3.12.3-GCCcore-13.3.0.eb
  • SUCCESS Python-3.13.1-GCCcore-14.2.0.eb

Build succeeded for 3 out of 3 (3 easyconfigs in total)
tcn358.local.snellius.surf.nl - Linux RHEL 9.4, x86_64, AMD EPYC 7H12 64-Core Processor, Python 3.9.18
See https://gist.github.com/casparvl/f13c0fa1d22f6a8c060edf8f1ec54f4a for a full test report.

Edit: note that these were all without the changes from easybuilders/easybuild-easyconfigs#23499 i.e. just to prove that this PR doesn't change any existing behavior and still works when EB is NOT configured to filter LD_LIBRARY_PATH.

@boegelbot
Copy link

Test report by @boegelbot

Overview of tested easyconfigs (in order)

  • SUCCESS Python-3.11.5-GCCcore-13.2.0.eb
  • SUCCESS Python-3.12.3-GCCcore-13.3.0.eb
  • SUCCESS Python-3.13.1-GCCcore-14.2.0.eb

Build succeeded for 3 out of 3 (3 easyconfigs in total)
jsczen3c1.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.6, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.21
See https://gist.github.com/boegelbot/ed316fef093d4d6b7b54b7e01c59a848 for a full test report.

@boegel boegel changed the title add support to Python easyblock for conditionally adding patches when EasyBuild is configured to filter LD_LIBRARY_PATH add support to Python easyblock for conditionally adding patches when EasyBuild is configured to filter $LD_LIBRARY_PATH Aug 27, 2025
Caspar van Leeuwen added 2 commits October 13, 2025 17:35
…s_ld_library_path. use self.cfg.get. Also check for not filtering LIBRARY_PATH. Make sure to update the rest of the code for these name changes (and the fact that patch_ctypes_ld_library_path is now the name of a single patch fle, not a list.
Copy link
Contributor Author

@casparvl casparvl left a comment

Choose a reason for hiding this comment

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

TODO: remark by @boegel is that we should have a sanity check that checks if the patch was applied, or more specifically, that the behavior is now correct. Since system libraries are system-specific, the only thing we can do is check if a library on LIBRARY_PATH is found correctly. E.g. we could try to load libpython3.so through a CDLL and a LoadLibrary call, and even call a find_library on it for good measure.

Caspar van Leeuwen added 4 commits October 14, 2025 21:07
if (
'LD_LIBRARY_PATH' in filtered_env_vars and
'LIBRARY_PATH' not in filtered_env_vars and
patch_ctypes_ld_library_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.

Should we remove the condition that a patch is applied? In other words: should we allow a user to build with filtered LD_LIBRARY_PATH but without the patch? (currently, that is allowed, the user will just receive a warning from the elif on line 397

@casparvl
Copy link
Contributor Author

Ok, sanity check seems to work as intended. Using the patch from easybuilders/easybuild-easyconfigs#23499 I get a successful sanity check, with this in the debugging output:

== 2025-10-15 10:53:41,597 run.py:457 INFO run_shell_cmd: command environment of "python -c 'import ctypes; print(ctypes.CDLL("libpython3.so"))'" will be saved to /scratch-local/casparl.15333717/eb-g6qr2e5w/run-shell-cmd-output/python-utohkjqy
== 2025-10-15 10:53:41,597 run.py:460 INFO run_shell_cmd: Output of "python -c 'import ctypes; print(ctypes.CDLL("libpython3.so"))'" will be logged to /scratch-local/casparl.15333717/eb-g6qr2e5w/run-shell-cmd-output/python-utohkjqy/out.txt
== 2025-10-15 10:53:41,617 run.py:494 INFO Path to bash that will be used to run shell commands: /cvmfs/software.eessi.io/versions/2023.06/compat/linux/x86_64/bin/bash
== 2025-10-15 10:53:41,617 run.py:508 INFO Running shell command 'python -c 'import ctypes; print(ctypes.CDLL("libpython3.so"))'' in /tmp/casparl/easybuild/build/Python/3.11.5/GCCcore-13.2.0/pip/pip-23.2.1
== 2025-10-15 10:53:42,135 run.py:622 INFO Shell command completed successfully: python -c 'import ctypes; print(ctypes.CDLL("libpython3.so"))'
== 2025-10-15 10:53:42,135 run.py:624 INFO Output of 'python ...' shell command (stdout + stderr):
<CDLL '/home/casparl/eessi/versions/2023.06/software/linux/x86_64/amd/zen2/software/Python/3.11.5-GCCcore-13.2.0/lib/../lib64/libpython3.so', handle 11ed940 at 0x1456f50afb10>

== 2025-10-15 10:53:42,138 python.py:748 DEBUG Matching regular expression pattern ^<CDLL '/home/casparl/eessi/versions/2023\.06/software/linux/x86_64/amd/zen2/software/Python/3\.11\.5\-GCCcore\-13\.2\.0.*', handle [a-f0-9]+ at 0x[a-f0-9]+>$ to string <CDLL '/home/casparl/eessi/versions/2023.06/software/linux/x86_64/amd/zen2/software/Python/3.11.5-GCCcore-13.2.0/lib/../lib64/libpython3.so', handle 11ed940 at 0x1456f50afb10>
== 2025-10-15 10:53:42,138 python.py:752 INFO Call to ctypes.CDLL('libpython3.so') succesfully opened libpython3.so, indicating that the patch that fixes ctypes when EasyBuild is configured to filter LD_LIBRARY_PATH was applied succesfully.

If I use a dummy patch that just inserts some comments, I get:

== FAILED: Installation ended unsuccessfully: Opening of libpython3.so using ctypes.CDLL('libpython3.so') failed. Ctypes requires a patch when
EasyBuild is configured to filter LD_LIBRARY_PATH. Please check if you specified a patch through patch_ctypes_ld_library_path and check the
logs to see if it applied correctly. (took 12 mins 41 secs)
== Results of the build can be found in the log file(s)
/scratch-local/casparl.15371430/eb-h2rz1r18/easybuild-Python-3.11.5-20251015.104150.PXTEX.log
== Running post-easyblock hook...
== Summary:
   * [FAILED]  Python/3.11.5-GCCcore-13.2.0

ERROR: Installation of Python-3.11.5-GCCcore-13.2.0.eb failed: "Opening of libpython3.so using ctypes.CDLL('libpython3.so') failed. Ctypes requires a patch when EasyBuild is configured to filter LD_LIBRARY_PATH. Please check if you specified a patch through patch_ctypes_ld_library_path and check the logs to see if it applied correctly."

@casparvl
Copy link
Contributor Author

@boegelbot please test @ jsc-zen3
EB_ARGS="Python-3.11.5-GCCcore-13.2.0.eb Python-3.12.3-GCCcore-13.3.0.eb Python-3.13.1-GCCcore-14.2.0.eb"

@boegelbot
Copy link

@casparvl: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=3860 EB_ARGS="Python-3.11.5-GCCcore-13.2.0.eb Python-3.12.3-GCCcore-13.3.0.eb Python-3.13.1-GCCcore-14.2.0.eb" EB_CONTAINER= EB_REPO=easybuild-easyblocks EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_3860 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 8415

Test results coming soon (I hope)...

- notification for comment with ID 3407980100 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@boegelbot
Copy link

Test report by @boegelbot

Overview of tested easyconfigs (in order)

Build succeeded for 2 out of 3 (3 easyconfigs in total)
jsczen3c3.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.6, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.21
See https://gist.github.com/boegelbot/321093a94c35bb285ea06efca5fe4069 for a full test report.

@casparvl
Copy link
Contributor Author

3.11.5 failed because I was rebuilding that in easybuilders/easybuild-easyconfigs#23499 as well, so lock file existed. Trying again for good measure...

@boegelbot please test @ jsc-zen3
EB_ARGS="Python-3.11.5-GCCcore-13.2.0.eb"

@boegelbot
Copy link

@casparvl: Request for testing this PR well received on jsczen3l1.int.jsc-zen3.fz-juelich.de

PR test command 'if [[ develop != 'develop' ]]; then EB_BRANCH=develop ./easybuild_develop.sh 2> /dev/null 1>&2; EB_PREFIX=/home/boegelbot/easybuild/develop source init_env_easybuild_develop.sh; fi; EB_PR=3860 EB_ARGS="Python-3.11.5-GCCcore-13.2.0.eb" EB_CONTAINER= EB_REPO=easybuild-easyblocks EB_BRANCH=develop /opt/software/slurm/bin/sbatch --job-name test_PR_3860 --ntasks=8 ~/boegelbot/eb_from_pr_upload_jsc-zen3.sh' executed!

  • exit code: 0
  • output:
Submitted batch job 8416

Test results coming soon (I hope)...

- notification for comment with ID 3408456358 processed

Message to humans: this is just bookkeeping information for me,
it is of no use to you (unless you think I have a bug, which I don't).

@boegelbot
Copy link

Test report by @boegelbot

Overview of tested easyconfigs (in order)

  • SUCCESS Python-3.11.5-GCCcore-13.2.0.eb

Build succeeded for 1 out of 1 (1 easyconfigs in total)
jsczen3c2.int.jsc-zen3.fz-juelich.de - Linux Rocky Linux 9.6, x86_64, AMD EPYC-Milan Processor (zen3), Python 3.9.21
See https://gist.github.com/boegelbot/6cb03b081d28cc424efa14fd78aff697 for a full test report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

EESSI Related to EESSI project enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants