matlabdomain icon indicating copy to clipboard operation
matlabdomain copied to clipboard

Autoapplication directive does not document source code

Open QTBdev opened this issue 2 years ago • 5 comments

Hello,

Autoapplication directive does not document the application source code, as only the metadata files are read by the parse_mlappfile function.

I understand that this limitation is most probably due to the fact that the source code is stored in a .mat file inside the .mlapp archive, instead of the usual .m file, and that reading a .mat file outside matlab is not a simple task.

Still I wanted to make this info show up on the project somewhere because I spent a good amount of time trying to understand why it wouldn't autodocument my application.

QTBdev avatar Apr 15 '22 12:04 QTBdev

Hi

I haven't used App Designer myself, so I would like to know what extra information that you need from the file? Could you share a simple App and what you expect to be documented?

joeced avatar Apr 20 '22 09:04 joeced

Hello,

Of course, you will find attached an archive containing :

  • A simple application example
  • A class created by copy-pasting the whole application source code into a brand new .m file
  • And the sphinx generated documentation of both of them

I expected autoapplication to document the application just like autoclass documents the class created with the exact same source code, but the parse_mlappfile function does not look into the file that contains the application source code autoapplicationTest.zip .

QTBdev avatar Apr 20 '22 15:04 QTBdev

Thanks for the example! I think I found a way to get the documentation you expected. As the mlapp file is just a ZIP-file, I examined every file in there.

In <root>/matlab/document.xml there is a verbatim copy of the code that is used in the App. We can extract that, and parse it, and then we should be able to get the documentation you want.

joeced avatar Apr 21 '22 07:04 joeced

That would be great ! I knew the application source code was stored in <root>/appdesigner/appModel.mat, but I didn't realise a copy was also available in this file

QTBdev avatar Apr 21 '22 08:04 QTBdev

I took a look at it, and frankly I'm not sure how to proceed exactly.

In the parse_mlappfile function in mat_types.py I can extract the MATLAB code with:

with ZipFile(mlappfile, "r") as mlapp:
    document = ET.fromstring(mlapp.read("matlab/document.xml"))

documentNs = {"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"}
documentDesc = document.find(".//w:t", documentNs)

Then documentDesc will contain a verbatim copy of your MATLAB code in the app. However, most of this is private methods, even the callbacks. So you would end up with a ton of noise, and very little information.

If anyone has a good idea on how to present this, then please provide a PR.

joeced avatar Mar 15 '23 09:03 joeced