Skip to content

Update python setup logic #111

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 5 commits into from
Jul 14, 2025
Merged

Update python setup logic #111

merged 5 commits into from
Jul 14, 2025

Conversation

krisfed
Copy link
Member

@krisfed krisfed commented Jul 3, 2025

I've consulted with the Python interface team and reworked the logic for python setup. Changes include:

  1. Moving py.importlib.reload into a separate method, Zarr.pyReloadInProcess(). Reloading of the python module is only needed during development - when the python code is changed and MATLAB is using in-process python. In that case, the developer needs to do the following in order for the updates in the python code to be picked up:
clear classes
Zarr.pyReloadInProcess()

If they are using out-of-process python, they can just do

terminate(pyenv)
  1. Instead of using py.ZarrPy to refer to the Python module, updated the code to always use the return of py.importlib.import_module('ZarrPy'). Using py.ZarrPy should normally work, but there seems to be some issue with that workflow at the moment (especially with out-of-process python). So using the return of py.importlib.import_module('ZarrPy') is currently more robust. We are ok to do multiple calls to py.importlib.import_module('ZarrPy') without any performance penalty, as it internally caches the module after the first call.

  2. Added a test for the new Zarr.pyReloadInProcess() method. It is just a sanity check to make sure using the method does not break any functionality. Since we now have two tests for functions of Zarr class, created a separate tZarr file for those kinds of unit tests.

Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.09%. Comparing base (350881d) to head (a04a72a).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
- Coverage   97.11%   97.09%   -0.03%     
==========================================
  Files           8        8              
  Lines         243      241       -2     
==========================================
- Hits          236      234       -2     
  Misses          7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@krisfed krisfed marked this pull request as ready for review July 10, 2025 16:48
@krisfed krisfed requested review from jm9176 and jhughes-mw July 10, 2025 16:49
zarrPy = py.importlib.import_module('ZarrPy');
end

function pyReloadInProcess()
Copy link
Member

Choose a reason for hiding this comment

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

Where is this called?

Copy link
Member

Choose a reason for hiding this comment

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

NM, I missed the tests. Is it only for the tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for development convenience. If Python is in-process and we modify the Python code, this method can be used after clear classes to reload the Python module to pick up the code changes.

Copy link
Member

Choose a reason for hiding this comment

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

Ahhhh- you could do something like having a constant hidden property that cleans up and executes that function so clear classes would do this automagically.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've discussed different approaches with external interface team and didn't arrive to anything much cleaner, so time-boxed it to this solution. But will follow up with you offline to see if we can improve it.

Copy link
Member

@jm9176 jm9176 left a comment

Choose a reason for hiding this comment

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

Thanks for updating the tests.

@krisfed krisfed merged commit 8898cee into main Jul 14, 2025
6 checks passed
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.

3 participants