Skip to content

Commit

Permalink
Clean up help text
Browse files Browse the repository at this point in the history
  • Loading branch information
mducle committed Jan 13, 2022
1 parent 33b0891 commit b5a0c51
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion +light_python_wrapper/light_python_wrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function delete(obj)
classname = module;
while p2 ~= ""
[p1, p2] = strtok(p2, '.');
classname = classname.(p1);
classname = py.getattr(classname, p1);
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion helputils/doc.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function doc_python(helpStr, class_summary, topic)
for ii = 1:size(class_summary{icl},1)
name_str = class_summary{icl}{ii,1};
sum_str = class_summary{icl}{ii,2};
if ~isempty(sum_str)
no_link = class_summary{icl}{ii,3};
if ~isempty(sum_str) && ~no_link
name_str = sprintf('<a href="matlab:doc %s.%s">%s</a>', topic, name_str, name_str);
end
pstr = join([pstr {h1 sprintf(d1, name_str) sprintf(d2, sum_str) h2}], newline);
Expand Down
5 changes: 3 additions & 2 deletions helputils/help.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
for ii = 1:size(class_summary{icl},1)
name_str = class_summary{icl}{ii,1};
sum_str = class_summary{icl}{ii,2};
if ~isempty(sum_str)
no_link = class_summary{icl}{ii,3};
if ~isempty(sum_str) && ~no_link
pstr = sprintf('%%%is', lmax - numel(name_str));
name_str = sprintf(['<a href="matlab:help %s.%s">%s</a>' pstr], topic, name_str, name_str, '');
name_str = sprintf([pstr '<a href="matlab:help %s.%s">%s</a>'], '', topic, name_str, name_str);
end
out = [out sprintf([' ' lstr ' - %s\n'], name_str, sum_str)];
end
Expand Down
29 changes: 22 additions & 7 deletions helputils/private/python_help.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,40 @@
idx = find(cellfun(@(m) ~startsWith(m, '_'), cell(props)));
blurb = cell(1, numel(idx));
ismethod = zeros(1, numel(idx));
no_link = ones(1, numel(idx));
for ii = 1:numel(idx)
child_ref = py.getattr(parent_ref, props{idx(ii)});
child_docstr = py.getattr(child_ref, '__doc__');
try
child_ref = py.getattr(parent_ref, props{idx(ii)});
child_docstr = py.getattr(child_ref, '__doc__');
catch
child_docstr = py.NoneType;
end
if ~isa(child_docstr, 'py.NoneType')
helptxt = regexprep(helptxt, sprintf('(%s)(\\s*[\\(:])', props{idx(ii)}), ...
sprintf('<a href="matlab:help %s.$1">$1</a>$2', ml_class));
helptxt = strrep(helptxt, sprintf(' %s.%s ', classname, props{idx(ii)}), ...
sprintf(' <a href="matlab:help %s.%s">%s.%s</a> ', ml_class, props{idx(ii)}, classname, props{idx(ii)}));
if strncmp(class(child_ref), 'py.', 3)
helptxt = regexprep(helptxt, sprintf('(%s)(\\s*[\\(:])', props{idx(ii)}), ...
sprintf('<a href="matlab:help %s.$1">$1</a>$2', ml_class));
helptxt = strrep(helptxt, sprintf(' %s.%s ', classname, props{idx(ii)}), ...
sprintf(' <a href="matlab:help %s.%s">%s.%s</a> ', ml_class, props{idx(ii)}, classname, props{idx(ii)}));
no_link(ii) = 0;
end
blurb{ii} = strtrim(strtok(char(child_docstr), newline));
ismethod(ii) = py.hasattr(child_ref, '__call__');
end
end
if numel(idx) > 100
not_empty = (~cellfun(@isempty, blurb)) | ismethod;
idx = idx(not_empty);
blurb = blurb(not_empty);
ismethod = ismethod(not_empty);
no_link = no_link(not_empty);
end
class_summary = cell(1,2);
if strcmp(parent_class, py_class)
[~, isrt] = sort(cellfun(@(m) m(1), props(idx)));
for ii = 1:numel(isrt)
if ~isempty(blurb{isrt(ii)}), docstr = blurb{isrt(ii)}; else, docstr = ''; end
if ismethod(isrt(ii)), icl = 2; else, icl = 1; end
class_summary{icl} = cat(1, class_summary{icl}, [props(idx(isrt(ii))) {docstr}]);
class_summary{icl} = cat(1, class_summary{icl}, [props(idx(isrt(ii))) {docstr no_link(isrt(ii))}]);
end
end
end

0 comments on commit b5a0c51

Please sign in to comment.