Skip to content

Fix issue where python's sys.module dict fails to convert to a MATLAB dictionary #109

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ehennestad
Copy link

Fix issue #68

The following line in Zarr/pySetup attempts to convert the sys.modules python dict to a MATLAB dictionary.

loadedModules = dictionary(sys.modules);

When running this, I get the following error:

Error using six>__get__
Python Error: AttributeError: 'NoneType' object has no attribute 'BaseHTTPServer'

I have not explored why, but I assume I have a python module installed which fails to convert to a MATLAB type.

Here I propose to only convert the keys of the dict to a string array and check if ZarrPy is part if that array. I also added try catch to ensure there is a fallback if the check fails.

Convert keys to MATLAB keys instead of full dictionary
Fix bug. Add missing not
@ehennestad
Copy link
Author

ehennestad commented Jul 1, 2025

An alternative that uses python instead of converting to MATLAB types:

pyContainsModuleFcn = py.getattr(sys.modules, '__contains__');
requiresZarrPyReload = ~pyContainsModuleFcn("ZarrPy");

@krisfed
Copy link
Member

krisfed commented Jul 3, 2025

Hello Eivind,

Thank you for your interest in the project - for creating issues and for this pull request!

Apologies for the issues with pySetup - I was hoping to rework this logic there sometime soon as well. But happy to merge this in the meantime (and to receive any future pull requests!).

We will need to send you a CLA to sign as part of the policy if this is your first submission to the MathWorks github organization. I will reach out by email to handle that.

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.

2 participants