-
Notifications
You must be signed in to change notification settings - Fork 28
Attempt to write python-search-path docs #348
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8b569c8
Attempt to write python-search-path docs
Micket bbab73e
Typo fix from @verdurin
Micket c24bc10
Typo fix from @verdurin
Micket 156ede7
Typo fix from @verdurin
Micket 71c01f7
Typo fix from @verdurin
Micket 69032fe
Typo fix from @verdurin
Micket 9e7d6c8
Typo fix from @verdurin
Micket 8114ecd
Apply suggestion from @verdurin
Micket 6b1ee82
Apply suggestion from @verdurin
Micket 831c7f1
Apply suggestion from @smoors
Micket 2263927
Apply suggestion from @verdurin
Micket 9833430
Apply suggestion from @smoors
Micket ea7af4b
Apply suggestion from @smoors
Micket 1fd3c60
Apply suggestion from @smoors
Micket e30e7e3
Apply suggestion from @smoors
Micket e12f631
Update docs/python-search-path.md
Micket bfa4584
Update docs/python-search-path.md
Micket 576b596
Update mkdocs.yml
Micket d2182d6
Update docs/python-search-path.md
Micket File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Python search path | ||
|
|
||
| In order to locate python packages in modules, easybuild has conventionally used the `PYTHONPATH` environment variable. However, this has several issues: | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
smoors marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. `PYTHONPATH` has highest priority; it prevents users from makinga custom virtual environment on top of modules and shadowing packages. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 2. Packages are picked up even for incompatible python versions, e.g. an OS installed old python 3.6 will break if packages from 3.12 exists in `PYTHONPATH`. | ||
| 3. Modules can't have optional dependencies on different Python versions, as PYTHONPATH points directly to the `site-packages` subdirectory. | ||
| 4. Packages with `pth` files can't work with PYTHONPATH and requires being added to the site dir. | ||
|
|
||
| Unfortuanately, Python offers to environment variables to do the correct thing here. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| To solve this (initially for multi-deps) EasyBuild has for a long time supported the use of the custom `EBPYTHONPREFIXES` via a `sitecustomize.py` script for the Python modules we build. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| It is included in standard Python installations made with easybuild. You can opt out of having this `sitecustomize.py` if you have strong technical reasons to avoid it. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This does the correct thing by only considering the correct Python version, and puts the module provided python packages at the lowest priority path, allowing a user venv to shadow the packages correctly. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Using `--prefer-python-search-path` | ||
|
|
||
| Since v5.0.0 the new global configuration option `--prefer-python-search-path` can be used to EasyBuild prefer the use of either `PYTHONPATH` or `EBPYTHONPREFIXES`. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| For backwards compatibility with existing modules, EasyBuild was unfortunately required to keep `PYTHONPATH` as the default. | ||
| Note that the option is just the preferred option, if the package path doesn't follow the standard `lib/pythonY.X/site-packages` format then PYTHONPATH must be used. If ulti-deps is used, then `EBPYTHONPREFIXES` is required. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If you wish to switch to `EBPYTHONPREFIXES`, you should also traverse the existing python bundles you have installed and make sure to rebuild the modules. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Failure to do so might leave you with a few easyconfigs that requiring shadowing of older package versions not working correctly due to the import priority changing. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If you are swithing to building a new tree, you can safely switch this option to `EBPYTHONPREFIXES` and enjoy the benefits. | ||
Micket marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Fixing existing modules | ||
|
|
||
| You can convert existing modules by rebuilding them with `eb --module-only --rebuild ...`. | ||
| You can find the modules that use `PYTHONPATH` by e.g. grepping through your modules: | ||
|
|
||
| ```bash | ||
| grep --include '*.lua' -Rl 'PYTHONPATH.*site-packages' /path/to/modules/all | ||
| ``` | ||
|
|
||
| If you use the default module naming scheme | ||
|
|
||
| ```bash | ||
| cd $MODULEPATH | ||
| grep -Rl PYTHONPATH */*.lua | grep -v EasyBuild | sed -e 's+/+-+' | sed -e 's+lua$+eb+' | xargs eb --rebuild --module-only | ||
| ``` | ||
|
|
||
| If done correctly, your old module files will have gone from | ||
|
|
||
| ```lua | ||
| prepend_path("PYTHONPATH", pathJoin(root, "lib", "python3.12", "site-packages")) | ||
| # or | ||
| prepend_path("PYTHONPATH", pathJoin(root, "lib/python3.12/site-packages")) | ||
| ``` | ||
|
|
||
| to | ||
|
|
||
| ```lua | ||
| prepend_path("EBPYTHONPREFIXES", root) | ||
| ``` | ||
|
|
||
| Remember to back up all your module files first before rebuilding. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.