Skip to content

Commit

Permalink
Octave 6.x compatibility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
apjanke committed Jan 28, 2020
1 parent 4babc9e commit 09dcdb1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 82 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: jsonstuff
Version: 0.3.0
Version: 0.3.1
Date: 2019-01-29
Title: JsonStuff - JSON encoding and decoding
Author: Andrew Janke <floss@apjanke.net>
Expand Down
33 changes: 33 additions & 0 deletions inst/+jsonstuff/+internal/load_jsonstuff.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function load_jsonstuff
% Load the jsonstuff library

pkg_name = "jsonstuff";

this_dir = fileparts (fullfile (mfilename ("fullpath")));
inst_dir = fileparts (fileparts (this_dir));
shims_dir = fullfile (inst_dir, "shims", "compat");

% Load doco

% When a package is installed, the doc/ directory is added as a subdir
% of the main installation dir, which contains the inst/ files. But when
% running from the repo, doc/ is a sibling of inst/.

if exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file")
qhelp_file = fullfile (inst_dir, "doc", [pkg_name ".qch"]);
elseif exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file")
qhelp_file = fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]);
else
% Couldn't find doc file. Oh well.
qhelp_file = [];
endif

if ! isempty (qhelp_file)
if compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<")
__octave_link_register_doc__ (qhelp_file);
elseif compare_versions (version, "6.0.0", ">=")
__event_manager_register_doc__ (qhelp_file);
endif
endif

endfunction
30 changes: 30 additions & 0 deletions inst/+jsonstuff/+internal/unload_jsonstuff.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function unload_jsonstuff
% Unload the jsonstuff library

pkg_name = "jsonstuff";

this_dir = fileparts (fullfile (mfilename ("fullpath")));
inst_dir = fileparts (fileparts (this_dir));
shims_dir = fullfile (inst_dir, "shims", "compat");

% Unregister doco

if exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file")
qhelp_file = fullfile (inst_dir, "doc", [pkg_name ".qch"]);
elseif exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file")
qhelp_file = fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]);
else
% Couldn't find doc file. Oh well.
qhelp_file = [];
endif

if ! isempty (qhelp_file)
if compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<")
__octave_link_unregister_doc__ (qhelp_file);
elseif compare_versions (version, "6.0.0", ">=")
__event_manager_unregister_doc__ (qhelp_file);
endif
endif


endfunction
42 changes: 1 addition & 41 deletions inst/PKG_ADD
Original file line number Diff line number Diff line change
@@ -1,41 +1 @@
% Register package's QHelp with the doc browser

% PKG_ADD is run in the base workspace, not in a function. So use "__" variable
% names to reduce risk of collision with user variables, and clear them all
% at the end.

% Have to hardcode this since it's not available from context
__my_pkg_name = 'jsonstuff';

% We only want this to happen when we're called by 'pkg load', not when
% this code is just added to the path.
% Note: This detection is a hack and is brittle WRT changes in Octave's
% internal implementation.

__stack = dbstack;
__is_loading = any (ismember ({__stack.name}, {'load_packages'}));
if ~__is_loading
return;
end

% And we can only do this on Octave 4.4 and newer, because 4.2 has no
% __octave_link_register_doc___
if compare_versions (version, '4.4.0', '>=')

% When a package is installed, the doc/ directory is added as a subdir
% of the main installation dir, which contains the inst/ files

__this_dir = fileparts (mfilename ('fullpath'));
__my_doc_dir = fullfile (__this_dir, 'doc');
__my_qhelp_file = fullfile (__my_doc_dir, [__my_pkg_name '.qch']);
if ~exist (__my_qhelp_file, 'file')
warning('QHelp file for package %s is missing: %s', ...
__my_pkg_name, __my_qhelp_file);
return;
end

__octave_link_register_doc__ (__my_qhelp_file);

endif

clear __my_pkg_name __is_loading __stack __this_dir __my_doc_dir __my_qhelp_file
jsonstuff.internal.load_jsonstuff
41 changes: 1 addition & 40 deletions inst/PKG_DEL
Original file line number Diff line number Diff line change
@@ -1,40 +1 @@
% Unregister package's QHelp with the doc browser

% PKG_DEL is run in the base workspace, not in a function. So use "__" variable
% names to reduce risk of collision with user variables, and clear them all
% at the end.

% Have to hardcode this since it's not available from context
__my_pkg_name = 'jsonstuff';

% We only want this to happen when we're called by 'pkg unload', not when
% this code is just removed from the path.
% Note: This detection is a hack and is brittle WRT changes in Octave's
% internal implementation.

__stack = dbstack;
__is_loading = any (ismember ({__stack.name}, {'unload_packages','uninstall'}));
if ~__is_loading
return;
end

% And we can only do this on Octave 4.4 and newer, because 4.2 has no
% __octave_link_register_doc___
if compare_versions (version, '4.4.0', '>=')

% When a package is installed, the doc/ directory is added as a subdir
% of the main installation dir, which contains the inst/ files

__this_dir = fileparts (mfilename ('fullpath'));
__my_doc_dir = fullfile (__this_dir, 'doc');
__my_qhelp_file = fullfile (__my_doc_dir, [__my_pkg_name '.qch']);
if ~exist (__my_qhelp_file, 'file')
% Don't bother warning on unloads
return;
end

__octave_link_unregister_doc__ (__my_qhelp_file);

endif

clear __my_pkg_name __stack __is_loading __this_dir __my_doc_dir __my_qhelp_file
jsonstuff.internal.unload_jsonstuff

0 comments on commit 09dcdb1

Please sign in to comment.