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

add support for python importlib to locate MRtrix3 python libraries #2735

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

jdtournier
Copy link
Member

First attempt at addressing #2731...

Seems to work from my limited testing. Main idea is to use importlib (following suggestions from StackOverflow) as long as Python version is 3.5 or newer and importlib module can be loaded successfully. Otherwise fall back to the previous imp approach. Seems to work on my system using either Python 3.10 (using importlib) or Python 2.7 (using imp).

This also falls back to using the (deprecated) imp module to support
Python < 3.5
Copy link
Member

@Lestropie Lestropie left a comment

Choose a reason for hiding this comment

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

Confirmed working for me on both Python 2 and 3 also.

@Lestropie
Copy link
Member

Agree with comment in #2735 that it's ugly. But as long as it works I'm okay with it. With 3.1.0 this will reduce in two ways:

  1. Python2 support is revoked (Drop python2 support #2215), so can use importlib across the board
  2. Function imported() will either disappear or have reduced utilisations. That's there to handle potential discovery of the API through multiple possible mechanisms, at least one of which (looking at the build softlink) will disappear.
    (PR for proposing Python changes following cmake adoption is pending)

@Lestropie Lestropie added this pull request to the merge queue Oct 25, 2023
Merged via the queue into master with commit 5e95b5a Oct 25, 2023
5 checks passed
@Lestropie Lestropie deleted the python_importlib_support branch October 25, 2023 01:54
Lestropie added a commit that referenced this pull request Oct 25, 2023
- Move algorithm code from python/lib/mrtrix3/ to python/src/mrtrix3/.
- Modify python/bin/mrtrix3.py to reflect reduction of number of ways in which the Python API could potentially be found following calling mrtrix3.execute() in an executable command. This additionally includes the transition from the imp module to use importlib due to deprecation; this is a subset of #2735.
- For now, the capturing of the list of MRtrix3 executables in mrtrix3.EXE_LIST is disabled, as it is possible for MRtrix3 to be installed into a location that additionally includes other non-MRtrix3 executables. An alternative solution for this will need to be subsequently implemented.
Lestropie added a commit that referenced this pull request May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants