Skip to content

Commit

Permalink
Merge pull request #491 from SysBioChalmers/fix/functionUniqueness
Browse files Browse the repository at this point in the history
fix: checkFunctionUniqueness on mac/unix
  • Loading branch information
edkerk authored Jun 22, 2023
2 parents 9468a22 + d5b8d41 commit 59b27f0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 72 deletions.
147 changes: 76 additions & 71 deletions doc/installation/checkFunctionUniqueness.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,78 +79,83 @@ <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" sr
0023
0024 ravenFunctions={temp_res1.name,temp_res2.name}';
0025 <span class="keyword">else</span>
0026 altDirs = strsplit(altDirs,<span class="string">';'</span>)';
0027 ravenFunctions={};
0028 <span class="keyword">for</span> i=1:numel(altDirs)
0029 temp_res=dir(fullfile(char(altDirs(i)),<span class="string">'*.m'</span>));
0030 ravenFunctions = [ravenFunctions, temp_res.name];
0031 <span class="keyword">end</span>
0032 ravenFunctions=ravenFunctions';
0033 ravenDir=altDirs;
0034 <span class="keyword">end</span>
0035
0036 <span class="comment">%startup.m is not a normal function, any startup.m in the path should run</span>
0037 <span class="comment">%during startup, so duplicate use of this name is fine</span>
0038 ravenFunctions=ravenFunctions(~ismember(ravenFunctions,<span class="string">'startup.m'</span>));
0039
0040 <span class="comment">%Getting all the paths added to Matlab</span>
0041 <span class="keyword">if</span> ispc
0042 matlabPaths=regexp(path, <span class="string">';'</span>, <span class="string">'split'</span>)';
0043 <span class="keyword">elseif</span> isunix
0044 matlabPaths=regexp(path, <span class="string">':'</span>, <span class="string">'split'</span>)';
0045 <span class="keyword">end</span>
0046
0047 overlapPath={};
0048 overlapFunctions={};
0049 multiRaven=false;
0050 multiFunction=false;
0026 <span class="keyword">if</span> ispc
0027 splitChar = <span class="string">';'</span>;
0028 <span class="keyword">else</span>
0029 splitChar = <span class="string">':'</span>;
0030 <span class="keyword">end</span>
0031 altDirs = strsplit(altDirs,splitChar)';
0032 ravenFunctions={};
0033 <span class="keyword">for</span> i=1:numel(altDirs)
0034 temp_res=dir(fullfile(char(altDirs(i)),<span class="string">'*.m'</span>));
0035 ravenFunctions = [ravenFunctions, temp_res.name];
0036 <span class="keyword">end</span>
0037 ravenFunctions=ravenFunctions';
0038 ravenDir=altDirs;
0039 <span class="keyword">end</span>
0040
0041 <span class="comment">%startup.m is not a normal function, any startup.m in the path should run</span>
0042 <span class="comment">%during startup, so duplicate use of this name is fine</span>
0043 ravenFunctions=ravenFunctions(~ismember(ravenFunctions,<span class="string">'startup.m'</span>));
0044
0045 <span class="comment">%Getting all the paths added to Matlab</span>
0046 <span class="keyword">if</span> ispc
0047 matlabPaths=regexp(path, <span class="string">';'</span>, <span class="string">'split'</span>)';
0048 <span class="keyword">elseif</span> isunix
0049 matlabPaths=regexp(path, <span class="string">':'</span>, <span class="string">'split'</span>)';
0050 <span class="keyword">end</span>
0051
0052 <span class="keyword">for</span> i=1:numel(matlabPaths)
0053 <span class="keyword">if</span> ~startsWith(matlabPaths{i},ravenDir)
0054 temp_res=dir([matlabPaths{i} <span class="string">'/*.m'</span>]);
0055 <span class="keyword">if</span> ~isempty(temp_res)
0056 pathFunctions={temp_res.name}';
0057 <span class="keyword">else</span>
0058 pathFunctions=<span class="string">''</span>;
0059 <span class="keyword">end</span>
0060 <span class="keyword">if</span> ~isempty(pathFunctions) &amp;&amp; ~any(ismember(<span class="string">'Contents.m'</span>,pathFunctions))
0061 <span class="keyword">if</span> any(ismember(ravenFunctions,pathFunctions))
0062 <span class="keyword">if</span> sum(ismember(ravenFunctions,pathFunctions))&gt;(numel(ravenFunctions)/4)
0063 multiRaven=true;
0064 <span class="keyword">else</span>
0065 multiFunction=true;
0066 overlapPath = [overlapPath, matlabPaths(i)];
0067 overlapFunctions = [overlapFunctions, {ravenFunctions(ismember(ravenFunctions,pathFunctions))}];
0068 <span class="keyword">end</span>
0069 <span class="keyword">end</span>
0070 <span class="keyword">end</span>
0071 <span class="keyword">end</span>
0072 <span class="keyword">end</span>
0073
0074 <span class="keyword">if</span> multiRaven==true || multiFunction == true
0075 <span class="keyword">if</span> nargout &gt; 0
0076 status = false;
0077 <span class="keyword">else</span>
0078 fprintf(<span class="string">'Fail\n'</span>)
0079 <span class="keyword">end</span>
0080 <span class="keyword">if</span> multiRaven==true &amp;&amp; nargin &lt; 1
0081 error([<span class="string">'Multiple RAVEN versions detected in MATLAB path. Remove all '</span>,<span class="keyword">...</span>
0082 <span class="string">'RAVEN directories from the MATLAB path with removeRavenFromPath(), '</span>,<span class="keyword">...</span>
0083 <span class="string">'or manually remove them. Afterwards, re-run checkInstallation'</span>]);
0084 <span class="keyword">elseif</span> multiFunction == true
0085 <span class="keyword">for</span> i=1:numel(overlapPath)
0086 fprintf([<span class="string">' Duplicate functions in '</span>,regexprep(overlapPath{i},<span class="string">'(\\)'</span>,<span class="string">'\\$1'</span>),<span class="string">'\n'</span>]);
0087 fprintf([<span class="string">' '</span> strjoin(overlapFunctions{i},<span class="string">'\n '</span>) <span class="string">'\n'</span>]);
0088 <span class="keyword">end</span>
0089 fprintf(<span class="string">' Resolve conflicting functions to avoid unexpected behaviour\n'</span>);
0090 <span class="keyword">end</span>
0091 <span class="keyword">else</span>
0092 <span class="keyword">if</span> nargout &gt; 0
0093 status = true;
0094 <span class="keyword">else</span>
0095 fprintf(<span class="string">'Pass\n'</span>)
0096 <span class="keyword">end</span>
0097 <span class="keyword">end</span></pre></div>
0052 overlapPath={};
0053 overlapFunctions={};
0054 multiRaven=false;
0055 multiFunction=false;
0056
0057 <span class="keyword">for</span> i=1:numel(matlabPaths)
0058 <span class="keyword">if</span> ~startsWith(matlabPaths{i},ravenDir)
0059 temp_res=dir([matlabPaths{i} <span class="string">'/*.m'</span>]);
0060 <span class="keyword">if</span> ~isempty(temp_res)
0061 pathFunctions={temp_res.name}';
0062 <span class="keyword">else</span>
0063 pathFunctions=<span class="string">''</span>;
0064 <span class="keyword">end</span>
0065 <span class="keyword">if</span> ~isempty(pathFunctions) &amp;&amp; ~any(ismember(<span class="string">'Contents.m'</span>,pathFunctions))
0066 <span class="keyword">if</span> any(ismember(ravenFunctions,pathFunctions))
0067 <span class="keyword">if</span> sum(ismember(ravenFunctions,pathFunctions))&gt;(numel(ravenFunctions)/4)
0068 multiRaven=true;
0069 <span class="keyword">else</span>
0070 multiFunction=true;
0071 overlapPath = [overlapPath, matlabPaths(i)];
0072 overlapFunctions = [overlapFunctions, {ravenFunctions(ismember(ravenFunctions,pathFunctions))}];
0073 <span class="keyword">end</span>
0074 <span class="keyword">end</span>
0075 <span class="keyword">end</span>
0076 <span class="keyword">end</span>
0077 <span class="keyword">end</span>
0078
0079 <span class="keyword">if</span> multiRaven==true || multiFunction == true
0080 <span class="keyword">if</span> nargout &gt; 0
0081 status = false;
0082 <span class="keyword">else</span>
0083 fprintf(<span class="string">'Fail\n'</span>)
0084 <span class="keyword">end</span>
0085 <span class="keyword">if</span> multiRaven==true &amp;&amp; nargin &lt; 1
0086 error([<span class="string">'Multiple RAVEN versions detected in MATLAB path. Remove all '</span>,<span class="keyword">...</span>
0087 <span class="string">'RAVEN directories from the MATLAB path with removeRavenFromPath(), '</span>,<span class="keyword">...</span>
0088 <span class="string">'or manually remove them. Afterwards, re-run checkInstallation'</span>]);
0089 <span class="keyword">elseif</span> multiFunction == true
0090 <span class="keyword">for</span> i=1:numel(overlapPath)
0091 fprintf([<span class="string">' Duplicate functions in '</span>,regexprep(overlapPath{i},<span class="string">'(\\)'</span>,<span class="string">'\\$1'</span>),<span class="string">'\n'</span>]);
0092 fprintf([<span class="string">' '</span> strjoin(overlapFunctions{i},<span class="string">'\n '</span>) <span class="string">'\n'</span>]);
0093 <span class="keyword">end</span>
0094 fprintf(<span class="string">' Resolve conflicting functions to avoid unexpected behaviour\n'</span>);
0095 <span class="keyword">end</span>
0096 <span class="keyword">else</span>
0097 <span class="keyword">if</span> nargout &gt; 0
0098 status = true;
0099 <span class="keyword">else</span>
0100 fprintf(<span class="string">'Pass\n'</span>)
0101 <span class="keyword">end</span>
0102 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>
7 changes: 6 additions & 1 deletion installation/checkFunctionUniqueness.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@

ravenFunctions={temp_res1.name,temp_res2.name}';
else
altDirs = strsplit(altDirs,';')';
if ispc
splitChar = ';';
else
splitChar = ':';
end
altDirs = strsplit(altDirs,splitChar)';
ravenFunctions={};
for i=1:numel(altDirs)
temp_res=dir(fullfile(char(altDirs(i)),'*.m'));
Expand Down

0 comments on commit 59b27f0

Please sign in to comment.