How to use SPDX Licenseinformation in .mat matlab files?

4 ビュー (過去 30 日間)
Jonas Stein
Jonas Stein 2022 年 11 月 1 日
コメント済み: Suvansh Arora 2022 年 11 月 7 日
SPDX is an ISO standard which enables one to add structured human and machine readabel license information to files.
I do not want to clutter the preview function of matlab.
How should the SPDX information be added to the file?
Is it possible to tell matlab, that comments with SPDX data should be ignored in the preview?

採用された回答

Suvansh Arora
Suvansh Arora 2022 年 11 月 4 日
I think the “preview” function you are talking about is the “help” function that is used to provide help for the programs you write.
I would like to recommend a way to not clutter the help data with unwanted license information.
  • Add a space in between the license information and documentation in your code
function c = addMe(a,b)
% ADDME Add two values together.
% C = ADDME(A) adds A to itself.
%
% C = ADDME(A,B) adds A and B together.
%
% See also SUM, PLUS.
% License information:
switch nargin
case 2
c = a + b;
case 1
c = a + a;
otherwise
c = 0;
end
>> help addME % In order to view the documentation.
addMe Add two values together.
C = addMe(A) adds A to itself.
C = addMe(A,B) adds A and B together.
See also sum, plus.
I hope the above information helps you.
  2 件のコメント
Jonas Stein
Jonas Stein 2022 年 11 月 6 日
Does the following pseudo code cover all cases?
FOR ALL .mat FILES DO
IF there_is_a_function
THEN add_spdx_comment_before_function
ELSE add_spdx_comment_in_first_lines_of_the_file
Suvansh Arora
Suvansh Arora 2022 年 11 月 7 日
A better way of achieving this would be:
FOR ALL .mat FILES DO
IF there_is_a_function
THEN
skip_lines_with_comments
Add_space_and_add_spdx_information_as_a_comment
ELSE
skip_lines_with_comments
Add_space_and_add_spdx_information_as_a_comment
  • “skip_lines_with_comments”: This will be useful in having a “help” output of the functions/scripts.
  • “Add_space_and_add_spdx_information_as_a_comment”: Adding space would break the “help” output and the comments further on can be used to add “spdx” information.
In order to achieve above automation, you can follow the ML answers article mentioned below:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeManage Products についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by