Skip to content

Probe matlab folders at runtime#56

Open
t20100 wants to merge 3 commits intomathworks:R2025afrom
t20100:probe-matlab-at-runtime
Open

Probe matlab folders at runtime#56
t20100 wants to merge 3 commits intomathworks:R2025afrom
t20100:probe-matlab-at-runtime

Conversation

@t20100
Copy link
Copy Markdown

@t20100 t20100 commented Aug 21, 2025

This PR proposes a minimal implementation of probing matlab installation paths at runtime from the commands in $PATH rather than at build time (Related to #45):

  • Use _arch.txt file if it is in the package
  • Use shutil.which('matlab') as a fallback
  • Add the option in setup.py to build without _arch.txt, e.g. to generate a wheel.

I tested it on Linux and it should work on macos.

A more involved option would be to move the code finding matlab from setup.py into matlab-engine and call it at runtime rather than storing the info in _arch.txt + a fallback using shutil.which('matlab')

@t20100 t20100 force-pushed the probe-matlab-at-runtime branch from 7a06dda to 75f9416 Compare August 21, 2025 14:01
Comment thread setup.py
"""
Returns True if matlab folders should be configured at build time
"""
return os.environ.get('MATLAB_ENGINE_CONFIGURE_ROOT', 'true').lower() in ('true', '1')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Use env.var. to pass options, it could be replaced with extra build arguments

Comment thread src/matlab/_utils.py


@functools.cache
def get_path_info() -> MatlabPathInfo:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Read _arch.txt and use which matlab as fallback.
This could be more involved and use the whole _MatlabFinder logic.

if _envs[_arch] in os.environ:
_env = os.environ[_envs[_arch]]
os.environ[_envs[_arch]] = _bin_dir + os.pathsep + os.environ[_envs[_arch]]
_path_info = _utils.get_path_info()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Reuse path info rather than re-reading the file

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.

1 participant