Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BannerFunction to PackageInfo.g #2598

Merged
merged 1 commit into from
Sep 2, 2018

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Jul 2, 2018

This implements some in the idea described in issue #2568, by adding two new keys to the package info record (their names are of course still open for discussion):

  • BannerExtra can set to a string, or to a function returning a string; the string will be printed as part of the the default banner, as produced by DefaultPackageBannerString. This can be used to print some additional information in the banner, e.g. extra acknowledgements; or dynamic info about build configuration for a package with kernel extension.

  • BannerFunction can be set to a function which takes the info record as argument, and returns a string which is used just like BannerString. This way, one can print a custom banner string with dynamic data, such as information about the build configuration for a package with kernel extension.

One alternative suggestion was to just allow setting BannerString to a function. What I don't like about that is that such a package then cannot be loaded by older GAP versions anymore. While with the approach in this PR, a package using either of the two new keys would still be useable in older GAP versions.

Still missing is documentation for these new keys -- but I am not going to write that unless I know we'll (very likely) merge this.

UPDATE: I removed BannerExtra

Closes #2568

@fingolfin fingolfin added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements request for comments do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) topic: packages issues or PRs related to package handling, or specific to a package (for packages w/o issue tracker) topic: library labels Jul 2, 2018
Copy link
Contributor

@ThomasBreuer ThomasBreuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see why BannerExtra is helpful.
Adding extra information just at the end of the default banner (which would have to be documented) is probably not what one wants.
Note that one can easily call DefaultPackageBannerString from the BannerFunction function,
and then modify the returned string as needed.

I would prefer the simpler alternative to admit a function as BannerString.
Note that the feature is anyhow new, and if one wants to use it then it is natural to require, in the package's dependencies, a GAP version that supports it.

@laurentbartholdi
Copy link
Contributor

laurentbartholdi commented Jul 2, 2018 via email

@codecov
Copy link

codecov bot commented Jul 2, 2018

Codecov Report

Merging #2598 into master will increase coverage by <.01%.
The diff coverage is 75%.

@@            Coverage Diff             @@
##           master    #2598      +/-   ##
==========================================
+ Coverage    74.8%    74.8%   +<.01%     
==========================================
  Files         479      479              
  Lines      242251   242254       +3     
==========================================
+ Hits       181206   181211       +5     
+ Misses      61045    61043       -2
Impacted Files Coverage Δ
lib/package.gi 69.86% <75%> (-0.01%) ⬇️
hpcgap/lib/hpc/stdtasks.g 64.19% <0%> (+0.76%) ⬆️

Copy link
Contributor

@laurentbartholdi laurentbartholdi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think that the extra functionality in BannerExtra is best left out. For users who already have BannerExtra set, they can just add

BannerFunction := info->Concatenation(DefaultPackageBannerString(info),info.BannerExtra);

@fingolfin
Copy link
Member Author

Adding data to the default package string is not quite that trivial, and the example @laurentbartholdi gives does not quite work the way I'd expect it to work, because it adds the extra data after the trailing separator line. So, to insert data, one has to split the string into lines, then insert additional lines before the final line, and re-assemble the line (or do something equivalent, e.g. just find the start of the last line, and insert before that.

While this is not very hard, it's cumbersome.

The reason why I thought BannerExtra might be useful is that I expect most people would just want to add info to the default banner, but not change anything else about it. So having a convenient way to do that is, well, convenient. That said, I myself always use the default banner, so I don't mind dropping this again very much.

As to BannerString vs. BannerFunction: For it to have any effect, you indeed need to run a new GAP anyhow. But if you are author of a package that otherwise works great with GAP 4.8, it seems undesirable to me to change it to require GAP 4.10, just to take advantage of a different way of printing banners. By using BannerFunction, your package can still be used in GAP 4.8 (with a default banner).

And of course all of this would have to be documented -- as I stated, I did not yet write documentation because the future of these is unclear (and the discussion here proves that point quite well ;-)

@fingolfin
Copy link
Member Author

@laurentbartholdi your example rather would look like this:

BannerFunction := function(info)
  local l;
  l:=SplitString(DefaultPackageBannerString(info), "\n");
  Add(l, info.BannerExtra, Length(l));
  return JoinStringsWithSeparator(l,"\n");
end;

Anyway, I certainly don't mind not adding BannerExtra if people don't think its useful shrug

@laurentbartholdi
Copy link
Contributor

laurentbartholdi commented Jul 3, 2018 via email

@frankluebeck
Copy link
Member

How many packages are there who potentially want to use these new features? Not many, I guess.

Therefore I would say that ultimate convenience or compatibility with old GAP versions are not a practical issue here.

I would just extend the definition of 'BannerString' and allow to set this to a function that gets the package info record as argument and must return a string (or to a string as before).

@olexandr-konovalov
Copy link
Member

olexandr-konovalov commented Jul 3, 2018

As soon as a package will start to use the extended definition of the BannerString and will have a function there, its development version and its new releases will not be usable with GAP 4.9 release series, and all updates there will be frozen until GAP 4.10. So I do see the point in compatibility achieved by BannerFunction.

