Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 4183461<!-- %W hints.xml GAP documentation Greg Gamble -->2<!-- %H -->3<!-- %Y Copyright (C) 2001, School of Math & Comp. Sci., St Andrews, Scotland -->45<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->6<Appendix Label="Guidelines for Writing a GAP Package">7<Heading>Guidelines for Writing a GAP Package</Heading>89This appendix explains the basics of how to write a &GAP; package so that10it interfaces properly to &GAP;. For the role of &GAP; packages and the11ways to load them, see Chapter <Ref Chap="Using GAP Packages" BookName="ref"/>.12<P/>1314There are two basic aspects of creating a &GAP; package.15<P/>1617First, it is a convenient possibility to load additional functionality into18&GAP; including a smooth integration of the package documentation. Second,19a package is a way to make your code available to other &GAP; users.20<P/>2122Moreover, the &GAP; Group may provide some help with redistributing your23package via the web and ftp site of GAP itself after checking if the24package provides some new or improved functionality which looks interesting25for other users, if it contains reasonable documentation, and if it seems26to work smoothly with the GAP library and other distributed packages. In27this case the package can take part in the &GAP; distribution update28mechanism and becomes a <E>deposited</E> package.29<P/>3031Furthermore, package authors are encouraged to check if the package would32be appropriate for the refereeing process and <E>submit</E> it. If the33refereeing has been successful, the package becomes an <E>accepted</E>34package. Check out the &GAP; Web site <URL>http://www.gap-system.org</URL>35for more details.36<P/>3738We start this chapter with a description how the directory structure of a39&GAP; package should be constructed and then add remarks on certain aspects40of creating a package, some of these only apply to some packages. Finally,41we provide guidelines for the release preparation, wrapping and42distribution.43<P/>44<!--45The &Example; package is intended to be a prototype for a package. Here46we describe just what features one should emulate when writing one's own47&GAP; package for popular consumption, and a few pointers as to where to48go for more information.49-->5051<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->52<Section Label="Structure of a GAP Package">53<Heading>Structure of a GAP Package</Heading>5455<Index Subkey="for a GAP package">home directory</Index>56A &GAP; package should have an alphanumeric name (<A>package-name</A>, say);57mixed case is fine, but there should be no whitespaces.58All files of a &GAP; package <A>package-name</A> must be collected in a59single directory <A>package-dir</A>, where <A>package-dir</A> should be60just <A>package-name</A> preferably converted to lowercase and optionally61followed by the package version (with or without hyphen to separate the62version from <A>package-name</A>).63Let us call this directory the <E>home directory</E> of the package.64<P/>65To use the package with &GAP;, the directory <A>package-dir</A> must66be a subdirectory of a <F>pkg</F> directory in (one of) the &GAP; root67directories (see <Ref Sect="GAP Root Directories" BookName="ref"/>).68For example, if &GAP; is installed in <F>/usr/local/gap4</F> then the69files of the package <C>MyPack</C> may be placed in the directory70<F>/usr/local/gap4/pkg/mypack</F>.7172The directory <A>package-dir</A> preferably should have the following73structure (below, a trailing <C>/</C> distinguishes directories from74ordinary files):75<P/>76<Alt Only="LaTeX">\newpage</Alt>77<Log><![CDATA[78package-dir/79doc/80lib/81src/82tst/83README84CHANGES85configure86Makefile.in87PackageInfo.g88init.g89read.g90]]></Log>91<P/>9293There are three file names with a special meaning in the home94directory of a package: <F>PackageInfo.g</F> and <F>init.g</F>95which must be present, and <F>read.g</F> which is optional.96We now describe the above files and directories:97<P/>9899<List>100101<Mark>102<F>README</F></Mark>103<Item>104<Index Key="README" Subkey="for a GAP package"><C>README</C></Index>105This should contain <Q>how to get it</Q> (from the &GAP; <C>ftp</C>- and106web-sites) instructions, as well as installation instructions and names107of the package authors and their email addresses. The installation108instructions should be repeated in the package's documentation, which109should be in the <F>doc</F> directory110(see <Ref Sect="Writing Documentation and Tools Needed"/>).111Authors' names and addresses should be repeated both in the package's112documentation and in the <File>PackageInfo.g</File> (see below).113</Item>114115<Mark>116<F>CHANGES</F></Mark>117<Item>118For further versions of the package, it will be also useful to have a119<F>CHANGES</F> file that records the main changes between versions120of the package.121</Item>122123<Mark><F>configure</F>, <F>Makefile.in</F></Mark>124<Item>125These files are only necessary if the package has a non-&GAP; component,126e.g. some C code (the files of which should be in the <F>src</F>127directory). The <F>configure</F> and <F>Makefile.in</F> files of the &Example;128package provide prototypes. The <F>configure</F> file typically takes a path129<A>path</A> to the &GAP; root directory as argument and uses the value130assigned to <C>GAParch</C> in the file <F>sysinfo.gap</F>, created when &GAP;131was compiled to determine the132compilation architecture, inserts this in place of the string <C>@GAPARCH@</C>133in <F>Makefile.in</F> and creates a file <F>Makefile</F>. When <C>make</C> is134run (which, of course, reads the constructed <F>Makefile</F>), a directory135<F>bin</F> (if necessary) and subdirectories of <F>bin</F> with the path equal136to the string assigned to <C>GAParch</C> in the file <F>sysinfo.gap</F> should137be created; any binaries constructed by compiling the code in <F>src</F> should138end up in this subdirectory of <F>bin</F>.139</Item>140141<Mark><F>PackageInfo.g</F></Mark>142<Item>143<Index Key="PackageInfo.g" Subkey="for a GAP package"><C>PackageInfo.g</C></Index>144Since &GAP; 4.4, a &GAP; package <E>must</E> have a <F>PackageInfo.g</F>145file which contains meta-information about the package (package name, version,146author(s), relations to other packages, homepage, download archives, banner,147...). This information is used by the package loading mechanism and also for148the distribution of a package to other users. The &Example; package's149<F>PackageInfo.g</F> file is well-commented and should be used as a150prototype (see also <Ref Sect="The PackageInfo.g File"/> for further details).151</Item>152153<Mark><F>init.g</F>, <F>read.g</F></Mark>154<Item>155<Index Key="init.g" Subkey="for a GAP package"><C>init.g</C></Index>156<Index Key="read.g" Subkey="for a GAP package"><C>read.g</C></Index>157A &GAP; package <E>must</E> have a file <F>init.g</F>. As of &GAP; 4.4,158the typical <F>init.g</F> and <F>read.g</F> files should normally consist159entirely of <Ref Func="ReadPackage" BookName="ref"/> commands (and possibly160also <Ref Func="Read" BookName="ref"/> commands) for reading further files161of the package. If the <Q>declaration</Q> and <Q>implementation</Q> parts of162the package are separated (and this is recommended), there should be a163<F>read.g</F> file.164The <Q>declaration</Q> part165of a package consists of function and variable <E>name</E> declarations and166these go in files with <C>.gd</C> extensions; these files are read in via167<C>ReadPackage</C> commands in the <F>init.g</F> file. The <Q>implementation</Q> part168of a package consists of the actual definitions of the functions and169variables whose names were declared in the <Q>declaration</Q> part, and170these go in files with <C>.gi</C> extensions; these files are read in via171<C>ReadPackage</C> commands in the <F>read.g</F> file. The reason for following the172above dichotomy is that the <F>read.g</F> file is read <E>after</E> the <F>init.g</F>173file, thus enabling the possibility of a function's implementation to174refer to another function whose name is known but is not actually defined175yet (see <Ref Sect="Declaration and Implementation Part of a Package"/>176below for more details).177<P/>178The &GAP; code (whether or not it is split into <Q>declaration</Q> and179<Q>implementation</Q> parts) should go in the package's <F>lib</F> directory180(see below).181</Item>182183<Mark><F>doc</F></Mark>184<Item>185<Index Key="GAPDoc" Subkey="for writing package documentation">GAPDoc format</Index>186<Index Key="gapmacro.tex" Subkey="for writing package documentation"><C>gapmacro.tex</C> format</Index>187This directory should contain the package's documentation.188It is strongly recommended to use an XML-based documentation format189supported by the &GAP; package &GAPDoc;190(see <Ref Sect="Introduction and Example" BookName="gapdoc"/>)191which is used for the &GAP; documentation. An alternative is to use the192&TeX;-based system, formerly used for the &GAP; documentation in193&GAP; 4.4 and earlier releases. This system is described in194the document <Q>The gapmacro.tex Manual Format</Q>195(the file <F>gap4r5/doc/gapmacrodoc.pdf</F> included in the196tools archive as described in Section197<Ref Sect="Writing Documentation and Tools Needed"/>)198and is still used by some of the &GAP; packages whose authors are199encouraged to switch at some point to the &GAPDoc;-based documenation.200Please spend some time reading the documentation for whichever201system you decide to use for writing your package's documentation.202The &Example; package's documentation is written in the XML format203supported by the <Package>GAPDoc</Package> package.204If you intend to use this format, please use the &Example;205package's <F>doc</F> directory as a prototype, which as you will observe206contains the master file <F>main.xml</F>, further <F>.xml</F> files for207manual chapters (included in the manual via <C>Include</C> directives in208the master file) and the &GAP; input file <F>../makedocrel.g</F> which209generates the manuals.210Generally, one should also provide a <F>manual.bib</F> Bib&TeX; database211file or an <F>xml</F> file in the BibXMLext format (see212<Ref Sect="The BibXMLext Format" BookName="gapdoc"/>).213With <F>gapmacro.tex</F>, it is also possible to use a <F>manual.bbl</F> file.214<!-- Generating the215various formats of the manuals requires various software tools which are216called directly or indirectly by <C>make&uscore;doc</C> and these are listed in217Section <Ref Sect="Writing Documentation and Tools Needed"/>. The file <C>manual.mst</C> is218needed for generating a manual index; it should be a copy of the one219provided in the &Example; package. The only adjustments that a package220writer should need to make to <C>make&uscore;doc</C> is to replace occurrences of the221word <C>Example</C> with <A>package-name</A>. -->222</Item>223224<Mark><F>lib</F></Mark>225<Item>226This is the preferred place for the &GAP; code, i.e. the <C>.g</C>, <C>.gd</C> and227<C>.gi</C> files (other than <F>PackageInfo.g</F>, <F>init.g</F> and <F>read.g</F>). For some228packages, the directory <F>gap</F> has been used instead of <F>lib</F>; <F>lib</F> has the229slight advantage that it is the default subdirectory of a package directory230searched for by the <Ref Func="DirectoriesPackageLibrary" BookName="ref"/> command.231</Item>232233<Mark><F>src</F></Mark>234<Item>235If the package has non-&GAP; code, e.g. C code, then this <Q>source</Q>236code should go in the <F>src</F> directory. If there are <C>.h</C>237<Q>include</Q> files you may prefer to put these all together in a separate238<C>include</C> directory. There is one further rule for the location of kernel239library modules or external programs which is explained in240<Ref Sect="Installation of GAP Package Binaries"/> below.241</Item>242243<Mark><F>tst</F></Mark>244<Item>245If the package has test files, then they should go in the <F>tst</F>246directory. For a deposited package, a test file with a basic test247of the package (for example, to check that it works as expected and/or248that the manual examples are correct) may be specified in the249<File>PackageInfo.g</File> to be included in the &GAP; standard test suite.250More specific and time consuming tests are not supposed to be a part of the251&GAP; standard test suite but may be placed in the <F>tst</F> directory252with further instructions on how to run them.253See Section <Ref Sect="Testing a GAP package"/> about the requirements254to the test files formats and further recommendations.255</Item>256257</List>258259All other files can be organized as you like. But we suggest that you260have a look at existing packages and use a similar scheme, for261example, put examples in the <File>examples</File> subdirectory, data262libraries in extra subdirectories, and so on.263<P/>264Sometimes there may be a need to include an empty directory in the265package distribution (for example, as a place to store some data that266may appear at runtime). In this case package authors are267advised to put in this directory a short <F>README</F> file describing268its purpose to ensure that such directory will be included in the269redistribution.270<P/>271Concerning the &GAP; code in packages, it is recommended to use only272documented &GAP; functions, see <Ref Sect="Undocumented Variables" BookName="ref"/>.273In particular if you want to make your package available to other &GAP; users274it is advisable to avoid using <Q>obsolescent</Q> variables275(see <Ref Chap="Replaced and Removed Command Names" BookName="ref"/>).276For that, you can set the <C>ReadObsolete</C> component in your277<F>gap.ini</F> file to <K>false</K>,278see <Ref Sect="The gap.ini and gaprc files" BookName="ref"/>.279280</Section>281282<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->283<Section Label="Writing Documentation and Tools Needed">284<Heading>Writing Documentation and Tools Needed</Heading>285286If you intend to make your package available to other users it is287essential to include documentation explaining how to install and use your288programs.289<P/>290Concerning the installation you should produce a file <F>README</F> which291gives a short description of the purpose of the package and contains292proper instructions how to install your package. Again, check out some293existing packages to get an idea how this could look like.294<P/>295Concerning the documentation of the use of the package there296are currently two recognised ways of producing &GAP; package297documentation.298<P/>299First, there is a recommended XML-based documentation format300that is defined in and can be used with the &GAPDoc; package301(see <Ref Chap="Introduction and Example" BookName="gapdoc"/>).302<P/>303Second, there is a method which requires the documentation to be304written in &TeX; according to the format described in305the document <Q>The gapmacro.tex Manual Format</Q>.306<P/>307In principle it is also possible to use some completely different308documentation format. In that case you need to study the309Chapter <Ref Chap="Interface to the GAP Help System" BookName="ref"/>310to learn how to make your documentation available to the &GAP; help system.311There should be at least a text version of your documenation provided for use312in the terminal running &GAP; and some nicely printable version in313<C>.pdf</C> format.314Many &GAP; users like to browse the documentation in HTML format315via their Web browser. As a package author, you are not obliged316to provide an HTML version of your package manual, but if you317will either use the &GAPDoc; package or follow the guidelines in318the document <Q>The gapmacro.tex Manual Format</Q>,319(the file <F>gap4r5/doc/gapmacrodoc.pdf</F> included in the320tools archive as described in this Section below),321you should have no trouble in producing one. Moreover, using the322&GAPDoc; package, it is also possible to produce HTML version of the323documentation supporting MathJax (<URL>http://www.mathjax.org/</URL>)324for the high quality rendering of mathematical symbols while viewing325it online. For example, if you are viewing the HTML version of the manual,326compare how this formula will look with MathJax turned on/off:327<Display Mode="M">328[ \chi, \psi ] = \left( \sum_{{g \in G}} \chi(g) \psi(g^{{-1}}) \right) / |G|.329</Display>330<P/>331The manual of the &Example; package is written in the &GAPDoc; format,332and commands needed to build it are contained in the file <C>makedocrel.g</C>333(you don't need to re-build the manual since it is already included in the package).334<P/>335Whenever you use the <Package>GAPDoc</Package> or <F>gapmacro.tex</F> &TeX;-based336system, you need to have certain &TeX; tools installed: to produce manuals337in the <C>.pdf</C> format, you need <C>pdflatex</C> if the <Package>GAPDoc</Package>338is used, and either <C>pdftex</C> or <C>gs</C> together with <C>ps2pdf</C> if your339package uses <F>gapmacro.tex</F>.340Note that using <C>gs</C> and <C>ps2pdf</C> in lieu of <C>pdftex</C> or341<C>pdflatex</C> is a poor substitute unless your <C>gs</C> is at least342version 6.<A>xx</A> for some <A>xx</A>.343In addition, the <C>gapmacro.tex</C> documentation system requires some more tools344described below. If you intend to use the &GAPDoc; package for the documenation345of your package, you may skip the rest of this section and proceed to the next one346to see a minimalistic example of a &GAP; package.347<P/>348<Index>tools archive for package authors</Index>349Otherwise, to produce the <C>.pdf</C> manual formats, the following &GAP;350tools (supplied as a part of the &GAP; distribution in the archive351<C>tools.tar.gz</C> in the in &GAP;'s <F>etc</F> directory and installed352using the script <F>install-tools.sh</F> in the same directory) are needed:353<F>gapmacro.tex</F>354(the macros file that dictates the style and mark-up for the traditional355&TeX;-based system of &GAP; documentation),356<C>manualindex</C>357(an <C>awk</C> script that adjusts the &TeX;-produced index entries358and calls <C>makeindex</C> to process them),359and360<F>mrabbrev.bib</F>361(usually supplied with your &TeX; tools but nevertheless a copy of362<F>mrabbrev.bib</F> should be located in &GAP;'s main <F>doc</F> directory.363To find it on your system, try: <C>kpsewhich mrabbrev.bib</C> or, if that364doesn't work and you can't otherwise find it check out a CTAN site,365e.g. search for it at: <URL>http://www.dante.de/cgi-bin/ctan-index</URL>.366<P/>367If your manual cross-refers to <Package>GAPDoc</Package>- or368<F>gapmacro.tex</F>-produced manuals, then <C>manual.lab</C>369for each such other manual is needed. For packages using370<Package>GAPDoc</Package>-manuals since &GAP; 4.3,371this is done by starting &GAP; and running372<P/>373 <C>gap> GapDocManualLab( "<A>package</A>" );</C>374<P/>375<Alt Only="LaTeX">\noindent</Alt>376for each such <A>package</A> whose manual is cross-referred to377(this includes the <Q>main</Q> manuals, e.g. those in the378<F>doc/ref</F> and <F>doc/tut</F> directories).379For packages using <F>gapmacro.tex</F>-produced manuals,380<C>manual.lab</C> is generated by running <C>tex manual</C>381for each package whose manual is cross-referred to.382In most cases, packages from the &GAP; distribution will already383have these files since they will be created as a part of building their384manuals (see e.g. the last command of the <F>example/makedocrel.g</F> script)385and included in their distribution, so you will probably not need to386create <C>manual.lab</C> files yourself.387<P/>388To produce an HTML version of the manual one needs the Perl 5 program389<F>convert.pl</F> which is included in the tools archive <C>tools.tar.gz</C>.390This archive is supplied as a part of the &GAP; distribution in the &GAP;'s391<F>etc</F> directory and should be installed using the script392<F>install-tools.sh</F> in the same directory.393<P/>394Finally, to ensure the mathematical formulae are rendered as well as they395can be in the HTML version, one should also have the program <C>tth</C>396(&TeX; to HTML converter); <F>convert.pl</F> calls <F>tth</F> to translate397mathmode formulae to HTML (if it's available). The <F>tth</F> program is easy398to compile and can be obtained from399<URL>http://hutchinson.belmont.ma.us/tth/tth-noncom/download.html</URL>.400<!--401A prototype of the command to execute is in the file <F>make_doc</F>;402note that the HTML manual is produced in files with <C>.htm</C> extensions403in a directory <F>htm</F> outside the <F>doc</F> directory. The beginning404of the file <F>convert.pl</F> contains instructions on its usage should405you need them.406-->407<P/>408409</Section>410411412<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->413<Section Label="An Example of a GAP Package">414<Heading>An Example of a GAP Package</Heading>415416We illustrate the creation of a &GAP; package by an example of a basic package.417<P/>418Create the following directories in your home area:419<F>.gap</F>, <F>.gap/pkg</F> and <F>.gap/pkg/test</F>.420Then inside the directory <F>.gap/pkg/test</F> create an empty file421<F>init.g</F>, and a file <F>PackageInfo.g</F> with the following contents:422<P/>423<Log><![CDATA[424SetPackageInfo( rec(425PackageName := "test",426Version := "1.0",427PackageDoc := rec(428BookName := "test",429SixFile := "doc/manual.six",430Autoload := true ),431Dependencies := rec(432GAP := "4.5",433NeededOtherPackages := [ ["GAPDoc", "1.3"] ],434SuggestedOtherPackages := [ ] ),435AvailabilityTest := ReturnTrue ) );436]]></Log>437<P/>438This file declares the &GAP; package with name <Q>test</Q> in version 1.0.439The package documentation consists of one autoloaded book; the <C>SixFile</C>440component is needed by the &GAP; help system. Package dependencies require at441least &GAP; 4.5 and &GAPDoc; package at version at least 1.3, and these442conditions will be checked when the package will be loaded443(see <Ref Sect="Version Numbers"/>).444Since there are no requirements that have to be tested,445<C>AvailabilityTest</C> just uses <Ref Func="ReturnTrue" BookName="ref"/>.446<P/>447Now start &GAP; (without using the <C>-r</C> option) and the <F>.gap</F>448directory will be added to the &GAP; root directory to449allow &GAP; to find the packages installed there450(see <Ref Sect="GAP Root Directories" BookName="ref"/>).451<P/>452<Log><![CDATA[453gap> LoadPackage("test");454true455]]></Log>456<P/>457This &GAP; package is too simple to be useful, but we have succeeded458in loading it via <Ref Func="LoadPackage" BookName="ref"/>, satisfying459all specified dependencies.460461</Section>462463464<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->465<Section Label="File Structure">466<Heading>File Structure</Heading>467468Package files may follow the style used for the &GAP; library.469Every file in the &GAP; library starts with a header that lists the470filename, copyright, a short description of the file contents and the471original authors of this file, and ends with a comment line <C>#E</C>.472Indentation in functions and the use of decorative spaces in the code473are left to the decision of the authors of each file. Global (i.e.474re-used elsewhere) comments usually are indented by two hash marks and475two blanks, in particular, every declaration or method or function476installation which is not only of local scope is separated by a header.477<P/>478Historically, when the &GAP; main manuals were based on the &TeX; macros479described in the document <Q>The gapmacro.tex Manual Format</Q>480(the file <F>gap4r5/doc/gapmacrodoc.pdf</F> included in the481tools archive as described in Section482<Ref Sect="Writing Documentation and Tools Needed"/>)483such headers were used for the manuals and have the type484<P/>485<Log><![CDATA[486#############################################################################487##488#X ExampleFunction(<A>,<B>)489##490## This function does great things.491]]></Log>492<P/>493where <Q>X</Q> was one of the letters: <C>F</C>, <C>A</C>, <C>P</C>, <C>O</C>,494<C>C</C>, <C>R</C> or <C>V</C> indicating whether the object declared will495be a function, attribute, property, operation, category, representation or496variable, respectively. Additionally <C>M</C> was used in <C>.gi</C> files497for method installations. Then a sample usage of the function was given,498followed by a comment which described the identifier.499This description was automatically be extracted to build the500manual source, if there is a <C>\Declaration</C> line in some501<C>.msk</C> file together with an appropriate configuration file.502<P/>503Nowadays, facilities to distribute a document over several files504to allow the documentation for parts of some code to be stored in505the same file as the code itself are provided by the &GAPDoc; package (see506<Ref Sect="Distributing a Document into Several Files" BookName="gapdoc"/>).507The same approach is demonstrated by the <Package>Example</Package> package.508E.g. <F>example/doc/example.xml</F> has the statement509<C><#Include Label="ListDirectory"></C>510and <F>example/lib/files.gd</F> contains511<Log><![CDATA[512#############################################################################513##514#F ListDirectory([<dir>]) . . . . . . . . . . list the files in a directory515##516## <#GAPDoc Label="ListDirectory">517## <ManSection>518## <Func Name="ListDirectory" Arg="[dir]"/>519##520## <Description>521## lists the files in directory <A>dir</A> (a string)522## or the current directory if called with no arguments.523## </Description>524## </ManSection>525## <#/GAPDoc>526DeclareGlobalFunction( "ListDirectory" );527]]></Log>528This is all put together in the file <F>example/makedocrel.g</F> which529builds the package documentation, calling530<Ref Func="MakeGAPDocDoc" BookName="gapdoc"/> with531locations of library files containing parts of the532documentation.533534</Section>535536537538<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->539<Section Label="The PackageInfo.g File">540<Heading>The PackageInfo.g File</Heading>541<Index Key="ValidatePackageInfo"><C>ValidatePackageInfo</C></Index>542As a first step the example in <Ref Sect="An Example of a GAP Package"/>543shows the information needed for the package loading mechanism to load544a simple package. However, if your package depends on the functionality545of other packages, the component <C>Dependencies</C> given in the546<F>PackageInfo.g</F> file becomes important547(see <Ref Label="Package dependencies"/> below),548and more entries become relevant if you want to549distribute your package: they contain lists of authors and/or550maintainers including contact information, URLs of the package archives551and README files, status information, text for a package overview Web552page, and so on.553<P/>554We suggest to create a <F>PackageInfo.g</F> file for your package by555copying the one in the <Package>Example</Package> package,556distributed with &GAP;, and then adjusting it for your package.557Within &GAP; you can look at this template file for a list and explanation558of all recognized entries by559<Log><![CDATA[560Pager(StringFile(Filename(DirectoriesLibrary(),561"../pkg/example/PackageInfo.g")));562]]></Log>563<P/>564Once you have created the <F>PackageInfo.g</F> file for your package,565you can test its validity with the function566<Ref Func="ValidatePackageInfo" BookName="ref"/>.567568</Section>569570571572<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->573<Section Label="Functions and Variables and Choices of Their Names">574<Heading>Functions and Variables and Choices of Their Names</Heading>575576In writing the &GAP; code for your package you need to be a little577careful on just how you define your functions and variables.578<P/>579<E>Firstly</E>, in general one should avoid defining functions and variables580via assignment statements in the way you would interactively, e.g.581<P/>582<Example><![CDATA[583gap> Squared := x -> x^2;;584gap> Cubed := function(x) return x^3; end;;585]]></Example>586<P/>587The reason for this is that such functions and variables are <E>easily588overwritten</E> and what's more you are not warned about it when it happens.589<P/>590To protect a function or variable against overwriting there is the591command <Ref Func="BindGlobal" BookName="ref"/>,592or alternatively (and equivalently) you may define a global593function via a <Ref Func="DeclareGlobalFunction" BookName="ref"/>594and <Ref Func="InstallGlobalFunction" BookName="ref"/> pair595or a global variable via a <Ref Func="DeclareGlobalVariable" BookName="ref"/>596and <Ref Func="InstallValue" BookName="ref"/> pair. There are also operations597and their methods, and related objects like attributes and filters which598also have <C>Declare...</C> and <C>Install...</C> pairs.599<P/>600<E>Secondly</E>, it's a good idea to reduce the chance of accidental601overwriting by choosing names for your functions and variables that begin602with a string that identifies it with the package, e.g. some of the603undocumented functions in the &Example; package begin with <C>Eg</C>. This is604especially important in cases where you actually want the user to be able605to change the value of a function or variable defined by your package,606for which you have used direct assignments (for which the user will607receive no warning if she accidentally overwrites them). It's also608important for functions and variables defined via <C>BindGlobal</C>,609<C>DeclareGlobalFunction</C>/<C>InstallGlobalFunction</C> and610<C>DeclareGlobalVariable</C>/<C>InstallValue</C>, in order to avoid name clashes611that may occur with (extensions of) the &GAP; library and other612packages.613<P/>614<Index Subkey="for a GAP package">local namespace</Index>615Additionally, since &GAP; 4.5 a package may place global variables into616a local namespace as explained in617<Ref Sect="Namespaces for GAP Packages" BookName="ref"/> in order to avoid618name clashes and preserve compatibility. This new feature619allows you to define in your package global variables with the identifier620ending with the <C>@</C> symbol, e.g. <C>xYz@</C>. Such variables may be used621in your package code safely, as they may be accessed from outside the package622only by their full name, i.e. <C>xYz@YourPackageName</C>. This helps to prevent623clashes between different packages or between a package and the &GAP; library624because of the same variable names.625<!-- TODO: demonstrate in the example package how this is actually used -->626<P/>627On the other hand, operations and their methods (defined via628<Ref Func="DeclareOperation" BookName="ref"/>,629<Ref Func="InstallMethod" BookName="ref"/> etc. pairs)630and their relatives do not need this consideration, as they631avoid name clashes by allowing for more than one <Q>method</Q>632for the same-named object.633<P/>634To demonstrate the definition of a function via a635<C>DeclareOperation</C>/<C>InstallMethod</C> pair,636the method <Ref Oper="Recipe"/> was included in the &Example; package;637<C>Recipe( FruitCake );</C> gives a <Q>method</Q> for making a638fruit cake (forgive the pun).639<P/>640<E>Thirdly</E>, functions or variables with <C>Set<A>XXX</A></C> or <C>Has<A>XXX</A></C> names641(even if they are defined as operations) should be avoided as these may642clash with objects associated with attributes or properties (attributes643and properties <A>XXX</A> declared via the <C>DeclareAttribute</C> and644<C>DeclareProperty</C> commands have associated with them testers of form645<C>Has<A>XXX</A></C> and setters of form <C>Set<A>XXX</A></C>).646<P/>647<E>Fourthly</E>, it is a good idea to have some convention for internal648functions and variables (i.e. the functions and variables you don't649intend for the user to use). For example, they might be entirely650CAPITALISED.651<P/>652Additionally, there is a recommended naming convention that the &GAP; core653system and &GAP; packages should not use global variables starting in the654lowercase. This allows to reserve variables with names starting in lowecase655to the &GAP; user so they will never clash with the system. It is extremely656important to avoid using for package global variables very short names657started in lowercase. For example, such names like <C>cs</C>, <C>exp</C>,658<C>ngens</C>, <C>pc</C>, <C>pow</C> which are perfectly fine for local659variables, should never be used for globals. Additionally, the package must660not have writable global variables with very short names even if they are661starting in uppercase, for example, <C>C1</C> or <C>ORB</C>, since they662also could be easily overwritten by the user.663<P/>664It is a good practice to follow naming conventions used in &GAP; as665explained in <Ref Sect="Naming Conventions" BookName="ref"/> and666<Ref Sect="Changing the Structure" BookName="tut"/>, which667might help users to memorize or even guess names of functions668provided by the package.669<P/>670<E>Finally</E>, note the advantage of using671<C>DeclareGlobalFunction</C>/<C>InstallGlobalFunction</C>,672<C>DeclareGlobalVariable</C>/<C>InstallValue</C>, etc. pairs (rather than673<C>BindGlobal</C>) to define functions and variables, which allow the package674author to organise her function- and variable- definitions in any order675without worrying about any interdependence. The <C>Declare...</C> statements676should go in files with <C>.gd</C> extensions and be loaded by <C>ReadPackage</C>677statements in the package <F>init.g</F> file, and the <C>Install...</C> definitions678should go in files with <C>.gi</C> extensions and be loaded by <C>ReadPackage</C>679statements in the package <F>read.g</F> file; this ensures that the <C>.gi</C>680files are read <E>after</E> the <C>.gd</C> files. All other package code should go681in <C>.g</C> files (other than the <F>init.g</F> and <F>read.g</F> files themselves) and682be loaded via <C>ReadPackage</C> statements in the <F>init.g</F> file.683<P/>684685<Index Key="ShowPackageVariables"><C>ShowPackageVariables</C></Index>686In conclusion, here is some practical advice on how to check which variables687are used by the package.688<P/>689Firstly, there is a function690<Ref Func="ShowPackageVariables" BookName="ref"/>.691If the package <A>pkgname</A> is available692but not yet loaded then <C>ShowPackageVariables( pkgname )</C>693prints a list of global variables that become bound and of methods694that become installed when the package is loaded (for that, the package695will be actually loaded, so <C>ShowPackageVariables</C> can be called696only once for the same package in the same &GAP; session.)697The second optional argument <A>version</A> may specify a particular698package version to be loaded.699An error message will be printed if (the given version of) the package700is not available or already loaded.701<P/>702Info lines for undocumented variables will be marked with an asterisk703<C>*</C>. Note that the &GAP; help system is case insensitive,704so it is difficult to document identifiers that differ only by case.705<P/>706The following entries are omitted from the list:707default setter methods for attributes and properties that are declared708in the package,709and <C>Set<A>attr</A></C> and <C>Has<A>attr</A></C> type variables710where <A>attr</A> is an attribute or property.711<P/>712For example, for this package it currently produces the following output:713<Log><![CDATA[714gap> ShowPackageVariables("example");715----------------------------------------------------------------716Loading Example 3.3 (Example/Template of a GAP Package)717by Werner Nickel (http://www.mathematik.tu-darmstadt.de/~nickel),718Greg Gamble (http://www.math.rwth-aachen.de/~Greg.Gamble), and719Alexander Konovalov (http://www.cs.st-andrews.ac.uk/~alexk/).720----------------------------------------------------------------721new global functions:722EgSeparatedString( str, c )*723FindFile( dir, file )724HelloWorld( )725ListDirectory( arg )726LoadedPackages( )727WhereIsPkgProgram( prg )728Which( prg )729730new global variables:731FruitCake732733new operations:734Recipe( arg )735736new methods:737Recipe( cake )738]]></Log>739740Another trick is to start &GAP; with <C>-r -A</C> options, immediately741load your package and then call <Ref Func="NamesUserGVars" BookName="ref"/>742which returns a list of the global variable names created since the743library was read, to which a value is currently bound. For example, for the744<Package>Example</Package> it produces745<Log><![CDATA[746gap> NamesUserGVars();747[ "EgSeparatedString", "FindFile", "FruitCake", "HelloWorld", "ListDirectory",748"LoadedPackages", "Recipe", "WhereIsPkgProgram", "Which" ]749]]></Log>750but for packages with dependencies it will also contain variables created by751other packages. Nevertheless, it may be a useful check to search for unwanted752variables appearing after package loading. A potentially dangerous situation753which should be avoided is when the package uses some simply named temporary754variables at the loading stage. Such <Q>phantom</Q> variables may then remain755unnoticed and, as a result, there will be no warnings if the user occasionally756uses the same name as a local variable name in a function. Even more757dangerous is the case when the user variable with the same name already exists758before the package is loaded so it will be silently overwritten.759760</Section>761762763<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->764<Section Label="Package dependencies">765<Heading>Package Dependencies (Requesting one &GAP; Package from within Another)</Heading>766767<Index>needed package</Index>768<Index>suggested package</Index>769<Index Subkey="for a GAP package">dependencies</Index>770It is possible for one &GAP; package <C>A</C>, say,771to require another package <C>B</C>.772For that, one simply adds the name and the (least) version number of the773package <C>B</C> to the <C>NeededOtherPackages</C> component of the774<C>Dependencies</C> component of the <F>PackageInfo.g</F> file of the package775<C>A</C>.776In this situation, loading the package <C>A</C> forces that also the package777<C>B</C> is loaded, and that <C>A</C> cannot be loaded if <C>B</C> is not778available.779<P/>780781If <C>B</C> is not essential for <C>A</C> but should be loaded if it is782available783(for example because <C>B</C> provides some improvements of the main system784that are useful for <C>A</C>)785then the name and the (least) version number of <C>B</C> should be added to786the <C>SuggestedOtherPackages</C> component of the787<C>Dependencies</C> component of the <F>PackageInfo.g</F> file of <C>A</C>.788In this situation, loading <C>A</C> forces an attempt to load also <C>B</C>,789but <C>A</C> is loaded even if <C>B</C> is not available.790<P/>791792Also the component <C>Dependencies.OtherPackagesLoadedInAdvance</C> in793<F>PackageInfo.g</F> is supported, which describes needed packages that794shall be loaded before the current package is loaded.795See <Ref Sect="Declaration and Implementation Part of a Package"/>796for details about this and more generally about the order in which the files797of the packages in question are read.798<P/>799800All package dependencies must be documented explicitly in the801<File>PackageInfo.g</File> file. It is important to properly802identify package dependencies and make the right decision803whether the other package should be <Q>needed</Q> or <Q>suggested</Q>.804For example, declaring package as <Q>needed</Q> when <Q>suggested</Q>805might be sufficient may prevent loading of packages under Windows for806no good reason.807<P/>808809It is not appropriate to explicitly call810<Ref BookName="ref" Func="LoadPackage"/> <E>when the package is loaded</E>,811since this may distort the order of package loading and result in warning812messages. It is recommended to turn such dependencies into needed or813suggested packages. For example, a package can be designed in such a way814that it can be loaded with restricted functionality if another package815(or standalone program) is missing, and in this case the missing package816(or binary) is <E>suggested</E>. Alternatively, if the package author817decides that loading the package in this situation makes no sense,818then the missing component is <E>needed</E>.819<P/>820821On the other hand, if <Ref BookName="ref" Func="LoadPackage"/> is called822inside functions of the package then there is no such problem, provided823that these functions are called only after the package has been loaded,824so it is not necessary to specify the other package as suggested. The same825applies to test files and manual examples, which may be simply extended826by calls to <Ref BookName="ref" Func="LoadPackage"/>.827<P/>828829<Index Key="OnlyNeeded" Subkey="option"><C>OnlyNeeded</C></Index>830It may happen that a package B that is listed as a suggested831package of package A is actually needed by A.832If no explicit <Ref BookName="ref" Func="LoadPackage"/> calls for B833occur in A at loading time, this can now be detected using834the new possibility to load a package without loading its suggested835packages using the global option <C>OnlyNeeded</C> which836can be used to (recursively) suppress loading the suggested packages837of the package in question. Using this option, one can check whether838errors or warnings appear when B is not available (note that this option839should be used only for such checks to simulate the situation when840package B is not available; it is not supposed to be used in an actual841&GAP; session when package B will be loaded later, since this may cause842problems). In case of any errors or warnings, their consequence can843then be either turning B into a needed package or (since apparently B844was not intended to become a needed package) changing the code accordingly.845Only if package A calls <Ref BookName="ref" Func="LoadPackage"/> for B at846loading time (see above) then package B needs to be <E>deinstalled</E>847(i.e. removed) to test loading of A without B.848<!-- TODO: write a new subsection in Reference manual Chapter 77 GAP849Packages how to uninstall GAP package and refer to it from "Example".-->850<P/>851852Finally, if the package manual is in the &GAPDoc; format,853then &GAPDoc; should still be listed as <E>needed</E> for854this package (not as <E>suggested</E>), even though &GAPDoc;855is now a needed package for &GAP; itself.856<P/>857858</Section>859860861862<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->863<Section Label="Declaration and Implementation Part of a Package">864<Heading>Declaration and Implementation Part of a Package</Heading>865866When &GAP; packages require each other in a circular way,867a <Q>bootstrapping</Q> problem arises of defining functions before they are868called.869The same problem occurs in the &GAP; library, and it is resolved there870by separating declarations (which define global variables such as871filters and operations)872and implementations (which install global functions and methods)873in different files.874Any implementation file may use global variables defined in any declaration875file.876&GAP; initially reads all declaration files (in the library they have a877<C>.gd</C> suffix) and afterwards reads all implementation files878(which have a <C>.gi</C> suffix).879<P/>880Something similar is possible for &GAP; packages:881if a file <F>read.g</F> exists in the home directory of the package,882this file is read only <E>after</E> all the <F>init.g</F> files of all883(implicitly) required &GAP; packages are read.884Thus one can separate declaration and implementation for a &GAP; package885in the same way as is done for the &GAP; library,886by creating a file <F>read.g</F>,887restricting the <Ref Func="ReadPackage" BookName="ref"/> statements in888<F>init.g</F> to only read those files of the package that provide889declarations,890and to read the implementation files from <F>read.g</F>.891<P/>892<E>Examples:</E>893<P/>894Suppose that there are two packages <C>A</C> and <C>B</C>,895each with files <F>init.g</F> and <F>read.g</F>.896<P/>897<List>898<Item>899If package <C>A</C> suggests or needs package <C>B</C>900and package <C>B</C> does not need or suggest any other package901then first <F>init.g</F> of <C>B</C> is read,902then <F>read.g</F> of <C>B</C>,903then <F>init.g</F> of <C>A</C>,904then <F>read.g</F> of <C>A</C>.905</Item>906<Item>907If package <C>A</C> suggests or needs package <C>B</C>908and package <C>B</C> (or a package that is suggested or needed by <C>B</C>)909suggests or needs package <C>A</C>910then first the files <F>init.g</F> of <C>A</C> and <C>B</C> are read911(in an unspecified order)912and then the files <F>read.g</F> of <C>A</C> and <C>B</C>913(in the same order).914</Item>915</List>916<P/>917918In general, when &GAP; is asked to load a package then first the dependencies919between this packages and its needed and suggested packages are inspected920(recursively), and a list of package sets is computed such that no cyclic921dependencies occur between different package sets and such that no package922in any of the package sets needs any package in later package sets.923Then &GAP; runs through the package sets and reads for each set first all924<F>init.g</F> files and then all <F>read.g</F> files of the packages in the925set.926(There is one exception from this rule:927Whenever packages are autoloaded before the implementation part of the &GAP;928library is read, only the <F>init.g</F> files of the packages are read;929as soon as the &GAP; library has been read, the <F>read.g</F> files of these930packages are also read, and afterwards the above rule holds.)931<P/>932933<Index Key="IsPackageMarkedForLoading"><C>IsPackageMarkedForLoading</C></Index>934It can happen that some code of a package depends on the availability of935suggested packages, i.e., different initializations are performed936depending on whether a suggested package will eventually be loaded or not.937One can test this condition with the function938<Ref Func="IsPackageMarkedForLoading" BookName="ref"/>.939In particular, one should <E>not</E> call940(and use the value returned by this call) the function941<Ref Func="LoadPackage" BookName="ref"/> inside942package code that is read during package loading.943Note that for debugging purposes loading suggested packages may944have been deliberately disabled via the global option <C>OnlyNeeded</C>.945<P/>946947Note that the separation of the &GAP; code of packages into declaration948part and implementation part does in general <E>not</E> allow one to actually949<E>call</E> functions from a package when the implementation part is read.950For example,951in the case of a <Q>cyclic dependency</Q> as in the second example above,952suppose that <C>B</C> provides a new function <C>f</C> or a new global record953<C>r</C>, say, which are declared in the declaration part of <C>B</C>.954Then the code in the implementation part of <C>A</C> may contain955calls to the functions defined in the declaration part of <C>B</C>.956However, the implementation part of <C>A</C> may be read957<E>before</E> the implementation part of <C>B</C>.958So one can in general not assume that during the loading of <C>A</C>,959the function <C>f</C> can be called, or that one can access components of960the record <C>r</C>.961<P/>962963If one wants to call the function <C>f</C> or to access components of the964record <C>r</C> in the code of the package <C>A</C> then the problem is965that it may be not possible to determine a cyclic dependency between <C>A</C>966and <C>B</C> from the packages <C>A</C> and <C>B</C> alone.967A safe solution is then to add the name of <C>B</C> to the component968<C>Dependencies.OtherPackagesLoadedInAdvance</C> of the <F>PackageInfo.g</F>969file of <C>A</C>.970The effect is that package <C>B</C> is completely loaded before the file971<F>read.g</F> of <C>A</C> is read, provided that there is no cyclic972dependency between <C>A</C> and <C>B</C>,973and that package <C>A</C> is regarded as not available in the case that974such a cyclic dependency between <C>A</C> and <C>B</C> exists.975<P/>976977A special case where <C>Dependencies.OtherPackagesLoadedInAdvance</C>978can be useful is that a package wants to force the complete &GAP; library979to be read before the file <F>read.g</F> of the package <C>A</C> is read.980In this situation, the <Q>package name</Q> <C>"gap"</C> should be added981to this component in the <F>PackageInfo.g</F> file of <C>A</C>.982<P/>983984<Index>autoreadable variables</Index>985In the case of cyclic dependencies, one solution for the above problem986might be to delay those computations (typically initializations)987in package <C>A</C> that require package <C>B</C> to be loaded988until all required packages are completely loaded.989This can be done by moving the declaration and implementation of the990variables that are created in the initialization into a separate file991and to declare these variables in the <F>init.g</F> file of the package,992via a call to <Ref Func="DeclareAutoreadableVariables" BookName="ref"/>993(see also <Ref Sect="Autoreadable Variables"/>).994<P/>995996</Section>997998999<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1000<Section Label="Autoreadable Variables">1001<Heading>Autoreadable Variables</Heading>10021003Package files containing method installations must be read1004when the package is loaded.1005For package files <E>not</E> containing method installations1006(this applies, for example, to many data files)1007another mechanism allows one to delay reading such files1008until the data are actually accessed. See1009<Ref Label="DeclareAutoreadableVariables" BookName="ref"/> for further1010details.10111012</Section>1013101410151016<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1017<Section Label="Standalone Programs in a GAP Package">1018<Heading>Standalone Programs in a &GAP; Package</Heading>10191020&GAP; packages that involve stand-alone programs are fundamentally1021different from &GAP; packages that consist entirely of &GAP; code.1022<P/>1023This difference is threefold: A user who installs the &GAP; package1024must also compile (or install) the package's binaries, the1025package must check whether the binaries are indeed available,1026and finally the &GAP; code of the package has to start the external1027binary and to communicate with it.1028We will cover these three points in the following sections.1029<P/>1030If the package does not solely consist of an interface to an external1031binary and if the external program called is not just special-purpose1032code, but a generally available program, chances are high that sooner1033or later other &GAP; packages might also require this program.1034We therefore strongly recommend the provision of a documented &GAP;1035function that will call the external binary. We also suggest to create1036actually two &GAP; packages; the first providing only the binary and the1037interface and the second (requiring the first,1038see <Ref Label="Package dependencies"/>) being the actual &GAP; package.1039<P/>104010411042<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1043<Subsection Label="Installation of GAP Package Binaries">1044<Heading>Installation of &GAP; Package Binaries</Heading>10451046<Index Key="sysinfo.gap"><C>sysinfo.gap</C></Index>1047<Index Subkey="for a GAP package">external binaries</Index>1048The scheme for the installation of package binaries which is described1049further on is intended to permit the installation on different1050architectures which share a common file system (and share the1051architecture independent file).1052<P/>1053A &GAP; package which includes external binaries contains a <F>bin</F>1054subdirectory. This subdirectory in turn contains subdirectories for1055the different architectures on which the &GAP; package binaries are1056installed. The names of these directories must be the same as the1057names of the architecture dependent subdirectories of the main <F>bin</F>1058directory. Unless you use a tool like <C>autoconf</C> yourself, you must1059obtain the correct name of the binary directory from the main &GAP;1060branch. To help with this, the main &GAP; directory contains a file1061<F>sysinfo.gap</F> which assigns the shell variable <C>GAParch</C> to the1062proper name as determined by &GAP;'s <C>configure</C> process.1063For example on a Linux system, the file <F>sysinfo.gap</F> may look like1064this:1065<P/>1066<Log><![CDATA[1067GAParch=i586-unknown-linux2.0.31-gcc1068]]></Log>1069<P/>1070We suggest that your &GAP; package contains a file <F>configure</F> which1071is called with the path of the &GAP; root directory as1072parameter. This file then will read <F>sysinfo.gap</F> and set up1073everything for compiling under the given architecture (for example1074creating a <F>Makefile</F> from <F>Makefile.in</F>). As initial templates,1075you may use installation scripts of the <Package>Example</Package> package.10761077</Subsection>107810791080<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1081<Subsection Label="Test for the Existence of GAP Package Binaries">1082<Heading>Test for the Existence of GAP Package Binaries</Heading>10831084If an external binary is essential for the workings of a &GAP; package,1085the function stored in the component <C>AvailabilityTest</C> of the1086<F>PackageInfo.g</F> file of the package should test whether the program1087has been compiled on the architecture (and inhibit package loading1088if this is not the case).1089This is especially important if the package is loaded automatically.1090<P/>1091The easiest way to accomplish this is to use1092<Ref Func="Filename" Label="for a directory and a string" BookName="ref"/>1093for checking for the actual binaries in the path given by1094<Ref Func="DirectoriesPackagePrograms" BookName="ref"/>1095for the respective package.1096For example the <Package>example</Package> &GAP; package could use the1097following function to test whether the binary <F>hello</F> has been compiled;1098it will issue a warning if not, and will only load the package if the binary1099is indeed available:1100<P/>1101<Log><![CDATA[1102...1103AvailabilityTest := function()1104local path,file;1105# test for existence of the compiled binary1106path:= DirectoriesPackagePrograms( "example" );1107file:= Filename( path, "hello" );1108if file = fail then1109LogPackageLoadingMessage( PACKAGE_WARNING,1110[ "The program `hello' is not compiled,",1111"`HelloWorld()' is thus unavailable.",1112"See the installation instructions;",1113"type: ?Installing the Example package" ] );1114fi;1115return file <> fail;1116end,1117...1118]]></Log>1119<P/>1120However, if you look at the actual <F>PackageInfo.g</F> file of the1121<Package>example</Package> package, you will see that its1122<C>AvailabilityTest</C> function always returns <K>true</K>,1123and just logs the warning if the binary is not available1124(which may be later viewed with1125<Ref Func="DisplayPackageLoadingLog" BookName="ref"/>).1126This means that the binary is not regarded as essential for this1127package.1128<P/>1129You might also have to cope with the situation that external binaries will1130only run under UNIX (and not, say, under Windows), or may not compile with1131some compilers or default compiler options.1132See <Ref Sect="Testing for the System Architecture" BookName="ref"/>1133for information on how to test for the architecture.1134<P/>1135<Index Key="LogPackageLoadingMessage"><C>LogPackageLoadingMessage</C></Index>1136Last but not least: do not print anything in the <C>AvailabilityTest</C>1137function of the package via <C>Print</C> or <C>Info</C>. Instead one should1138call <Ref Func="LogPackageLoadingMessage" BookName="ref"/> to store1139a message which may be viewed later with1140<Ref Func="DisplayPackageLoadingLog" BookName="ref"/>1141(the latter two functions are introduced in &GAP; 4.5)1142</Subsection>1143114411451146<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1147<Subsection Label="Calling of and Communication with External Binaries">1148<Heading>Calling of and Communication with External Binaries</Heading>11491150There are two reasons for this: the input data has to be passed on to1151the stand-alone program and the stand-alone program has to be started1152from within &GAP;.1153<P/>1154There are two principal ways of doing this.1155<P/>1156The first possibility is to write all the data for the stand-alone to1157one or several files, then start the stand-alone with1158<Ref Oper="Process" BookName="ref"/> or1159<Ref Func="Exec" BookName="ref"/>1160which then writes the output data to file, and finally read in1161the standalone's output file.1162<P/>1163The second way is interfacing via input-output streams,1164see Section <Ref Sect="Input-Output Streams" BookName="ref"/>.1165<P/>1166Some &GAP; packages use kernel modules1167(see <Ref Sect="Kernel modules in GAP packages" BookName="ref"/>)1168instead of external binaries.1169A kernel module is implemented in C and follows certain conventions to1170comply with the &GAP; kernel interface, which we plan to document later.1171In the meantime, we advise you to look at existing examples of such packages1172and get in touch with &GAP; developers if you plan to develop such a package.11731174</Subsection>11751176</Section>1177117811791180<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1181<Section Label="Having an InfoClass">1182<Heading>Having an InfoClass</Heading>11831184<!-- TODO: (CW) the Example package does not declare an InfoExample,1185and it ought to do so! It might be a good idea to suggest1186_where_ to put this declaration.-->11871188<Index Key="InfoClass" Subkey="for a GAP package"><C>InfoClass</C></Index>1189It is a good idea to declare an <C>InfoClass</C> for your package. This gives1190the package user the opportunity to control the verbosity of output1191and/or the possibility of receiving debugging information1192(see <Ref Sect="Info functions" BookName="ref"/>). Below, we give a quick1193overview of its utility.1194<P/>1195An <C>InfoClass</C> is defined with a <C>DeclareInfoClass( <A>InfoPkgname</A> );</C>1196statement and may be set to have an initial <C>InfoLevel</C> other than the1197zero default (which means no <C>Info</C> statement is to output information)1198via a <C>SetInfoLevel( <A>InfoPkgname</A>, <A>level</A> );</C> statement. An initial1199<C>InfoLevel</C> of 1 is typical.1200<P/>1201<C>Info</C> statements have the form:1202<C>Info( <A>InfoPkgname</A>, <A>level</A>, <A>expr1</A>, <A>expr2</A>, ...);</C>1203where the expression list <C><A>expr1</A>, <A>expr2</A>, ...</C>1204appears just like it would in a <C>Print</C> statement. The only difference is1205that the expression list is only printed (or even executed) if the1206<C>InfoLevel</C> of <A>InfoPkgname</A> is at least <A>level</A>.12071208</Section>1209121012111212<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1213<Section Label="The Banner">1214<Heading>The Banner</Heading>12151216<Index Subkey="for a GAP package">banner</Index>1217Since &GAP; 4.4, the package banner, if one is desired, should be1218provided by assigning a string to the <C>BannerString</C> field of the record1219argument of <C>SetPackageInfo</C> in the <F>PackageInfo.g</F> file.1220<P/>1221It is a good idea to have a hook into your package documentation from1222your banner. The banner of the &Example; package suggests to the &GAP; user:1223<P/>1224<Log><![CDATA[1225For help, type: ?Example package1226]]></Log>1227<P/>1228In order for this to display the introduction of the &Example; package1229the index-entry1230<C>&tlt;Index&tgt;Example package&tlt;/Index&tgt;</C>1231was added just before the first paragraph of the introductory section in1232the file <F>example.xml</F>. The &Example; package uses1233<Package>GAPDoc</Package>1234(see Section <Ref Sect="Writing Documentation and Tools Needed"/>)1235for documentation1236(you will need some different scheme to achieve this using1237the <F>gapmacro.tex</F> system).12381239</Section>124012411242<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1243<Section Label="Version Numbers">1244<Heading>Version Numbers</Heading>12451246<Index Subkey="for a GAP package">version number</Index>1247Version numbers are strings containing nonnegative integers separated1248by non-numeric characters. They are compared by1249<Ref Func="CompareVersionNumbers" BookName="ref"/>1250which first splits them at non-digit characters and then lexicographically1251compares the resulting integer lists.1252Thus version <C>"2-3"</C> is larger than version <C>"2-2-5"</C>1253but smaller than <C>"4r2p3"</C> or <C>"11.0"</C>.1254<P/>1255It is possible for code to require &GAP; packages in certain1256versions. In this case, all versions, whose number is equal or larger1257than the requested number are acceptable. It is the task of the1258package author to provide upwards compatibility.1259<P/>1260Loading a specific version of a package (that is, <E>not</E> one with a1261larger version number) can be achieved by prepending <C>=</C> to the desired1262version number.1263For example, <C>LoadPackage( "example", "=1.0" )</C> will load version1264<C>"1.0"</C> of the package <C>"example"</C>,1265even if version <C>"1.1"</C> is available.1266As a consequence, version numbers must not start with <C>=</C>,1267so <C>"=1.0"</C> is not a valid version number.1268<P/>1269Package authors should choose a version numbering scheme that admits a1270new version number even after tiny changes to the package, and1271ensure that version numbers of successive package versions increase.1272The automatic update of package archives in the &GAP; distribution will1273only work if a package has a new version number.1274<P/>1275It is a well-established custom to name package archives like1276<F>name-version.tar.gz</F>, <F>name-version.tar.bz2</F> etc.,1277where <C>name</C> is the lower case name, and <C>version</C> is1278the version (another custom is that the archive then should extract1279to a directory that has exactly the name <F>name-version</F>).1280<P/>1281It is very important that there should not ever be, for a given &GAP;1282package, two different archives with the same package version number.1283If you make changes to your package and place a new archive of the1284package onto the public server, please ensure that a new archive has1285a new version number. This should be done even for very minor changes.1286<P/>1287For most of the packages it will be inappropriate to re-use the date1288of the release as a version number. It's much more obvious how big are1289the changes between versions "4.4.12", "4.5.1" and "4.5.2" than between1290versions "2008.12.17", "2011.04.15" and "2011.09.14".1291<P/>1292Since version information is duplicated in several places throughout the1293package documentation, for &GAPDoc;-based manuals you may define the1294version and the release manual in the comments in <F>PackageInfo.g</F>1295file close to the place where you specified its <C>Version</C> and1296<C>Date</C> components, for example1297<Log><![CDATA[1298## <#GAPDoc Label="PKGVERSIONDATA">1299## <!ENTITY VERSION "3.3">1300## <!ENTITY RELEASEDATE "11/11/2011">1301## <#/GAPDoc>1302]]></Log>1303notify <Ref Func="MakeGAPDocDoc" BookName="gapdoc"/> that a part of the1304document is stored in <F>PackageInfo.g</F> (see <F>example/makedocrel.g</F>),1305read this data into the header of the main document via1306<C><#Include Label="PKGVERSIONDATA"></C> directive and then use them via1307&VERSION; and &RELEASEDATE; entities almost everywhere where you1308need to refer to them (most commonly, in the title page and installation1309instructions).13101311</Section>131213131314<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1315<Section Label="Testing a GAP package">1316<Heading>Testing a &GAP; package</Heading>13171318<Subsection Label="Tests files for a GAP package">1319<Heading>Tests files for a GAP package</Heading>13201321The (optional) <F>tst</F> directory of your package may contain as1322many tests of the package functionality as appears appropriate. These tests1323should be organised into test files similarly to those in the <F>tst</F>1324directory of the &GAP; distribution as documented in1325<Ref Sect="Test Files" BookName="ref"/>.1326<P/>1327For a deposited package, a test file with a basic test of the package1328(for example, to check that it works as expected and/or that the manual1329examples are correct) may be specified in the component <C>TestFile</C>1330in the <F>PackageInfo.g</F> to be included in the GAP standard test suite.1331This file can either consist of <Ref BookName="ref" Oper="Test"/>1332calls (in this case, it is common to call it <F>testall.g</F>) or be1333itself a test file having an extension <F>.tst</F> and supposed to be1334read via <Ref BookName="ref" Oper="Test"/>. It is assumed that the1335latter case occurs if and only if the file contains the substring<P/>1336 <C>"gap> START_TEST("</C>1337<P/>1338<Alt Only="LaTeX">\noindent</Alt>1339(with exactly one space after the &GAP; prompt).1340<P/>1341For deposited packages, these tests are run by the &GAP; Group regularly,1342as a part of the standard &GAP; test suite. For the efficient testing it1343is important that the test specified in the <F>PackageInfo.g</F> file1344does not display any output (e.g. no test progress indicators) except1345reporting discrepancies if such occur and the completion report as1346in the example below:1347<Log><![CDATA[1348gap> Test("tst/testall.tst");1349Example package: testall.tst1350GAP4stones: 33331351true1352]]></Log>1353Tests which produce extended output and/or requires substantial runtime1354are not supposed to be a part of the &GAP; standard test suite but may1355be placed in the <F>tst</F> directory of the packages with further1356instructions on how to run them elsewhere.13571358</Subsection>135913601361<Subsection Label="Testing GAP package loading">1362<Heading>Testing &GAP; package loading</Heading>13631364To test that your package may be loaded into &GAP; without any problems1365and conflicts with other packages, test that it may be loaded in various1366configurations:1367<List>1368<Item>1369starting &GAP; with no packages (except needed for &GAP;) using <C>-r -A</C> options1370and calling <C>LoadPackage("your-package-name");</C>1371</Item>1372<Item>1373starting &GAP; with no packages (except needed for &GAP;) using <C>-r -A</C> options1374and calling <C>LoadPackage("your-package-name" : OnlyNeeded );</C>1375</Item>1376<Item>1377starting &GAP; in the default configuration (with no options)1378and calling <C>LoadPackage("your-package-name");</C>1379</Item>1380<Item>1381starting &GAP; in the default configuration (with no options)1382and calling <C>LoadPackage("your-package-name" : OnlyNeeded );</C>1383</Item>1384<Item>1385finally, together with all other packages using1386<Ref Func="LoadAllPackages"/> (see below) in four possible combinations1387of starting &GAP; with/without <C>-r -A</C> options and calling1388<Ref Func="LoadAllPackages"/> with/without <C>Reversed</C> option.1389</Item>1390</List>1391The test of loading all packages is the most subtle one. Quite often1392it reveals problems which do not occur in the default configuration1393but may cause difficulties to the users of specialised packages.1394<P/>1395For your convenience, <C>make testpackagesload</C> called in the &GAP;1396root directory will run all package loading tests listed in this subsection1397and write their output in its <C>dev/log</C> directory.1398<P/>1399It will produce four files with test logs, corresponding to the1400four cases above (the letter <C>N</C> in the filename stands for1401<Q>needed</Q>, <C>A</C> stands for <Q>autoloaded</Q>):1402<List>1403<Item>1404<F>dev/log/testpackagesload1_...</F>1405</Item>1406<Item>1407<F>dev/log/testpackagesloadN1_...</F>1408</Item>1409<Item>1410<F>dev/log/testpackagesloadA_...</F>1411</Item>1412<Item>1413<F>dev/log/testpackagesloadNA_...</F>1414</Item>1415</List>1416Each file contains small sections for loading individual packages: among those,1417you need to find the section related to your package and may ignore all other1418sections. For example, the section for the &Example; package looks like1419<Log><![CDATA[1420%%% Loading example 3.3.31421[ ]1422### Loaded example 3.3.31423]]></Log>1424so it has clearly passed the test. If there are any error messages displayed1425between <C>Loading ...</C> and <C>Loaded ...</C> lines, they will signal on1426errors during loading of your package.1427<P/>1428Additionally, this test collects information about variables created since1429the library was read (obtained using <Ref Func="NamesUserGVars" BookName="ref"/>)1430with either short names (no more than three characters) or names breaking a1431recommended naming convention that the &GAP; core system and &GAP; packages1432should not use global variables starting in the lowercase1433(see Section <Ref Sect="Functions and Variables and Choices of Their Names"/>).1434Their list will be displayed in the test log (in the example above, &Example;1435packages does not create any such variables, so an empty list is displayed).1436It may be hard to attribute a particular identifier to a package, since it1437may be created by another package loaded because of dependencies, so when1438a more detailed and precise report on package variables is needed, it may1439be obtained using <Ref Func="ShowPackageVariables" BookName="ref"/>1440(also, <C>make testpackagesvars</C> called in the &GAP; root directory1441produces such reports for each package and writes them to a file1442<F>dev/log/testpackagesvars_...</F>).1443<P/>1444Finally, each log file finishes with two large sections for loading all1445packages in the alphabetical and reverse aplhabetical order (to check more1446combinations of loading one package after another). We are aiming at1447releasing only collections of package which do not break1448<Ref Func="LoadAllPackages"/> in any of the four configurations, so if1449it is broken when you plug in the development version of your package into1450the released version of &GAP;, it is likely that your package triggers1451this error. If you observe that <Ref Func="LoadAllPackages"/> is broken1452and suspect that this is not the fault of your package, please contact1453the &GAP; Support.1454</Subsection>14551456<ManSection>1457<Func Name="LoadAllPackages" Arg=": Reversed"/>1458<Description>1459loads all &GAP; packages from their list sorted in alphabetical order1460(needed and suggested packages will be loaded when required). This is a1461technical function to check packages compatibility, so it should NOT be1462used to run anything except tests; it is known that &GAP; performance is1463slower if all packages are loaded. To introduce some variations of the1464order in which packages will be loaded for testing purposes,1465<Ref Func="LoadAllPackages"/> accepts version <C>Reversed</C> to load1466packages from their list sorted in the reverse alphabetical order.1467</Description>1468</ManSection>146914701471<Subsection Label="Testing a GAP package with the GAP standard test suite">1472<Heading>Testing a &GAP; package with the &GAP; standard test suite</Heading>14731474The <F>tst</F> directory of the &GAP; installation contains a selection of1475test files and two scripts, <F>testinstall.g</F> and <F>testall.g</F>1476which are a part of the &GAP; standard test suite.1477<P/>1478It is important to check that your package does not break &GAP; standard1479tests. To perform a clean test and avoid interfering with other packages,1480first you must start a new &GAP; session with the following command1481(assuming that <C>gap</C> starts &GAP; in your system):1482<Log><![CDATA[1483gap -N -A -x 80 -r -m 100m -o 512m1484]]></Log>1485After that load your package and run either <F>testinstall.g</F> or1486<F>testall.g</F> as demonstrated below.1487<P/>14881489The quicker test, <F>testinstall.g</F>, requires about 512MB of memory and1490runs for about one minute on an Intel Core 2 Duo / 2.53 GHz machine. It may1491be started with the command1492<Log><![CDATA[1493gap> Read( Filename( DirectoriesLibrary( "tst" ), "testinstall.g" ) );1494]]></Log>1495You will get a large number of lines with output about the progress of1496the tests.1497<Log><![CDATA[1498test file GAP4stones time(msec)1499-------------------------------------------1500testing: .../gap4r5/tst/zlattice.tst1501zlattice.tst 0 01502testing: .../gap4r5/tst/gaussian.tst1503gaussian.tst 0 101504... further lines deleted ...1505]]></Log>1506<P/>15071508The more thorough test is <F>testall.g</F> which exercises more of &GAP;'s1509capabilities, containing all test files from <F>testinstall.g</F> as1510a subset. It requires about 512MB of memory, runs for about one hour1511on an Intel Core 2 Duo / 2.53 GHz machine, and produces an output1512similar to the testinstall.g test.1513To run it, also start a new &GAP; session with1514<C>gap -N -A -x 80 -r -m 100m -o 512m</C> and then call1515<Log><![CDATA[1516gap> Read( Filename( DirectoriesLibrary( "tst" ), "testall.g" ) );1517]]></Log>1518You may repeat the same check loading your package with <C>OnlyNeeded</C>1519option. Remember to perform each subsequent test in a new &GAP; session.1520<P/>1521Also you may perform individual tests from the <F>tst</F> directory of the1522&GAP; installation loading them with <Ref Func="Test" BookName="ref"/>,1523for example, the file <F>bugfix.tst</F>.1524<P/>152515261527</Subsection>15281529</Section>153015311532<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1533<Section Label="Access to the GAP Development Version">1534<Heading>Access to the &GAP; Development Version</Heading>15351536We are aiming at providing a stable platform for package development and1537testing with official &GAP; releases. However, when it may be of benefit to1538obtain access to the &GAP; development version, please contact the &GAP;1539team by mailing to <Email>[email protected]</Email>.1540<P/>1541</Section>154215431544<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1545<Section Label="Selecting a license for a GAP Package">1546<Heading>Selecting a license for a &GAP; Package</Heading>15471548It is advised to make clear in the documentation of the package the basis1549on which it is being distributed to users. GAP itself is distributed under1550the GNU Public License version 2 (version 2 or later). We would encourage1551you to consider the GPL for your packages, but you might wish to be more1552restrictive (for instance forbidding redistribution for profit) or less1553restrictive (allowing your software to be incorporated into commercial1554software). See <Q>Choosing a License for the Distribution of Your Package</Q>1555from <URL>http://www.gap-system.org/Packages/Authors/authors.html</URL>1556for further details.1557<P/>15581559In the past many &GAP; packages used the text1560<Q>We adopt the copyright regulations of GAP as detailed in the copyright1561notice in the &GAP; manual</Q> or a similar statement. We now advise to be1562more explicit and make the exact reference to the GPL license, for example:1563<P/>1564<E>1565<Package>package-name</Package> is free software; you can redistribute it1566and/or modify it under the terms of the1567<URL Text="GNU General Public License">http://www.fsf.org/licenses/gpl.html</URL>1568as published by the Free Software Foundation; either version 2 of the License,1569or (at your option) any later version.1570</E>15711572</Section>15731574<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1575<Section Label="Wrapping up a GAP Package">1576<Heading>Wrapping up a &GAP; Package</Heading>15771578<!-- TODO: also accept .zip archives -->15791580Currently, the &GAP; distribution provides archives in four different1581formats.1582<P/>1583<List>1584<Mark><F>.tar.gz</F></Mark>1585<Item>1586a standard UNIX <C>tar</C> archive, compressed with <C>gzip</C>1587</Item>1588<Mark><F>.tar.bz2</F></Mark>1589<Item>1590a standard UNIX <C>tar</C> archive, compressed with <C>bzip2</C>1591</Item>1592<Mark><F>.zip</F></Mark>1593<Item>1594an archive in <C>zip</C> format, where text files should have1595UNIX style line breaks1596</Item>1597<Mark><F>-win.zip</F></Mark>1598<Item>1599an archive in <C>zip</C> format, where text files should have1600DOS/Windows style line breaks1601</Item>1602</List>1603<P/>1604For convenience of possible users it is sensible that you provide an1605archive of your package in at least one of these formats.1606<P/>1607For example, if you wish to supply a <F>.tar.gz</F> archive,1608you may create it with the command1609<P/>1610 <C>tar -cvzf package-name-version.tar.gz package-name</C>1611<P/>1612<Alt Only="LaTeX">\noindent</Alt>1613The <F>etc</F> directory obtained from <C>tools.tar.gz</C>1614(described above in1615Section <Ref Sect="Writing Documentation and Tools Needed"/>)1616contains a file <F>packpack</F> which provides a more versatile1617packing-up script.1618<P/>1619Because the release of the &GAP; package is independent of the version1620of &GAP;, a &GAP; package should be wrapped up in separate file that1621can be installed onto any version of &GAP;. In this way, a package can1622be upgraded any time without the need to wait for new &GAP; releases.1623To ensure this, the package should be archived from the &GAP; <F>pkg</F>1624directory, that is all files are archived with the path starting at the1625package's name.1626<P/>1627<Index Key="GAPDocManualLab"><C>GAPDocManualLab</C></Index>1628The archive of a &GAP; package should contain all files necessary for the1629package to work. In particular there should be a compiled documentation,1630which includes the <F>manual.six</F>, <F>manual.toc</F> and <F>manual.lab</F>1631file in the1632documentation subdirectory which are created by &TeX;ing the documentation,1633if you use &GAPDoc; or the <F>gapmacro.tex</F> document formats.1634(The first two files are needed by the &GAP; help system,1635and the <F>manual.lab</F> file is needed if the main manuals or another1636package is referring to your package.1637Use the command <C>GAPDocManualLab( packagename );</C> to create this file1638for your help books if you use &GAPDoc;.)1639<P/>16401641For packages which are redistributed via the &GAP; Web site,1642we offer an automatic conversion of any of the formats listed1643above to all the others (note that this, as well as wrapping1644the &GAP; distribution as a single archive containing the1645core system and all currently redistributed packages, will1646change file timestamps, so one should not rely on them anywhere1647in the package).1648<P/>16491650To use the conversion and repackaging service, you can provide any of1651the four archive formats or even more than one, however you should1652adhere to the following rule: text files in <File>.tar.gz</File>1653and <File>.tar.bz2</File> archives must have UNIX style line breaks,1654while text files in <File>-win.zip</File> archives must have1655DOS/Windows line breaks.1656<P/>16571658The package wrapping tools for the &GAP; distribution and web pages1659then will use a sensible list of file extensions to decide if a file1660is a text file (being conservative, it may miss a few text files).1661These rules may be prepended by the application of rules from the1662<F>PackageInfo.g</F> file:1663<List>1664<Item>1665if it has a <C>.TextFiles</C> component, then consider the given files1666as text files before &GAP; defaults will be applied;1667</Item>1668<Item>1669if it has a <C>.BinaryFiles</C> component, then consider given files1670as binary files before &GAP; defaults will be applied;1671</Item>1672<Item>1673if it has a <C>.TextBinaryFilesPatterns</C> component, then apply it1674before &GAP; defaults will be applied;1675</Item>1676</List>1677<P/>16781679The <F>etc</F> directory obtained from <C>tools.tar.gz</C>1680(described above in1681Section <Ref Sect="Writing Documentation and Tools Needed"/>)1682contains a file <F>classifyfiles.py</F> and two files <F>patternscolor.txt</F>1683and <F>patternstextbinary.txt</F> implementing &GAP; default rules used1684to classify files in packages.1685For most of the packages these default rules perfecty detect binary and1686text files, so there is no need for them to use any of the three optional1687components. However, <C>.TextBinaryFilesPatterns</C>, or <C>.TextFiles</C>,1688or <C>.BinaryFiles</C> will become useful if the package has e.g. data1689files which are recognised as binary files by the default rules, or if the1690package uses standard extensions in a non-standard way (this is not1691recommended, of course). If things will go wrong, it is possible that one1692(or indeed all) created archives have wrong line breaks.1693<P/>16941695Utility functions available in <File>gap4r7/lib/lbutil.g</File>, namely1696<C>DosUnixLinebreaks</C>, <C>UnixDosLinebreaks</C>, <C>MacUnixLinebreaks</C>1697may be helpful. They are described in the comments to their source code.16981699</Section>170017011702<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1703<Section Label="The WWW Homepage of a Package">1704<Heading>The WWW Homepage of a Package</Heading>17051706If you want to distribute your package1707you should create a WWW homepage containing1708some basic information,1709archives for download,1710the <F>README</F> file with installation instructions,1711and a copy of the package's <F>PackageInfo.g</F> file.1712<P/>1713The responsibility for this WWW homepage is with the package1714authors/maintainers.1715<P/>1716If you tell us about your package1717(say, by mail to <Email>[email protected]</Email>)1718we may consider either1719<List>1720<Item>1721adding a link to your package homepage from the &GAP; website1722(thus, the package will be an <E>undeposited contribution</E>);1723</Item>1724<Item>1725or redistributing the current version of your package as a part of1726the &GAP; distribution (this, the package will be <E>deposited</E>),1727also ;1728</Item>1729</List>1730In the latter case we can also provide some services for producing several1731archive formats from the archive you provide (e.g., you produce a1732<C>.tar.gz</C> version of your archive and we produce also a <C>.tar.bz2</C>1733and a <C>-win.zip</C> version from it).1734<P/>1735Please also consider submitting your package to the &GAP; package refereeing1736process (see <URL>http://www.gap-system.org/Contacts/submit.html</URL> for1737further information).1738</Section>173917401741<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1742<Section Label="Upgrading the package to work with GAP 4.5">1743<Heading>Upgrading the package to work with &GAP; 4.5</Heading>17441745<Subsection Label="Changes in GAP 4.5 from the packages perspective">1746<Heading>Changes in &GAP; 4.5 from the packages perspective</Heading>17471748Here we list only those changes which may have some implications for the1749packages.17501751<List>17521753<Item>1754Changing the distribution format providing one archive with the core system1755and all currently redistributed packages.1756</Item>17571758<Item>1759The &GAP; kernel is now compiled by default to use the GMP large integer1760arithmetic library, speeding up arithmetic by a factor of 4 or more in many cases.1761This slightly changes the build process, affecting mainly packages with1762dynamically loaded modules (see <URL>http://www.gap-system.org/Download/</URL>1763for &GAP; installation instructions).1764</Item>17651766<Item>1767The &GAP; documentation has been converted to the &GAPDoc; format and extensively1768reviewed. Now it has only two books: the Tutorial and the Reference Manual.1769The two other books, <Q>Extending &GAP;</Q> and <Q>Programming Tutorial</Q> became1770parts of the Reference Manual. Packages that refer to parts of the &GAP; documentation1771may need to rebuild their manuals to update references.1772<P/>1773Some packages still use the1774old <Q>gapmacro</Q> format for their manuals, for which support may be discontinued1775in the future. There is no urgent need to convert such manuals into the &GAPDoc;1776format before &GAP; 4.5 release, but we encourage you very much to consider1777doing this at some later point.1778</Item>17791780<Item>1781The old concept of an autoloaded package has been integrated with the <E>needed</E>1782and <E>suggested</E> mechanism that already exists between packages. &GAP; itself1783now <Q>needs</Q> certain packages (for instance &GAPDoc;) and <Q>suggests</Q> others1784(typically the packages that were autoloaded). The decisions1785which packages &GAP; should need or suggest are made by developers based on1786technical criteria. They can be easily overridden by a user1787using the new <File>gap.ini</File>1788(see <Ref Sect="The gap.ini and gaprc files" BookName="ref"/>).1789The default file ensures that all previously autoloaded packages are1790still loaded if present.1791</Item>17921793<Item>1794Optional <File>~/.gap</File> directory for user's customisations which may contain e.g.1795locally installed packages (see <Ref BookName="ref" Sect="GAP Root Directories"/>).1796If package installation instructions explain how to install the package in a1797non-standard location, they may need an update. This is intended to replace1798<File>.gaprc</File> files, but those are still supported for backwards1799compatibility (see <Ref Sect="The former .gaprc file" BookName="ref"/>).1800</Item>18011802<Item>1803Various improvements in the packages loading mechanism make it more1804informative, while avoiding confusing the user with warning and error1805messages for packages they didn't1806know they were loading. For example, many messages are stored but not1807displayed using the function <Ref Func="LogPackageLoadingMessage" BookName="ref"/>1808and there is a function <Ref BookName="ref" Func="DisplayPackageLoadingLog"/>1809to show log messages that occur during package loading.1810Packages are encouraged to use these mechanisms to report1811problems in loading (e.g. binaries not compiled), rather than printing messages directly.1812</Item>18131814<Item>1815Since &GAP; 4.5 a package may place global variables into a local1816namespace as explained in <Ref Sect="Namespaces for GAP Packages" BookName="ref"/>1817in order to avoid name clashes and preserve compatibility.1818</Item>18191820<Item>1821In &GAP; 4.5 the internal representation of a record has changed,1822as well as some of the basic functions to manipulate records. This speeds1823up considerably the creation of and access to records with many components.1824Record components are now internally stored in the order in which they were used1825first, and this means that the internal ordering of components (returned by1826<Ref Func="RecNames" BookName="ref"/> and so the ordering of records, depends1827on the GAP session.1828<!--1829# in new session1830gap> s:=rec(aa:=1,bb:=0);;1831gap> r:=rec(bb:=1,aa:=0);;1832gap> r<s;1833true1834gap> RecNames(r);1835[ "aa", "bb" ]18361837# in another new session1838gap> r:=rec(bb:=1,aa:=0);;1839gap> s:=rec(aa:=1,bb:=0);;1840gap> r<s;1841false1842gap> RecNames(r);1843[ "bb", "aa" ]1844-->1845Therefore, within each session everything is consistent, so one can1846efficiently remove duplicates with <Ref Oper="Set" BookName="ref"/>,1847sort lists of records, find records with binary search, etc., but a1848care should be taken not to rely on <Ref Func="RecNames" BookName="ref"/>1849always returning names of components in the same order.1850</Item>18511852</List>18531854</Subsection>18551856</Section>185718581859<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->1860<Section Label="Checklists">1861<Heading>Checklists</Heading>18621863<Index>checklists</Index>1864<Subsection Label="Package release checklist">1865<Heading>Package release checklist</Heading>18661867The following checklist may be used by package authors, members of the1868&GAP; team responsible for package updates, package editors and referees.18691870<List>18711872<Item>1873Test that the package:1874<List>1875<Item>1876does not break <File>testinstall.g</File> and <File>testall.g</File>1877and does not slow them down noticeably1878(see <Ref Label="Testing a GAP package with the GAP standard test suite"/>);1879</Item>1880<Item>1881may be loaded in various configurations (see <Ref Label="Testing GAP package loading"/>);1882</Item>1883<Item>1884follows the guidelines of Section1885<Ref Label="Functions and Variables and Choices of Their Names"/>1886about names of functions and variables;1887</Item>1888</List>1889</Item>18901891<Item>1892Package documentation:1893<List>1894<Item>1895is built and included in the package archive together with1896its source files;1897</Item>1898<Item>1899states the version, release date and package authors;1900</Item>1901<Item>1902has the same version, release date and package authors1903details as stated in the <File>PackageInfo.g</File> file;1904</Item>1905<Item>1906is searchable using the &GAP; help system;1907</Item>1908<Item>1909is clear about the license under which the package is distributed;1910</Item>1911</List>1912</Item>19131914<Item>1915<File>PackageInfo.g</File> file:1916<List>1917<Item>1918has the same version, release date and package authors1919details as stated in the package manual;1920</Item>1921<Item>1922has all mandatory components and also optional components where appropriate;1923</Item>1924<Item>1925in particular, contains hints to distinguish binary and text files in1926case of non-standard file names and extensions;1927</Item>1928<Item>1929is validated using <Ref BookName="ref" Func="ValidatePackageInfo"/>;1930</Item>1931</List>1932</Item>19331934<Item>1935Package archive(s):1936<List>1937<Item>1938have correct permisisons for all files and directories after their1939unpacking (755 for directories and executables, if any; 644 for other1940files);1941</Item>1942<Item>1943contain files with correct line breaks for the given format1944(see <Ref Sect="Wrapping up a GAP Package"/>);1945</Item>1946<Item>1947contain no hidden system files and directories that are not supposed1948to be included in the package, e.g. <File>.cvsignore</File>,1949<File>.git</File> etc.;1950</Item>1951</List>1952</Item>19531954<Item>1955Package availability:1956<List>1957<Item>1958not only the package archive(s), but also the1959<File>PackageInfo.g</File> and <File>README</File> files1960are available online;1961</Item>1962<Item>1963the URL of the <File>PackageInfo.g</File> file is validated using1964the online tool available from1965<URL>http://www.gap-system.org/Packages/Authors/authors.html</URL>;1966</Item>1967</List>1968</Item>19691970</List>19711972</Subsection>197319741975<Subsection Label="Checklist for package upgrade to work with GAP 4.5">1976<Heading>Checklist for package upgrade to work with &GAP; 4.5</Heading>19771978The following checklist will help you to check how well your package is1979ready to work with &GAP; 4.5.1980<P/>19811982<List>19831984<Item>1985Mandatory changes needed for package upgrade to work with &GAP; 4.5:19861987<List>19881989<Mark>1990Check that the package works as expected:1991</Mark>1992<Item>1993<List>1994<Item>1995verify that the package functionality works as required, that examples1996in the manual are correct and that test files show no discrepancies;1997</Item>1998<Item>1999if necessary, update manual examples and test files because the order2000in which record components are printed has changed2001(but now it will be more consistent and less dependent on how the record2002was created);2003</Item>2004<Item>2005check the usage of names of record components in the code:2006take care not to rely on <Ref Func="RecNames" BookName="ref"/>2007always returning names of components in the same order2008(see <Ref Label="Upgrading the package to work with GAP 4.5"/>)2009</Item>2010</List>2011</Item>20122013<Mark>2014Revise package dependencies:2015</Mark>2016<Item>2017Check the the <F>PackageInfo.g</F> has the correct list of2018needed and suggested packages (see <Ref Label="Package dependencies"/>).2019</Item>20202021<Mark>2022Revise licensing information:2023</Mark>2024<Item>2025Check that the package states clearly under which conditions it is distributed2026(see <Ref Label="Selecting a license for a GAP Package"/>).2027</Item>20282029<Mark>2030Rebuild the package documentation:2031</Mark>2032<Item>2033whenever your package documentation is &GAPDoc; or <C>gapmacro.tex</C>-based,2034&GAP; 4.5 contains new versions of both tools. This will ensure that2035cross-references from the package manual to the main &GAP; manuals are2036correct and that the &GAP; help system will be able to navigate to the more2037precise location in the package manual. This will also improve the layout of2038the package documentation. In particular, &GAPDoc; has a better2039<File>.css</File> file and is capable of producing the HTML version with2040MathJax support to display nicely mathematical formulae.2041<P/> Note that it's not possible for a package to have an HTML manual which2042contains correct links to both &GAP; 4.4 and &GAP; 4.5 main manuals.2043</Item>20442045</List>20462047</Item>20482049<Item>2050Optional changes recommended for package upgrade to work with &GAP; 4.5:20512052<List>20532054<Item>2055When the <C>AvailabilityTest</C> component in <File>PackageInfo.g</File>2056differs from <Ref Func="ReturnTrue" BookName="ref"/>, use2057<Ref Func="LogPackageLoadingMessage" BookName="ref"/> to store2058a message which may be viewed later with2059<Ref Func="DisplayPackageLoadingLog" BookName="ref"/>2060instead of calling <C>Print</C> or <C>Info</C> directly2061(see <Ref Label="Test for the Existence of GAP Package Binaries"/>).2062</Item>20632064<Item>2065It is recommended not to call <Ref Func="LoadPackage" BookName="ref"/>2066from a package file while this file is read: instead one should list the2067package in question in the lists of needed or suggested packages.2068To verify whether such calls occur in the package first load it and2069then call <C>DisplayPackageLoadingLog( PACKAGE_WARNING );</C>. If there is2070a genuine need to decide whether some package will be available at runtime,2071use the function <Ref Func="IsPackageMarkedForLoading" BookName="ref"/>2072introduced in &GAP; 4.5.2073</Item>20742075<Item>2076Check if the package still relies on some obsolete variables2077(see <Ref Chap="Replaced and Removed Command Names" BookName="ref"/>)2078and try to get rid of their usage.2079</Item>2080</List>2081</Item>2082</List>20832084</Subsection>20852086</Section>20872088</Appendix>20892090<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->2091<!-- %% -->2092<!-- %E -->2093209420952096