File tree Expand file tree Collapse file tree 5 files changed +42
-51
lines changed Expand file tree Collapse file tree 5 files changed +42
-51
lines changed Original file line number Diff line number Diff line change 1+ function rel = relative_to(base , other )
2+
3+ if strempty(other )
4+ rel = base ;
5+ return
6+ end
7+ if strempty(base )
8+ rel = other ;
9+ return
10+ end
11+
12+ base = fullfile(base );
13+ other = fullfile(other );
14+
15+ if stdlib .is_absolute(base ) && ~(startsWith(base , other ) || startsWith(other , base ))
16+ rel = " " ;
17+ else
18+ % https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getrelativepath
19+ rel = string(System .IO .Path .GetRelativePath(base , other ));
20+ end
21+
22+ end
Original file line number Diff line number Diff line change 1+ function rel = relative_to(base , other )
2+
3+ try
4+ rel = string(py .os .path .relpath(other , base ));
5+ catch e
6+ if e .identifier == " MATLAB:Python:PyException" && startsWith(e .message , ' Python Error: ValueError' )
7+ rel = " " ;
8+ else
9+ rethrow(e )
10+ end
11+ end
12+
13+ end
Original file line number Diff line number Diff line change 1717 rel = other ;
1818end
1919
20-
2120end
22-
23- % !testif 0
Original file line number Diff line number Diff line change 1717 force_old (1 ,1 ) logical = false
1818end
1919
20- persistent v_
20+ persistent stdlib_py_version
2121
22- if ~isempty(v_ )
23- v = v_ ;
22+ if ~isempty(stdlib_py_version )
23+ v = stdlib_py_version ;
2424 return
2525end
2626
3232end
3333
3434% we use a separate function because the JIT compiler in Matlab < R2022a
35- % breaks try-catch for any py.* command
35+ % breaks for any py.* command when pyenv() is not correctly configured
3636
3737v = stdlib .python .version();
3838
3939% cache the result
4040if ~isempty(v )
41- v_ = v ;
41+ stdlib_py_version = v ;
4242end
4343
4444end
Original file line number Diff line number Diff line change 2323end
2424
2525if stdlib .has_python()
26- rel = relative_to_python (base , other );
26+ rel = stdlib . python .relative_to (base , other );
2727elseif stdlib .dotnet_api() >= 5
28- rel = relative_to_dotnet (base , other );
28+ rel = stdlib . dotnet .relative_to (base , other );
2929else
3030 error(' no supported relative path method found, please install .NET or "buildtool mex"' )
3131end
3232
3333end
34-
35-
36- function rel = relative_to_dotnet(base , other )
37-
38- if strempty(other )
39- rel = base ;
40- return
41- end
42- if strempty(base )
43- rel = other ;
44- return
45- end
46-
47- base = fullfile(base );
48- other = fullfile(other );
49-
50- if stdlib .is_absolute(base ) && ~(startsWith(base , other ) || startsWith(other , base ))
51- rel = " " ;
52- else
53- % https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getrelativepath
54- rel = string(System .IO .Path .GetRelativePath(base , other ));
55- end
56-
57- end
58-
59-
60- function rel = relative_to_python(base , other )
61-
62- try
63- rel = string(py .os .path .relpath(other , base ));
64- catch e
65- if e .identifier == " MATLAB:Python:PyException" && startsWith(e .message , ' Python Error: ValueError' )
66- rel = " " ;
67- else
68- rethrow(e )
69- end
70- end
71-
72- end
73-
74- % !testif 0
You can’t perform that action at this time.
0 commit comments