From 74c54fe0ff149397c846d5bebc1dedd7518b279f Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Fri, 19 Jun 2020 10:49:24 -0500 Subject: [PATCH 01/10] +dj/Connection.m, setupDJ.m: move matlab, mym version checks into setupDJ.m - ensures earlier detection of outdated components - part of fix for #228 --- +dj/Connection.m | 9 --------- setupDJ.m | 13 ++++++++++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/+dj/Connection.m b/+dj/Connection.m index 650814ed..517486fc 100644 --- a/+dj/Connection.m +++ b/+dj/Connection.m @@ -28,15 +28,6 @@ % initQuery is the SQL query to be executed at the start % of each new session. setupDJ(true); - try - mymVersion = mym('version'); - assert(mymVersion.major > 2 || mymVersion.major==2 && mymVersion.minor>=6) - catch - error 'Outdated version of mYm. Please upgrade to version 2.6 or later' - end - if verLessThan('matlab', '8.6') - error 'MATLAB version 8.6 (R2015b) or greater is required' - end self.host = host; self.user = username; self.password = password; diff --git a/setupDJ.m b/setupDJ.m index 25bb9b07..e820d24b 100644 --- a/setupDJ.m +++ b/setupDJ.m @@ -10,6 +10,10 @@ function setupDJ(skipPathAddition, force) return end + if verLessThan('matlab', '8.6') + error 'MATLAB version 8.6 (R2015b) or greater is required' + end + base = fileparts(mfilename('fullpath')); if nargin < 1 @@ -42,6 +46,13 @@ function setupDJ(skipPathAddition, force) % run mymSetup.m fprintf('Setting up mym...\n') run(fullfile(mymdir, 'mymSetup.m')) - + + try + mymVersion = mym('version'); + assert(mymVersion.major > 2 || mymVersion.major==2 && mymVersion.minor>=6) + catch + error 'Outdated version of mYm. Please upgrade to version 2.6 or later' + end + INVOKED = 1; end From 03f798aa97dc16b1a7dc40913c440952e327a2da Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Fri, 26 Jun 2020 11:32:07 -0500 Subject: [PATCH 02/10] setupDJ: move mym-related functionality to new setupMYM.m - setupMYM now manages actual install/setup of mym - setupDJ calls this to install mym, and checks versions. currently: - we install 'master' (other options 'X.Y.Z', maps to github releases e.g: https://github.com/datajoint/mym/archive/v2.7.2.zip) - we check for >2 or >= 2.6 --- setupMYM.m | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 setupMYM.m diff --git a/setupMYM.m b/setupMYM.m new file mode 100644 index 00000000..4d371f08 --- /dev/null +++ b/setupMYM.m @@ -0,0 +1,67 @@ +function setupMYM(version, force) + + if nargin < 1 + version = 'master'; + elseif nargin < 2 + force = false; + end + + persistent INVOKED; + + if ~isempty(INVOKED) && ~force + return + end + + base = fileparts(mfilename('fullpath')); + + mymdir = fullfile(base, 'mym'); + + if isdir(mymdir) + if force + fprintf('force install.. removing %s\n', mymdir); + rmdir(mymdir, 's'); + else + fprintf('Warning: mym directory exists. not re-installing.\n'); + fprintf(' to override, pass force=true\n'); + end + end + + if ~isdir(mymdir) %% mym directory missing, download and install + fprintf('Installing %s...\n', version); + target = fullfile(base, 'mym.zip'); + + mymURL = 'https://github.com/datajoint/mym/archive/'; + + if strcmp(version, 'master') + mymURL = strcat(mymURL, version, '.zip'); + else + mymURL = strcat(mymURL, 'v', version, '.zip'); + end + + fprintf('downloading %s to %s\n', mymURL, target); + target = websave(target, mymURL); + + extdir = fullfile(base, sprintf('mym-%s', version)); + fprintf('extracting %s into %s\n', target, extdir); + + if isunix && ~ismac + % on Linux Matlab unzip doesn't work properly so use system unzip + system(sprintf('unzip -o %s -d %s', target, base)); + else + unzip(target, base); + end + + % rename extracted mym-master directory to mym + fprintf('renaming %s to %s\n', extdir, mymdir) + movefile(extdir, mymdir); + + delete(target); + end + + % run mymSetup.m + fprintf('Setting up mym...\n') + run(fullfile(mymdir, 'mymSetup.m')) + + INVOKED = 1; + +end From a42397beb525f45f75b45772b775e430653e3408 Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Fri, 26 Jun 2020 11:42:26 -0500 Subject: [PATCH 03/10] setupDJ.m: use new setupMYM --- setupDJ.m | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/setupDJ.m b/setupDJ.m index e820d24b..0ef2a63e 100644 --- a/setupDJ.m +++ b/setupDJ.m @@ -25,27 +25,7 @@ function setupDJ(skipPathAddition, force) addpath(base) end - mymdir = fullfile(base, 'mym'); - % if mym directory missing, download and install - if ~isdir(mymdir) - fprintf('mym missing. Downloading...\n') - target = fullfile(base, 'mym.zip'); - mymURL = 'https://github.com/datajoint/mym/archive/master.zip'; - target = websave(target, mymURL); - if isunix && ~ismac - % on Linux Matlab unzip doesn't work properly so use system unzip - system(sprintf('unzip -o %s -d %s', target, base)) - else - unzip(target, base) - end - % rename extracted mym-master directory to mym - movefile(fullfile(base, 'mym-master'), mymdir) - delete(target) - end - - % run mymSetup.m - fprintf('Setting up mym...\n') - run(fullfile(mymdir, 'mymSetup.m')) + setupMYM('master', force); try mymVersion = mym('version'); From 5c195b08032481bfaf3976c6ddcc6d68b08b4fde Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Fri, 31 Jul 2020 18:40:50 -0500 Subject: [PATCH 04/10] {setupDJ,setupMYM}.m: minver 9.1/2016b, adjust print/error/warnings. --- setupDJ.m | 16 +++++++++------- setupMYM.m | 11 ++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/setupDJ.m b/setupDJ.m index 0ef2a63e..e22acef6 100644 --- a/setupDJ.m +++ b/setupDJ.m @@ -10,8 +10,9 @@ function setupDJ(skipPathAddition, force) return end - if verLessThan('matlab', '8.6') - error 'MATLAB version 8.6 (R2015b) or greater is required' + if verLessThan('matlab', '9.1') + error('DataJoint:System:UnsupportedMatlabVersion', ... + 'MATLAB version 9.1 (R2016b) or greater is required'); end base = fileparts(mfilename('fullpath')); @@ -19,19 +20,20 @@ function setupDJ(skipPathAddition, force) if nargin < 1 skipPathAddition = false; end - + if ~skipPathAddition - fprintf('Adding DataJoint to the path...\n') - addpath(base) + fprintf('Adding DataJoint to the path...\n'); + addpath(base); end setupMYM('master', force); try mymVersion = mym('version'); - assert(mymVersion.major > 2 || mymVersion.major==2 && mymVersion.minor>=6) + assert(mymVersion.major > 2 || mymVersion.major==2 && mymVersion.minor>=6); catch - error 'Outdated version of mYm. Please upgrade to version 2.6 or later' + error('DataJoint:System:UnsupportedMyMVersion', ... + 'Outdated version of mYm. Please upgrade to version 2.6 or later'); end INVOKED = 1; diff --git a/setupMYM.m b/setupMYM.m index 4d371f08..be53af58 100644 --- a/setupMYM.m +++ b/setupMYM.m @@ -21,8 +21,9 @@ function setupMYM(version, force) fprintf('force install.. removing %s\n', mymdir); rmdir(mymdir, 's'); else - fprintf('Warning: mym directory exists. not re-installing.\n'); - fprintf(' to override, pass force=true\n'); + warning('DataJoint:System:setupMyMwarning', ... + ['Warning: mym directory exists. not re-installing.\n', ... + ' to override, pass force=true\n']); end end @@ -52,15 +53,15 @@ function setupMYM(version, force) end % rename extracted mym-master directory to mym - fprintf('renaming %s to %s\n', extdir, mymdir) + fprintf('renaming %s to %s\n', extdir, mymdir); movefile(extdir, mymdir); delete(target); end % run mymSetup.m - fprintf('Setting up mym...\n') - run(fullfile(mymdir, 'mymSetup.m')) + fprintf('Setting up mym...\n'); + run(fullfile(mymdir, 'mymSetup.m')); INVOKED = 1; From e24c374af43611a17d707f29a099e2f03ec8c6ed Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Fri, 31 Jul 2020 21:16:44 -0500 Subject: [PATCH 05/10] setupMYM: quiet no-reinstall warning for default case --- setupMYM.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setupMYM.m b/setupMYM.m index be53af58..ce64b3be 100644 --- a/setupMYM.m +++ b/setupMYM.m @@ -1,7 +1,9 @@ function setupMYM(version, force) + default_version = 'master'; + if nargin < 1 - version = 'master'; + version = default_version; elseif nargin < 2 force = false; end @@ -20,7 +22,7 @@ function setupMYM(version, force) if force fprintf('force install.. removing %s\n', mymdir); rmdir(mymdir, 's'); - else + elseif(~strcmp(version, default_version)) warning('DataJoint:System:setupMyMwarning', ... ['Warning: mym directory exists. not re-installing.\n', ... ' to override, pass force=true\n']); From 602be47e90cbd3c169f398fd32ad90fc10efab26 Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Thu, 6 Aug 2020 18:26:41 -0500 Subject: [PATCH 06/10] += +tests/TestSetupMYM.m skeleton --- +tests/TestSetupMYM.m | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 +tests/TestSetupMYM.m diff --git a/+tests/TestSetupMYM.m b/+tests/TestSetupMYM.m new file mode 100644 index 00000000..e3c93362 --- /dev/null +++ b/+tests/TestSetupMYM.m @@ -0,0 +1,28 @@ + +classdef TestSetupMYM < tests.Prep +% TestSetupMyM tests setupMYM + + methods (Test) + function TestSetupMYM_testDefaultInstall(testCase) + + end + function TestSetupMYM_testVersionInstallFresh(testCase) + + end + function TestSetupMYM_testVersionInstallStale(testCase) + + end + function TestSetupMYM_testVersionInstallStaleForce(testCase) + + end + function TestSetupMYM_testMasterInstallFresh(testCase) + + end + function TestSetupMYM_testMasterInstallStale(testCase) + + end + function TestSetupMYM_testMasterInstallStaleForce(testCase) + + end + end +end From b888852464b84af1d29459c1dfa3ce89502aaeea Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Thu, 13 Aug 2020 21:44:53 -0500 Subject: [PATCH 07/10] setupMYM.m: document appropriate version strings --- setupMYM.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setupMYM.m b/setupMYM.m index ce64b3be..f6020710 100644 --- a/setupMYM.m +++ b/setupMYM.m @@ -1,6 +1,6 @@ function setupMYM(version, force) - default_version = 'master'; + default_version = 'master'; % else git tag string e.g. '2.7.2' if nargin < 1 version = default_version; From 331758710535498ceb379d1475ca8a3c26e98727 Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Thu, 13 Aug 2020 21:45:38 -0500 Subject: [PATCH 08/10] += +tests/TestSetupMYM.m: prototype/WIP --- +tests/TestSetupMYM.m | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/+tests/TestSetupMYM.m b/+tests/TestSetupMYM.m index e3c93362..3d899008 100644 --- a/+tests/TestSetupMYM.m +++ b/+tests/TestSetupMYM.m @@ -5,23 +5,109 @@ methods (Test) function TestSetupMYM_testDefaultInstall(testCase) + [dir, nam, ext] = fileparts(mfilename('fullpath')); + tmym = strcat(dir, '/../', 'mym'); + + if isdir(tmym) + fprintf('testDefaultInstall: mymdir %s exists. removing\n', ... + tmym); + rmdir(tmym, 's'); + end + + ms = setupMYM(); % TODO: how properly verify? + end function TestSetupMYM_testVersionInstallFresh(testCase) + [dir, nam, ext] = fileparts(mfilename('fullpath')); + tmym = strcat(dir, '/../', 'mym'); + + if isdir(tmym) + fprintf('testVersionInstallFresh: removing mymdir %s\n', ... + tmym); + rmdir(tmym, 's'); + end + + % TODO: how manage version string? + ms = setupMYM('2.7.2'); % TODO: how properly verify? + + testCase.verifyTrue(isdir(tmym)); end function TestSetupMYM_testVersionInstallStale(testCase) + [dir, nam, ext] = fileparts(mfilename('fullpath')); + tmym = strcat(dir, '/../', 'mym'); + + if ~isdir(tmym) % XXX: valid? how handle otherwise? + fprintf('testVersionInstallStale: spoofing mymdir %s\n', ... + tmym); + mkdir(tmym); + testCase.verifyTrue(isdir(tmym)); + end + + % TODO: how manage version string? + ms = setupMYM('2.7.2'); % TODO: how verify fail? end function TestSetupMYM_testVersionInstallStaleForce(testCase) + [dir, nam, ext] = fileparts(mfilename('fullpath')); + tmym = strcat(dir, '/../', 'mym'); + + if ~isdir(tmym) % XXX: valid? how handle otherwise? + fprintf('testVersionInstallStaleForce: spoofing mymdir %s\n', ... + tmym); + mkdir(tmym); + testCase.verifyTrue(isdir(tmym)); + end + + % TODO: how manage version string? + ms = setupMYM('2.7.2', true); % TODO: how properly verify? + + testCase.verifyTrue(isdir(tmym)); end function TestSetupMYM_testMasterInstallFresh(testCase) + [dir, nam, ext] = fileparts(mfilename('fullpath')); + tmym = strcat(dir, '/../', 'mym'); + + if isdir(tmym) + fprintf('testMasterInstallFresh: removing mymdir %s\n', ... + tmym); + rmdir(tmym, 's'); + end + + ms = setupMYM('master'); % TODO: how properly verify + + testCase.verifyTrue(isdir(tmym)); end function TestSetupMYM_testMasterInstallStale(testCase) + [dir, nam, ext] = fileparts(mfilename('fullpath')); + tmym = strcat(dir, '/../', 'mym'); + + if ~isdir(tmym) % XXX: valid? how handle otherwise? + fprintf('testMasterInstallStale: spoofing mymdir %s\n', ... + tmym); + mkdir(tmym); + testCase.verifyTrue(isdir(tmym)); + end + + ms = setupMYM('master'); % TODO: how verify fail? end function TestSetupMYM_testMasterInstallStaleForce(testCase) + [dir, nam, ext] = fileparts(mfilename('fullpath')); + tmym = strcat(dir, '/../', 'mym'); + + if ~isdir(tmym) % XXX: valid? how handle otherwise? + fprintf('testMasterInstallStaleForce: spoofing mymdir %s\n', ... + tmym); + mkdir(tmym); + testCase.verifyTrue(isdir(tmym)); + end + + ms = setupMYM('master'); % TODO: how properly verify + + testCase.verifyTrue(isdir(tmym)); end end From 727f49e518973b279af4b840919467c757c077e9 Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Fri, 11 Sep 2020 20:20:26 -0500 Subject: [PATCH 09/10] setupMYM.m: return version string. fix nargin processing issue while here --- +tests/TestSetupMYM.m | 25 ++++++++++++++----------- setupMYM.m | 17 ++++++++++------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/+tests/TestSetupMYM.m b/+tests/TestSetupMYM.m index 3d899008..9e79b6cd 100644 --- a/+tests/TestSetupMYM.m +++ b/+tests/TestSetupMYM.m @@ -14,7 +14,9 @@ function TestSetupMYM_testDefaultInstall(testCase) rmdir(tmym, 's'); end - ms = setupMYM(); % TODO: how properly verify? + ms = setupMYM(); + testCase.verifyTrue(strcmp(ms, 'master')); + testCase.verifyTrue(isdir(tmym)); end function TestSetupMYM_testVersionInstallFresh(testCase) @@ -28,8 +30,8 @@ function TestSetupMYM_testVersionInstallFresh(testCase) end % TODO: how manage version string? - ms = setupMYM('2.7.2'); % TODO: how properly verify? - + ms = setupMYM('2.7.2'); + testCase.verifyTrue(strcmp(ms, '2.7.2')); testCase.verifyTrue(isdir(tmym)); end @@ -45,7 +47,8 @@ function TestSetupMYM_testVersionInstallStale(testCase) end % TODO: how manage version string? - ms = setupMYM('2.7.2'); % TODO: how verify fail? + ms = setupMYM('2.7.2'); % TODO: how properly verify? + % also: .. persistent & test state ... end function TestSetupMYM_testVersionInstallStaleForce(testCase) @@ -60,8 +63,8 @@ function TestSetupMYM_testVersionInstallStaleForce(testCase) end % TODO: how manage version string? - ms = setupMYM('2.7.2', true); % TODO: how properly verify? - + ms = setupMYM('2.7.2', true); + testCase.verifyTrue(strcmp(ms, '2.7.2')); testCase.verifyTrue(isdir(tmym)); end @@ -75,8 +78,8 @@ function TestSetupMYM_testMasterInstallFresh(testCase) rmdir(tmym, 's'); end - ms = setupMYM('master'); % TODO: how properly verify - + ms = setupMYM('master'); + testCase.verifyTrue(strcmp(ms, 'master')); testCase.verifyTrue(isdir(tmym)); end @@ -92,7 +95,7 @@ function TestSetupMYM_testMasterInstallStale(testCase) end ms = setupMYM('master'); % TODO: how verify fail? - + % also: .. persistent & test state ... end function TestSetupMYM_testMasterInstallStaleForce(testCase) [dir, nam, ext] = fileparts(mfilename('fullpath')); @@ -105,8 +108,8 @@ function TestSetupMYM_testMasterInstallStaleForce(testCase) testCase.verifyTrue(isdir(tmym)); end - ms = setupMYM('master'); % TODO: how properly verify - + ms = setupMYM('master'); + testCase.verifyTrue(strcmp(ms, 'master')); testCase.verifyTrue(isdir(tmym)); end diff --git a/setupMYM.m b/setupMYM.m index f6020710..5b2ffaad 100644 --- a/setupMYM.m +++ b/setupMYM.m @@ -1,17 +1,19 @@ -function setupMYM(version, force) +function mymVersion = setupMYM(version, force) default_version = 'master'; % else git tag string e.g. '2.7.2' if nargin < 1 version = default_version; - elseif nargin < 2 + end + if nargin < 2 force = false; end + + persistent INSTALLED_VERSION; - persistent INVOKED; - - if ~isempty(INVOKED) && ~force - return + if ~isempty(INSTALLED_VERSION) && ~force + mymVersion = INSTALLED_VERSION; + return; end base = fileparts(mfilename('fullpath')); @@ -65,6 +67,7 @@ function setupMYM(version, force) fprintf('Setting up mym...\n'); run(fullfile(mymdir, 'mymSetup.m')); - INVOKED = 1; + mymVersion = version; + INSTALLED_VERSION = mymVersion; end From 3712243cf8c74ffbc9da3c23d452ca895372af57 Mon Sep 17 00:00:00 2001 From: Chris Turner Date: Fri, 11 Sep 2020 20:30:02 -0500 Subject: [PATCH 10/10] setupMYM.m: += note on setupMYM version string vs mym('version') --- setupMYM.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setupMYM.m b/setupMYM.m index 5b2ffaad..7fa2e2a1 100644 --- a/setupMYM.m +++ b/setupMYM.m @@ -12,6 +12,9 @@ persistent INSTALLED_VERSION; if ~isempty(INSTALLED_VERSION) && ~force + % note: for 'master', is currently 'master' not mym('version') + % using mym('version') needs a master:version mapping, + % and how to handle this is a wider dev issue (releses, tests, etc) mymVersion = INSTALLED_VERSION; return; end