Second, as @fingolfin explained, BannerExtra allows to make a small modification of the banner when one does not want to recreate it completely. That seems quite useful to me exactly by his reasoning "I expect most people would just want to add info to the default banner, but not change anything else about it.". In this case, using a functions seems like an unnecessary overhead demanded from package authors.

@olexandr-konovalov
Copy link
Member

P.S. One more thing: the package update mechanism runs the officially released GAP version. So ValidatePackageInfo there will not validate any new release of the package which will have a function in BannerString because it is not a string. That's why it's much simpler to introduce a new field rather then to change an existing one.

This can be used instead of (or in addition to) BannerString: If present,
BannerFunction must be set to a function taking one argument, which is the
info record, and must return a string which is used as banner string for the
package.

If both `BannerFunction` and `BannerString` are present, only the former is
used and the latter is ignored.
@fingolfin fingolfin changed the title Add BannerExtra and BannerFunction to PackageInfo.g Add BannerFunction to PackageInfo.g Jul 4, 2018
@fingolfin
Copy link
Member Author

I have no removed BannerExtra. I still think having BannerFunction separate from BannerString is useful, as explained, even though right now I only know of two packages which might use this (JuliaInterface and float)

Copy link
Member

@olexandr-konovalov olexandr-konovalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with the current form now (i.e. with just one new BannerFunction component. But where this should be documented? Perhaps in the Example package, in its PackageInfo.g file. You can provide an example, comment it out, and also write in the comment that this will be available since GAP 4.10.

@fingolfin
Copy link
Member Author

@laurentbartholdi is this OK for you now? then please remove your "request for changes" flag, or even approve it. If not, then please state what you'd like to see changed. Thanks!

@alex-konovalov I think documenting this in doc/ref/gappkg.xml is enough, no need to put this obscure thing into the example package. But I'd like to see a major overhaul of doc/ref/gappkg.xml happening, to make it easier to find each possible record name possible in a package info record.

@olexandr-konovalov
Copy link
Member

olexandr-konovalov commented Jul 6, 2018

@fingolfin doc/ref/gappkg.xml refers to the template in Example, and does not describe it in great details otherwise. Unless you really want to spend time now and document all of PackageInfo.g there, doing that in the Example package for now is what I'd strongly advise.

@olexandr-konovalov
Copy link
Member

olexandr-konovalov commented Aug 11, 2018

@fingolfin I'd definitely want this to be documented before merging, and unless you have time for a a major overhaul of doc/ref/gappkg.xml now (what I really doubt), could you please just document that (and provide a commented out example) in comments in https://github.com/gap-packages/example/blob/master/PackageInfo.g, and then we could merge this?

@olexandr-konovalov
Copy link
Member

@fingolfin Alternatively, we can merge this first, and I will remember to add text to https://github.com/gap-packages/example/blob/master/PackageInfo.g

@fingolfin
Copy link
Member Author

I agree that documenting this first in the example package is the pragmatic solution for now; an overhaul of gappkg, while IMHO desirable, still might never happen.

Here is some text for the example package:

##  *Optional*: if you need a custom BannerString but would like to include
##  information in it that is only available once your package is being loaded
##  (i.e., which is computed in your init.g file, such as the presence and
##  versions of external software your package depends on), then you can
##  use a BannerFunction instead. The difference is that the BannerString is
##  usually computed when GAP starts, i.e., long before your init.g is run.
##  While the BannerFunction is called right before the banner is to be
##  displayed, which is after your init.g has been executed.
##
# BannerFunction := function(info)
#       local l;
#       # modify the default banner string, and insert something before
#       # its last line (which is a separator string)
#       l:=SplitString(DefaultPackageBannerString(info), "\n");
#       Add(l, " ...  some extra information ... ", Length(l));
#       return JoinStringsWithSeparator(l,"\n");
#     end,

Copy link
Member

@olexandr-konovalov olexandr-konovalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the text for PackageInfo.g - happy to merge this now.

@olexandr-konovalov olexandr-konovalov removed the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label Sep 2, 2018
@olexandr-konovalov olexandr-konovalov merged commit d1b62ac into gap-system:master Sep 2, 2018
olexandr-konovalov pushed a commit to gap-packages/example that referenced this pull request Sep 2, 2018
It will appear in GAP 4.10, being introduced in gap-system/gap#2598
@olexandr-konovalov
Copy link
Member

@fingolfin great. Text added to Example package's PackageInfo.g in gap-packages/example@aae6a93

@olexandr-konovalov olexandr-konovalov deleted the mh/Banner branch September 2, 2018 20:16
@fingolfin fingolfin added the release notes: added PRs introducing changes that have since been mentioned in the release notes label Sep 21, 2018
@fingolfin fingolfin added kind: discussion discussions, questions, requests for comments, and so on and removed kind: request for comments labels Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: discussion discussions, questions, requests for comments, and so on kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: added PRs introducing changes that have since been mentioned in the release notes topic: library topic: packages issues or PRs related to package handling, or specific to a package (for packages w/o issue tracker)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants