Skip to content

Commit 4fa69ee

Browse files
authored
Fold getToolboxVersion into exportForGit; report GECKO instead of COBRA (#635)
* Fold getToolboxVersion into exportForGit and report GECKO not COBRA getToolboxVersion was only used by exportForGit, so it becomes a local subfunction there and the standalone file (and its doc) are removed. The dependency report now covers RAVEN and, for enzyme-constrained models (those with an "ec" field), GECKO; the COBRA Toolbox version is no longer reported. GECKO is located via GECKOInstaller.m. The tIO test that called getToolboxVersion directly now checks that exportForGit writes a RAVEN_toolbox entry to dependencies.txt instead. * Report toolbox version from version.txt only, otherwise 'unknown' Drop the git describe/commit-hash fallback in the folded getToolboxVersion: the reported version now comes solely from the toolbox version.txt, and is 'unknown' when that file is absent (e.g. a development checkout between releases).
1 parent 7d74921 commit 4fa69ee

4 files changed

Lines changed: 79 additions & 276 deletions

File tree

doc/io/getToolboxVersion.html

Lines changed: 0 additions & 168 deletions
This file was deleted.

io/exportForGit.m

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
% should be exported (default all formats as {'mat', 'txt', 'xlsx',
2424
% 'xml', 'yml'}).
2525
% mainBranchFlag : logical
26-
% if true, function will error if RAVEN (and COBRA if detected) is/are
27-
% not on the main branch (default false).
26+
% if true, function will error if RAVEN (and GECKO for enzyme-
27+
% constrained models) is/are not on the main branch (default false).
2828
% subDirs : logical
2929
% whether model files for each file format should be written in their
3030
% own subdirectory, with 'model' as parent directory, in accordance to
@@ -77,12 +77,13 @@
7777
%Sort reactions, metabolites and genes alphabetically
7878
model=sortIdentifiers(model);
7979

80-
%Get versions or commits of toolboxes:
80+
%Get versions or commits of toolboxes. GECKO is only relevant for
81+
%enzyme-constrained models (those with an "ec" field).
8182
RAVENver = getToolboxVersion('RAVEN','ravenCobraWrapper.m',mainBranchFlag);
82-
if exist('initCobraToolbox.m','file')
83-
COBRAver = getToolboxVersion('COBRA','initCobraToolbox.m',mainBranchFlag);
83+
if isfield(model,'ec')
84+
GECKOver = getToolboxVersion('GECKO','GECKOInstaller.m',mainBranchFlag);
8485
else
85-
COBRAver = [];
86+
GECKOver = [];
8687
end
8788
%Retrieve libSBML version:
8889
[ravenDir,prevDir]=findRAVENroot();
@@ -159,8 +160,8 @@
159160
fprintf(fid,['MATLAB\t' version '\n']);
160161
fprintf(fid,['libSBML\t' libSBMLver '\n']);
161162
fprintf(fid,['RAVEN_toolbox\t' RAVENver '\n']);
162-
if ~isempty(COBRAver)
163-
fprintf(fid,['COBRA_toolbox\t' COBRAver '\n']);
163+
if ~isempty(GECKOver)
164+
fprintf(fid,['GECKO_toolbox\t' GECKOver '\n']);
164165
end
165166
if isfield(model,'modelVersion')
166167
fields = fieldnames(model.modelVersion);
@@ -171,3 +172,63 @@
171172
end
172173
fclose(fid);
173174
end
175+
176+
function version = getToolboxVersion(toolbox,fileID,mainBranchFlag)
177+
% getToolboxVersion Return the version of RAVEN or GECKO.
178+
%
179+
% Returns the version of the toolbox as stated in its version.txt, or
180+
% 'unknown' if that file cannot be found.
181+
%
182+
% toolbox name of the toolbox (e.g. 'RAVEN' or 'GECKO').
183+
% fileID a file only found in that toolbox, used to locate its root
184+
% (e.g. 'ravenCobraWrapper.m' or 'GECKOInstaller.m').
185+
% mainBranchFlag if true, error if the toolbox is not on the main branch.
186+
currentPath = pwd;
187+
version = '';
188+
189+
%Try to find root of toolbox:
190+
try
191+
toolboxPath = which(fileID); %full file path
192+
slashPos = getSlashPos(toolboxPath);
193+
toolboxPath = toolboxPath(1:slashPos(end)); %folder path
194+
%Go up until the root is found:
195+
D = dir(toolboxPath);
196+
while ~ismember({'.git'},{D.name})
197+
slashPos = getSlashPos(toolboxPath);
198+
toolboxPath = toolboxPath(1:slashPos(end-1));
199+
D = dir(toolboxPath);
200+
end
201+
cd(toolboxPath);
202+
catch
203+
disp([toolbox ' toolbox cannot be found'])
204+
version = 'unknown';
205+
end
206+
%Check if in main:
207+
if mainBranchFlag
208+
[~,currentBranch] = system('git rev-parse --abbrev-ref HEAD');
209+
currentBranch = strtrim(currentBranch);
210+
if any([strcmp(currentBranch, "main"), strcmp(currentBranch, "master")])
211+
cd(currentPath);
212+
error(['ERROR: ' toolbox ' not in main (or master) branch. Check-out this branch of ' toolbox ' before submitting model for Git.'])
213+
end
214+
end
215+
%Read the version from the toolbox version.txt; report 'unknown' otherwise
216+
if isempty(version)
217+
fid = fopen([toolboxPath 'version.txt'],'r');
218+
if fid ~= -1
219+
version = fscanf(fid,'%s');
220+
fclose(fid);
221+
end
222+
if isempty(version)
223+
version = 'unknown';
224+
end
225+
end
226+
cd(currentPath);
227+
end
228+
229+
function slashPos = getSlashPos(path)
230+
slashPos = strfind(path,'\'); %Windows
231+
if isempty(slashPos)
232+
slashPos = strfind(path,'/'); %MAC/Linux
233+
end
234+
end

io/getToolboxVersion.m

Lines changed: 0 additions & 97 deletions
This file was deleted.

testing/function_tests/tIO.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ function getMD5HashReturnsHexDigest(testCase)
3636
testCase.verifyMatches(char(h), '^[0-9a-fA-F]{32}$');
3737
end
3838

39-
function getToolboxVersionRuns(testCase)
40-
v = getToolboxVersion('RAVEN', 'ravenCobraWrapper.m');
41-
testCase.verifyNotEmpty(v);
39+
function exportForGitWritesDependencies(testCase)
40+
% The toolbox-version lookup is now embedded in exportForGit and
41+
% is exercised via the dependencies.txt it writes
42+
f = fullfile(testCase.ravenRoot,'tutorial','empty.xml');
43+
evalc('model = importModel(f);');
44+
outDir = tempname; mkdir(outDir);
45+
c = onCleanup(@() rmdir(outDir,'s'));
46+
evalc("exportForGit(model,'path',outDir,'formats',{'xml'},'subDirs',false)");
47+
dep = fileread(fullfile(outDir,'dependencies.txt'));
48+
testCase.verifySubstring(dep, 'RAVEN_toolbox');
4249
end
4350

4451
function importModelReadsSBML(testCase)

0 commit comments

Comments
 (0)