Skip to content

Commit 07a54f5

Browse files
committed
parse Matlab VersionInfo.xml from Python
1 parent 7d49912 commit 07a54f5

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

scripts/get_matlab_version_xml.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import argparse
2+
import xml.etree.ElementTree as ET
3+
import shutil
4+
from pathlib import Path
5+
6+
7+
def get_matlab_root() -> Path:
8+
ml = shutil.which("matlab")
9+
if ml is None:
10+
raise FileNotFoundError("MATLAB executable not found in PATH.")
11+
12+
return Path(ml).parents[1]
13+
14+
15+
def get_matlab_version(root: Path) -> str:
16+
if not root.is_dir():
17+
raise NotADirectoryError(f"{root} is not a valid directory.")
18+
19+
xmlPath = root / "VersionInfo.xml"
20+
if not xmlPath.is_file():
21+
raise FileNotFoundError(xmlPath)
22+
23+
tree = ET.parse(xmlPath)
24+
root = tree.getroot()
25+
26+
return root.find('version').text
27+
28+
29+
if __name__ == "__main__":
30+
parser = argparse.ArgumentParser(description="Get MATLAB version from VersionInfo.xml")
31+
parser.add_argument('matlab_root', nargs='?', help="Path to MATLAB root directory")
32+
args = parser.parse_args()
33+
34+
root = Path(args.matlab_root) if args.matlab_root else get_matlab_root()
35+
36+
print(get_matlab_version(root))

0 commit comments

Comments
 (0)