CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Views: 418346
1
2
A Guidelines for Writing a GAP Package
3
4
This appendix explains the basics of how to write a GAP package so that it
5
interfaces properly to GAP. For the role of GAP packages and the ways to
6
load them, see Chapter 'Reference: Using GAP Packages'.
7
8
There are two basic aspects of creating a GAP package.
9
10
First, it is a convenient possibility to load additional functionality into
11
GAP including a smooth integration of the package documentation. Second, a
12
package is a way to make your code available to other GAP users.
13
14
Moreover, the GAP Group may provide some help with redistributing your
15
package via the web and ftp site of GAP itself after checking if the package
16
provides some new or improved functionality which looks interesting for
17
other users, if it contains reasonable documentation, and if it seems to
18
work smoothly with the GAP library and other distributed packages. In this
19
case the package can take part in the GAP distribution update mechanism and
20
becomes a deposited package.
21
22
Furthermore, package authors are encouraged to check if the package would be
23
appropriate for the refereeing process and submit it. If the refereeing has
24
been successful, the package becomes an accepted package. Check out the GAP
25
Web site http://www.gap-system.org for more details.
26
27
We start this chapter with a description how the directory structure of a
28
GAP package should be constructed and then add remarks on certain aspects of
29
creating a package, some of these only apply to some packages. Finally, we
30
provide guidelines for the release preparation, wrapping and distribution.
31
32
33
A.1 Structure of a GAP Package
34
35
A GAP package should have an alphanumeric name (package-name, say); mixed
36
case is fine, but there should be no whitespaces. All files of a GAP package
37
package-name must be collected in a single directory package-dir, where
38
package-dir should be just package-name preferably converted to lowercase
39
and optionally followed by the package version (with or without hyphen to
40
separate the version from package-name). Let us call this directory the home
41
directory of the package.
42
43
To use the package with GAP, the directory package-dir must be a
44
subdirectory of a pkg directory in (one of) the GAP root directories (see
45
'Reference: GAP Root Directories'). For example, if GAP is installed in
46
/usr/local/gap4 then the files of the package MyPack may be placed in the
47
directory /usr/local/gap4/pkg/mypack. The directory package-dir preferably
48
should have the following structure (below, a trailing / distinguishes
49
directories from ordinary files):
50
51
 Example 
52
package-dir/
53
 doc/
54
 lib/
55
 src/
56
 tst/
57
 README
58
 CHANGES
59
 configure
60
 Makefile.in
61
 PackageInfo.g
62
 init.g
63
 read.g
64

65
66
There are three file names with a special meaning in the home directory of a
67
package: PackageInfo.g and init.g which must be present, and read.g which is
68
optional. We now describe the above files and directories:
69
70

71
README
72
This should contain how to get it (from the GAP ftp- and web-sites)
73
instructions, as well as installation instructions and names of the
74
package authors and their email addresses. The installation
75
instructions should be repeated in the package's documentation, which
76
should be in the doc directory (see A.2). Authors' names and addresses
77
should be repeated both in the package's documentation and in the
78
PackageInfo.g (see below).
79
80

81
CHANGES
82
For further versions of the package, it will be also useful to have a
83
CHANGES file that records the main changes between versions of the
84
package.
85
86
configure, Makefile.in
87
These files are only necessary if the package has a non-GAP component,
88
e.g. some C code (the files of which should be in the src directory).
89
The configure and Makefile.in files of the Example package provide
90
prototypes. The configure file typically takes a path path to the GAP
91
root directory as argument and uses the value assigned to GAParch in
92
the file sysinfo.gap, created when GAP was compiled to determine the
93
compilation architecture, inserts this in place of the string
94
@GAPARCH@ in Makefile.in and creates a file Makefile. When make is run
95
(which, of course, reads the constructed Makefile), a directory bin
96
(if necessary) and subdirectories of bin with the path equal to the
97
string assigned to GAParch in the file sysinfo.gap should be created;
98
any binaries constructed by compiling the code in src should end up in
99
this subdirectory of bin.
100
101
PackageInfo.g
102
Since GAP 4.4, a GAP package must have a PackageInfo.g file which
103
contains meta-information about the package (package name, version,
104
author(s), relations to other packages, homepage, download archives,
105
banner, ...). This information is used by the package loading
106
mechanism and also for the distribution of a package to other users.
107
The Example package's PackageInfo.g file is well-commented and should
108
be used as a prototype (see also A.5 for further details).
109
110
init.g, read.g
111
A GAP package must have a file init.g. As of GAP 4.4, the typical
112
init.g and read.g files should normally consist entirely of
113
ReadPackage (Reference: ReadPackage) commands (and possibly also Read
114
(Reference: Read) commands) for reading further files of the package.
115
If the declaration and implementation parts of the package are
116
separated (and this is recommended), there should be a read.g file.
117
The declaration part of a package consists of function and variable
118
name declarations and these go in files with .gd extensions; these
119
files are read in via ReadPackage commands in the init.g file. The
120
implementation part of a package consists of the actual definitions of
121
the functions and variables whose names were declared in the
122
declaration part, and these go in files with .gi extensions; these
123
files are read in via ReadPackage commands in the read.g file. The
124
reason for following the above dichotomy is that the read.g file is
125
read after the init.g file, thus enabling the possibility of a
126
function's implementation to refer to another function whose name is
127
known but is not actually defined yet (see A.8 below for more
128
details).
129
130
The GAP code (whether or not it is split into declaration and
131
implementation parts) should go in the package's lib directory (see
132
below).
133
134
doc
135
This directory should contain the package's documentation. It is
136
strongly recommended to use an XML-based documentation format
137
supported by the GAP package GAPDoc (see 'GAPDoc: Introduction and
138
Example') which is used for the GAP documentation. An alternative is
139
to use the TeX-based system, formerly used for the GAP documentation
140
in GAP 4.4 and earlier releases. This system is described in the
141
document The gapmacro.tex Manual Format (the file
142
gap4r5/doc/gapmacrodoc.pdf included in the tools archive as described
143
in Section A.2) and is still used by some of the GAP packages whose
144
authors are encouraged to switch at some point to the GAPDoc-based
145
documenation. Please spend some time reading the documentation for
146
whichever system you decide to use for writing your package's
147
documentation. The Example package's documentation is written in the
148
XML format supported by the GAPDoc package. If you intend to use this
149
format, please use the Example package's doc directory as a prototype,
150
which as you will observe contains the master file main.xml, further
151
.xml files for manual chapters (included in the manual via Include
152
directives in the master file) and the GAP input file ../makedocrel.g
153
which generates the manuals. Generally, one should also provide a
154
manual.bib BibTeX database file or an xml file in the BibXMLext format
155
(see 'GAPDoc: The BibXMLext Format'). With gapmacro.tex, it is also
156
possible to use a manual.bbl file.
157
158
lib
159
This is the preferred place for the GAP code, i.e. the .g, .gd and .gi
160
files (other than PackageInfo.g, init.g and read.g). For some
161
packages, the directory gap has been used instead of lib; lib has the
162
slight advantage that it is the default subdirectory of a package
163
directory searched for by the DirectoriesPackageLibrary (Reference:
164
DirectoriesPackageLibrary) command.
165
166
src
167
If the package has non-GAP code, e.g. C code, then this source code
168
should go in the src directory. If there are .h include files you may
169
prefer to put these all together in a separate include directory.
170
There is one further rule for the location of kernel library modules
171
or external programs which is explained in A.10-1 below.
172
173
tst
174
If the package has test files, then they should go in the tst
175
directory. For a deposited package, a test file with a basic test of
176
the package (for example, to check that it works as expected and/or
177
that the manual examples are correct) may be specified in the
178
PackageInfo.g to be included in the GAP standard test suite. More
179
specific and time consuming tests are not supposed to be a part of the
180
GAP standard test suite but may be placed in the tst directory with
181
further instructions on how to run them. See Section A.14 about the
182
requirements to the test files formats and further recommendations.
183
184
All other files can be organized as you like. But we suggest that you have a
185
look at existing packages and use a similar scheme, for example, put
186
examples in the examples subdirectory, data libraries in extra
187
subdirectories, and so on.
188
189
Sometimes there may be a need to include an empty directory in the package
190
distribution (for example, as a place to store some data that may appear at
191
runtime). In this case package authors are advised to put in this directory
192
a short README file describing its purpose to ensure that such directory
193
will be included in the redistribution.
194
195
Concerning the GAP code in packages, it is recommended to use only
196
documented GAP functions, see 'Reference: Undocumented Variables'. In
197
particular if you want to make your package available to other GAP users it
198
is advisable to avoid using obsolescent variables (see 'Reference: Replaced
199
and Removed Command Names'). For that, you can set the ReadObsolete
200
component in your gap.ini file to false, see 'Reference: The gap.ini and
201
gaprc files'.
202
203
204
A.2 Writing Documentation and Tools Needed
205
206
If you intend to make your package available to other users it is essential
207
to include documentation explaining how to install and use your programs.
208
209
Concerning the installation you should produce a file README which gives a
210
short description of the purpose of the package and contains proper
211
instructions how to install your package. Again, check out some existing
212
packages to get an idea how this could look like.
213
214
Concerning the documentation of the use of the package there are currently
215
two recognised ways of producing GAP package documentation.
216
217
First, there is a recommended XML-based documentation format that is defined
218
in and can be used with the GAPDoc package (see 'GAPDoc: Introduction and
219
Example').
220
221
Second, there is a method which requires the documentation to be written in
222
TeX according to the format described in the document The gapmacro.tex
223
Manual Format.
224
225
In principle it is also possible to use some completely different
226
documentation format. In that case you need to study the Chapter 'Reference:
227
Interface to the GAP Help System' to learn how to make your documentation
228
available to the GAP help system. There should be at least a text version of
229
your documenation provided for use in the terminal running GAP and some
230
nicely printable version in .pdf format. Many GAP users like to browse the
231
documentation in HTML format via their Web browser. As a package author, you
232
are not obliged to provide an HTML version of your package manual, but if
233
you will either use the GAPDoc package or follow the guidelines in the
234
document The gapmacro.tex Manual Format, (the file
235
gap4r5/doc/gapmacrodoc.pdf included in the tools archive as described in
236
this Section below), you should have no trouble in producing one. Moreover,
237
using the GAPDoc package, it is also possible to produce HTML version of the
238
documentation supporting MathJax (http://www.mathjax.org/) for the high
239
quality rendering of mathematical symbols while viewing it online. For
240
example, if you are viewing the HTML version of the manual, compare how this
241
formula will look with MathJax turned on/off:
242
243
244
[ χ, ψ ] = ( ∑_{g ∈ G} χ(g) ψ(g^{-1}) ) / |G|.
245
246
247
The manual of the Example package is written in the GAPDoc format, and
248
commands needed to build it are contained in the file makedocrel.g (you
249
don't need to re-build the manual since it is already included in the
250
package).
251
252
Whenever you use the GAPDoc or gapmacro.tex TeX-based system, you need to
253
have certain TeX tools installed: to produce manuals in the .pdf format, you
254
need pdflatex if the GAPDoc is used, and either pdftex or gs together with
255
ps2pdf if your package uses gapmacro.tex. Note that using gs and ps2pdf in
256
lieu of pdftex or pdflatex is a poor substitute unless your gs is at least
257
version 6.xx for some xx. In addition, the gapmacro.tex documentation system
258
requires some more tools described below. If you intend to use the GAPDoc
259
package for the documenation of your package, you may skip the rest of this
260
section and proceed to the next one to see a minimalistic example of a GAP
261
package.
262
263
Otherwise, to produce the .pdf manual formats, the following GAP tools
264
(supplied as a part of the GAP distribution in the archive tools.tar.gz in
265
the in GAP's etc directory and installed using the script install-tools.sh
266
in the same directory) are needed: gapmacro.tex (the macros file that
267
dictates the style and mark-up for the traditional TeX-based system of GAP
268
documentation), manualindex (an awk script that adjusts the TeX-produced
269
index entries and calls makeindex to process them), and mrabbrev.bib
270
(usually supplied with your TeX tools but nevertheless a copy of
271
mrabbrev.bib should be located in GAP's main doc directory. To find it on
272
your system, try: kpsewhich mrabbrev.bib or, if that doesn't work and you
273
can't otherwise find it check out a CTAN site, e.g. search for it at:
274
http://www.dante.de/cgi-bin/ctan-index.
275
276
If your manual cross-refers to GAPDoc- or gapmacro.tex-produced manuals,
277
then manual.lab for each such other manual is needed. For packages using
278
GAPDoc-manuals since GAP 4.3, this is done by starting GAP and running
279
280
  gap> GapDocManualLab( "package" );
281
282
for each such package whose manual is cross-referred to (this includes the
283
main manuals, e.g. those in the doc/ref and doc/tut directories). For
284
packages using gapmacro.tex-produced manuals, manual.lab is generated by
285
running tex manual for each package whose manual is cross-referred to. In
286
most cases, packages from the GAP distribution will already have these files
287
since they will be created as a part of building their manuals (see e.g. the
288
last command of the example/makedocrel.g script) and included in their
289
distribution, so you will probably not need to create manual.lab files
290
yourself.
291
292
To produce an HTML version of the manual one needs the Perl 5 program
293
convert.pl which is included in the tools archive tools.tar.gz. This archive
294
is supplied as a part of the GAP distribution in the GAP's etc directory and
295
should be installed using the script install-tools.sh in the same directory.
296
297
Finally, to ensure the mathematical formulae are rendered as well as they
298
can be in the HTML version, one should also have the program tth (TeX to
299
HTML converter); convert.pl calls tth to translate mathmode formulae to HTML
300
(if it's available). The tth program is easy to compile and can be obtained
301
from http://hutchinson.belmont.ma.us/tth/tth-noncom/download.html.
302
303
304
A.3 An Example of a GAP Package
305
306
We illustrate the creation of a GAP package by an example of a basic
307
package.
308
309
Create the following directories in your home area: .gap, .gap/pkg and
310
.gap/pkg/test. Then inside the directory .gap/pkg/test create an empty file
311
init.g, and a file PackageInfo.g with the following contents:
312
313
 Example 
314
SetPackageInfo( rec(
315
 PackageName := "test",
316
 Version := "1.0",
317
 PackageDoc := rec(
318
 BookName := "test",
319
 SixFile := "doc/manual.six",
320
 Autoload := true ),
321
 Dependencies := rec(
322
 GAP := "4.5",
323
 NeededOtherPackages := [ ["GAPDoc", "1.3"] ],
324
 SuggestedOtherPackages := [ ] ),
325
 AvailabilityTest := ReturnTrue ) );
326

327
328
This file declares the GAP package with name test in version 1.0. The
329
package documentation consists of one autoloaded book; the SixFile component
330
is needed by the GAP help system. Package dependencies require at least
331
GAP 4.5 and GAPDoc package at version at least 1.3, and these conditions
332
will be checked when the package will be loaded (see A.13). Since there are
333
no requirements that have to be tested, AvailabilityTest just uses
334
ReturnTrue (Reference: ReturnTrue).
335
336
Now start GAP (without using the -r option) and the .gap directory will be
337
added to the GAP root directory to allow GAP to find the packages installed
338
there (see 'Reference: GAP Root Directories').
339
340
 Example 
341
gap> LoadPackage("test");
342
true
343

344
345
This GAP package is too simple to be useful, but we have succeeded in
346
loading it via LoadPackage (Reference: LoadPackage), satisfying all
347
specified dependencies.
348
349
350
A.4 File Structure
351
352
Package files may follow the style used for the GAP library. Every file in
353
the GAP library starts with a header that lists the filename, copyright, a
354
short description of the file contents and the original authors of this
355
file, and ends with a comment line #E. Indentation in functions and the use
356
of decorative spaces in the code are left to the decision of the authors of
357
each file. Global (i.e. re-used elsewhere) comments usually are indented by
358
two hash marks and two blanks, in particular, every declaration or method or
359
function installation which is not only of local scope is separated by a
360
header.
361
362
Historically, when the GAP main manuals were based on the TeX macros
363
described in the document The gapmacro.tex Manual Format (the file
364
gap4r5/doc/gapmacrodoc.pdf included in the tools archive as described in
365
Section A.2) such headers were used for the manuals and have the type
366
367
 Example 
368
#############################################################################
369
##
370
#X ExampleFunction(<A>,<B>)
371
##
372
## This function does great things.
373

374
375
where X was one of the letters: F, A, P, O, C, R or V indicating whether the
376
object declared will be a function, attribute, property, operation,
377
category, representation or variable, respectively. Additionally M was used
378
in .gi files for method installations. Then a sample usage of the function
379
was given, followed by a comment which described the identifier. This
380
description was automatically be extracted to build the manual source, if
381
there is a \Declaration line in some .msk file together with an appropriate
382
configuration file.
383
384
Nowadays, facilities to distribute a document over several files to allow
385
the documentation for parts of some code to be stored in the same file as
386
the code itself are provided by the GAPDoc package (see 'GAPDoc:
387
Distributing a Document into Several Files'). The same approach is
388
demonstrated by the Example package. E.g. example/doc/example.xml has the
389
statement <#Include Label="ListDirectory"> and example/lib/files.gd contains
390
391
 Example 
392
#############################################################################
393
##
394
#F ListDirectory([<dir>]) . . . . . . . . . . list the files in a directory
395
##
396
## <#GAPDoc Label="ListDirectory">
397
## <ManSection>
398
## <Func Name="ListDirectory" Arg="[dir]"/>
399
##
400
## <Description>
401
## lists the files in directory <A>dir</A> (a string) 
402
## or the current directory if called with no arguments.
403
## </Description>
404
## </ManSection>
405
## <#/GAPDoc>
406
DeclareGlobalFunction( "ListDirectory" );
407

408
409
This is all put together in the file example/makedocrel.g which builds the
410
package documentation, calling MakeGAPDocDoc (GAPDoc: MakeGAPDocDoc) with
411
locations of library files containing parts of the documentation.
412
413
414
A.5 The PackageInfo.g File
415
416
As a first step the example in A.3 shows the information needed for the
417
package loading mechanism to load a simple package. However, if your package
418
depends on the functionality of other packages, the component Dependencies
419
given in the PackageInfo.g file becomes important (see A.7 below), and more
420
entries become relevant if you want to distribute your package: they contain
421
lists of authors and/or maintainers including contact information, URLs of
422
the package archives and README files, status information, text for a
423
package overview Web page, and so on.
424
425
We suggest to create a PackageInfo.g file for your package by copying the
426
one in the Example package, distributed with GAP, and then adjusting it for
427
your package. Within GAP you can look at this template file for a list and
428
explanation of all recognized entries by
429
430
 Example 
431
Pager(StringFile(Filename(DirectoriesLibrary(), 
432
 "../pkg/example/PackageInfo.g")));
433

434
435
Once you have created the PackageInfo.g file for your package, you can test
436
its validity with the function ValidatePackageInfo (Reference:
437
ValidatePackageInfo).
438
439
440
A.6 Functions and Variables and Choices of Their Names
441
442
In writing the GAP code for your package you need to be a little careful on
443
just how you define your functions and variables.
444
445
Firstly, in general one should avoid defining functions and variables via
446
assignment statements in the way you would interactively, e.g.
447
448
 Example 
449
gap> Squared := x -> x^2;;
450
gap> Cubed := function(x) return x^3; end;;
451

452
453
The reason for this is that such functions and variables are easily
454
overwritten and what's more you are not warned about it when it happens.
455
456
To protect a function or variable against overwriting there is the command
457
BindGlobal (Reference: BindGlobal), or alternatively (and equivalently) you
458
may define a global function via a DeclareGlobalFunction (Reference:
459
DeclareGlobalFunction) and InstallGlobalFunction (Reference:
460
InstallGlobalFunction) pair or a global variable via a DeclareGlobalVariable
461
(Reference: DeclareGlobalVariable) and InstallValue (Reference:
462
InstallValue) pair. There are also operations and their methods, and related
463
objects like attributes and filters which also have Declare... and
464
Install... pairs.
465
466
Secondly, it's a good idea to reduce the chance of accidental overwriting by
467
choosing names for your functions and variables that begin with a string
468
that identifies it with the package, e.g. some of the undocumented functions
469
in the Example package begin with Eg. This is especially important in cases
470
where you actually want the user to be able to change the value of a
471
function or variable defined by your package, for which you have used direct
472
assignments (for which the user will receive no warning if she accidentally
473
overwrites them). It's also important for functions and variables defined
474
via BindGlobal, DeclareGlobalFunction/InstallGlobalFunction and
475
DeclareGlobalVariable/InstallValue, in order to avoid name clashes that may
476
occur with (extensions of) the GAP library and other packages.
477
478
Additionally, since GAP 4.5 a package may place global variables into a
479
local namespace as explained in 'Reference: Namespaces for GAP packages' in
480
order to avoid name clashes and preserve compatibility. This new feature
481
allows you to define in your package global variables with the identifier
482
ending with the @ symbol, e.g. xYz@. Such variables may be used in your
483
package code safely, as they may be accessed from outside the package only
484
by their full name, i.e. xYz@YourPackageName. This helps to prevent clashes
485
between different packages or between a package and the GAP library because
486
of the same variable names.
487
488
On the other hand, operations and their methods (defined via
489
DeclareOperation (Reference: DeclareOperation), InstallMethod (Reference:
490
InstallMethod) etc. pairs) and their relatives do not need this
491
consideration, as they avoid name clashes by allowing for more than one
492
method for the same-named object.
493
494
To demonstrate the definition of a function via a
495
DeclareOperation/InstallMethod pair, the method Recipe (1.1-8) was included
496
in the Example package; Recipe( FruitCake ); gives a method for making a
497
fruit cake (forgive the pun).
498
499
Thirdly, functions or variables with SetXXX or HasXXX names (even if they
500
are defined as operations) should be avoided as these may clash with objects
501
associated with attributes or properties (attributes and properties XXX
502
declared via the DeclareAttribute and DeclareProperty commands have
503
associated with them testers of form HasXXX and setters of form SetXXX).
504
505
Fourthly, it is a good idea to have some convention for internal functions
506
and variables (i.e. the functions and variables you don't intend for the
507
user to use). For example, they might be entirely CAPITALISED.
508
509
Additionally, there is a recommended naming convention that the GAP core
510
system and GAP packages should not use global variables starting in the
511
lowercase. This allows to reserve variables with names starting in lowecase
512
to the GAP user so they will never clash with the system. It is extremely
513
important to avoid using for package global variables very short names
514
started in lowercase. For example, such names like cs, exp, ngens, pc, pow
515
which are perfectly fine for local variables, should never be used for
516
globals. Additionally, the package must not have writable global variables
517
with very short names even if they are starting in uppercase, for example,
518
C1 or ORB, since they also could be easily overwritten by the user.
519
520
It is a good practice to follow naming conventions used in GAP as explained
521
in 'Reference: Naming Conventions' and 'Tutorial: Changing the Structure',
522
which might help users to memorize or even guess names of functions provided
523
by the package.
524
525
Finally, note the advantage of using
526
DeclareGlobalFunction/InstallGlobalFunction,
527
DeclareGlobalVariable/InstallValue, etc. pairs (rather than BindGlobal) to
528
define functions and variables, which allow the package author to organise
529
her function- and variable- definitions in any order without worrying about
530
any interdependence. The Declare... statements should go in files with .gd
531
extensions and be loaded by ReadPackage statements in the package init.g
532
file, and the Install... definitions should go in files with .gi extensions
533
and be loaded by ReadPackage statements in the package read.g file; this
534
ensures that the .gi files are read after the .gd files. All other package
535
code should go in .g files (other than the init.g and read.g files
536
themselves) and be loaded via ReadPackage statements in the init.g file.
537
538
In conclusion, here is some practical advice on how to check which variables
539
are used by the package.
540
541
Firstly, there is a function ShowPackageVariables (Reference:
542
ShowPackageVariables). If the package pkgname is available but not yet
543
loaded then ShowPackageVariables( pkgname ) prints a list of global
544
variables that become bound and of methods that become installed when the
545
package is loaded (for that, the package will be actually loaded, so
546
ShowPackageVariables can be called only once for the same package in the
547
same GAP session.) The second optional argument version may specify a
548
particular package version to be loaded. An error message will be printed if
549
(the given version of) the package is not available or already loaded.
550
551
Info lines for undocumented variables will be marked with an asterisk *.
552
Note that the GAP help system is case insensitive, so it is difficult to
553
document identifiers that differ only by case.
554
555
The following entries are omitted from the list: default setter methods for
556
attributes and properties that are declared in the package, and Setattr and
557
Hasattr type variables where attr is an attribute or property.
558
559
For example, for this package it currently produces the following output:
560
561
 Example 
562
gap> ShowPackageVariables("example");
563
----------------------------------------------------------------
564
Loading Example 3.3 (Example/Template of a GAP Package)
565
by Werner Nickel (http://www.mathematik.tu-darmstadt.de/~nickel),
566
 Greg Gamble (http://www.math.rwth-aachen.de/~Greg.Gamble), and
567
 Alexander Konovalov (http://www.cs.st-andrews.ac.uk/~alexk/).
568
----------------------------------------------------------------
569
new global functions:
570
 EgSeparatedString( str, c )*
571
 FindFile( dir, file )
572
 HelloWorld( )
573
 ListDirectory( arg )
574
 LoadedPackages( )
575
 WhereIsPkgProgram( prg )
576
 Which( prg )
577

578
new global variables:
579
 FruitCake
580

581
new operations:
582
 Recipe( arg )
583

584
new methods:
585
 Recipe( cake )
586

587
588
Another trick is to start GAP with -r -A options, immediately load your
589
package and then call NamesUserGVars (Reference: NamesUserGVars) which
590
returns a list of the global variable names created since the library was
591
read, to which a value is currently bound. For example, for the Example it
592
produces
593
594
 Example 
595
gap> NamesUserGVars();
596
[ "EgSeparatedString", "FindFile", "FruitCake", "HelloWorld", "ListDirectory",
597
 "LoadedPackages", "Recipe", "WhereIsPkgProgram", "Which" ]
598

599
600
but for packages with dependencies it will also contain variables created by
601
other packages. Nevertheless, it may be a useful check to search for
602
unwanted variables appearing after package loading. A potentially dangerous
603
situation which should be avoided is when the package uses some simply named
604
temporary variables at the loading stage. Such phantom variables may then
605
remain unnoticed and, as a result, there will be no warnings if the user
606
occasionally uses the same name as a local variable name in a function. Even
607
more dangerous is the case when the user variable with the same name already
608
exists before the package is loaded so it will be silently overwritten.
609
610
611
A.7 Package Dependencies (Requesting one GAP Package from within Another)
612
613
It is possible for one GAP package A, say, to require another package B. For
614
that, one simply adds the name and the (least) version number of the package
615
B to the NeededOtherPackages component of the Dependencies component of the
616
PackageInfo.g file of the package A. In this situation, loading the package
617
A forces that also the package B is loaded, and that A cannot be loaded if B
618
is not available.
619
620
If B is not essential for A but should be loaded if it is available (for
621
example because B provides some improvements of the main system that are
622
useful for A) then the name and the (least) version number of B should be
623
added to the SuggestedOtherPackages component of the Dependencies component
624
of the PackageInfo.g file of A. In this situation, loading A forces an
625
attempt to load also B, but A is loaded even if B is not available.
626
627
Also the component Dependencies.OtherPackagesLoadedInAdvance in
628
PackageInfo.g is supported, which describes needed packages that shall be
629
loaded before the current package is loaded. See A.8 for details about this
630
and more generally about the order in which the files of the packages in
631
question are read.
632
633
All package dependencies must be documented explicitly in the PackageInfo.g
634
file. It is important to properly identify package dependencies and make the
635
right decision whether the other package should be needed or suggested. For
636
example, declaring package as needed when suggested might be sufficient may
637
prevent loading of packages under Windows for no good reason.
638
639
It is not appropriate to explicitly call LoadPackage (Reference:
640
LoadPackage) when the package is loaded, since this may distort the order of
641
package loading and result in warning messages. It is recommended to turn
642
such dependencies into needed or suggested packages. For example, a package
643
can be designed in such a way that it can be loaded with restricted
644
functionality if another package (or standalone program) is missing, and in
645
this case the missing package (or binary) is suggested. Alternatively, if
646
the package author decides that loading the package in this situation makes
647
no sense, then the missing component is needed.
648
649
On the other hand, if LoadPackage (Reference: LoadPackage) is called inside
650
functions of the package then there is no such problem, provided that these
651
functions are called only after the package has been loaded, so it is not
652
necessary to specify the other package as suggested. The same applies to
653
test files and manual examples, which may be simply extended by calls to
654
LoadPackage (Reference: LoadPackage).
655
656
It may happen that a package B that is listed as a suggested package of
657
package A is actually needed by A. If no explicit LoadPackage (Reference:
658
LoadPackage) calls for B occur in A at loading time, this can now be
659
detected using the new possibility to load a package without loading its
660
suggested packages using the global option OnlyNeeded which can be used to
661
(recursively) suppress loading the suggested packages of the package in
662
question. Using this option, one can check whether errors or warnings appear
663
when B is not available (note that this option should be used only for such
664
checks to simulate the situation when package B is not available; it is not
665
supposed to be used in an actual GAP session when package B will be loaded
666
later, since this may cause problems). In case of any errors or warnings,
667
their consequence can then be either turning B into a needed package or
668
(since apparently B was not intended to become a needed package) changing
669
the code accordingly. Only if package A calls LoadPackage (Reference:
670
LoadPackage) for B at loading time (see above) then package B needs to be
671
deinstalled (i.e. removed) to test loading of A without B.
672
673
Finally, if the package manual is in the GAPDoc format, then GAPDoc should
674
still be listed as needed for this package (not as suggested), even though
675
GAPDoc is now a needed package for GAP itself.
676
677
678
A.8 Declaration and Implementation Part of a Package
679
680
When GAP packages require each other in a circular way, a bootstrapping
681
problem arises of defining functions before they are called. The same
682
problem occurs in the GAP library, and it is resolved there by separating
683
declarations (which define global variables such as filters and operations)
684
and implementations (which install global functions and methods) in
685
different files. Any implementation file may use global variables defined in
686
any declaration file. GAP initially reads all declaration files (in the
687
library they have a .gd suffix) and afterwards reads all implementation
688
files (which have a .gi suffix).
689
690
Something similar is possible for GAP packages: if a file read.g exists in
691
the home directory of the package, this file is read only after all the
692
init.g files of all (implicitly) required GAP packages are read. Thus one
693
can separate declaration and implementation for a GAP package in the same
694
way as is done for the GAP library, by creating a file read.g, restricting
695
the ReadPackage (Reference: ReadPackage) statements in init.g to only read
696
those files of the package that provide declarations, and to read the
697
implementation files from read.g.
698
699
Examples:
700
701
Suppose that there are two packages A and B, each with files init.g and
702
read.g.
703
704
 If package A suggests or needs package B and package B does not need
705
or suggest any other package then first init.g of B is read, then
706
read.g of B, then init.g of A, then read.g of A.
707
708
 If package A suggests or needs package B and package B (or a package
709
that is suggested or needed by B) suggests or needs package A then
710
first the files init.g of A and B are read (in an unspecified order)
711
and then the files read.g of A and B (in the same order).
712
713
In general, when GAP is asked to load a package then first the dependencies
714
between this packages and its needed and suggested packages are inspected
715
(recursively), and a list of package sets is computed such that no cyclic
716
dependencies occur between different package sets and such that no package
717
in any of the package sets needs any package in later package sets. Then GAP
718
runs through the package sets and reads for each set first all init.g files
719
and then all read.g files of the packages in the set. (There is one
720
exception from this rule: Whenever packages are autoloaded before the
721
implementation part of the GAP library is read, only the init.g files of the
722
packages are read; as soon as the GAP library has been read, the read.g
723
files of these packages are also read, and afterwards the above rule holds.)
724
725
It can happen that some code of a package depends on the availability of
726
suggested packages, i.e., different initializations are performed depending
727
on whether a suggested package will eventually be loaded or not. One can
728
test this condition with the function IsPackageMarkedForLoading (Reference:
729
IsPackageMarkedForLoading). In particular, one should not call (and use the
730
value returned by this call) the function LoadPackage (Reference:
731
LoadPackage) inside package code that is read during package loading. Note
732
that for debugging purposes loading suggested packages may have been
733
deliberately disabled via the global option OnlyNeeded.
734
735
Note that the separation of the GAP code of packages into declaration part
736
and implementation part does in general not allow one to actually call
737
functions from a package when the implementation part is read. For example,
738
in the case of a cyclic dependency as in the second example above, suppose
739
that B provides a new function f or a new global record r, say, which are
740
declared in the declaration part of B. Then the code in the implementation
741
part of A may contain calls to the functions defined in the declaration part
742
of B. However, the implementation part of A may be read before the
743
implementation part of B. So one can in general not assume that during the
744
loading of A, the function f can be called, or that one can access
745
components of the record r.
746
747
If one wants to call the function f or to access components of the record r
748
in the code of the package A then the problem is that it may be not possible
749
to determine a cyclic dependency between A and B from the packages A and B
750
alone. A safe solution is then to add the name of B to the component
751
Dependencies.OtherPackagesLoadedInAdvance of the PackageInfo.g file of A.
752
The effect is that package B is completely loaded before the file read.g of
753
A is read, provided that there is no cyclic dependency between A and B, and
754
that package A is regarded as not available in the case that such a cyclic
755
dependency between A and B exists.
756
757
A special case where Dependencies.OtherPackagesLoadedInAdvance can be useful
758
is that a package wants to force the complete GAP library to be read before
759
the file read.g of the package A is read. In this situation, the package
760
name "gap" should be added to this component in the PackageInfo.g file of A.
761
762
In the case of cyclic dependencies, one solution for the above problem might
763
be to delay those computations (typically initializations) in package A that
764
require package B to be loaded until all required packages are completely
765
loaded. This can be done by moving the declaration and implementation of the
766
variables that are created in the initialization into a separate file and to
767
declare these variables in the init.g file of the package, via a call to
768
DeclareAutoreadableVariables (Reference: DeclareAutoreadableVariables) (see
769
also A.9).
770
771
772
A.9 Autoreadable Variables
773
774
Package files containing method installations must be read when the package
775
is loaded. For package files not containing method installations (this
776
applies, for example, to many data files) another mechanism allows one to
777
delay reading such files until the data are actually accessed. See
778
Reference: DeclareAutoreadableVariables for further details.
779
780
781
A.10 Standalone Programs in a GAP Package
782
783
GAP packages that involve stand-alone programs are fundamentally different
784
from GAP packages that consist entirely of GAP code.
785
786
This difference is threefold: A user who installs the GAP package must also
787
compile (or install) the package's binaries, the package must check whether
788
the binaries are indeed available, and finally the GAP code of the package
789
has to start the external binary and to communicate with it. We will cover
790
these three points in the following sections.
791
792
If the package does not solely consist of an interface to an external binary
793
and if the external program called is not just special-purpose code, but a
794
generally available program, chances are high that sooner or later other GAP
795
packages might also require this program. We therefore strongly recommend
796
the provision of a documented GAP function that will call the external
797
binary. We also suggest to create actually two GAP packages; the first
798
providing only the binary and the interface and the second (requiring the
799
first, see A.7) being the actual GAP package.
800
801
802
A.10-1 Installation of GAP Package Binaries
803
804
The scheme for the installation of package binaries which is described
805
further on is intended to permit the installation on different architectures
806
which share a common file system (and share the architecture independent
807
file).
808
809
A GAP package which includes external binaries contains a bin subdirectory.
810
This subdirectory in turn contains subdirectories for the different
811
architectures on which the GAP package binaries are installed. The names of
812
these directories must be the same as the names of the architecture
813
dependent subdirectories of the main bin directory. Unless you use a tool
814
like autoconf yourself, you must obtain the correct name of the binary
815
directory from the main GAP branch. To help with this, the main GAP
816
directory contains a file sysinfo.gap which assigns the shell variable
817
GAParch to the proper name as determined by GAP's configure process. For
818
example on a Linux system, the file sysinfo.gap may look like this:
819
820
 Example 
821
GAParch=i586-unknown-linux2.0.31-gcc
822

823
824
We suggest that your GAP package contains a file configure which is called
825
with the path of the GAP root directory as parameter. This file then will
826
read sysinfo.gap and set up everything for compiling under the given
827
architecture (for example creating a Makefile from Makefile.in). As initial
828
templates, you may use installation scripts of the Example package.
829
830
831
A.10-2 Test for the Existence of GAP Package Binaries
832
833
If an external binary is essential for the workings of a GAP package, the
834
function stored in the component AvailabilityTest of the PackageInfo.g file
835
of the package should test whether the program has been compiled on the
836
architecture (and inhibit package loading if this is not the case). This is
837
especially important if the package is loaded automatically.
838
839
The easiest way to accomplish this is to use Filename (Reference: Filename
840
(for a directory and a string)) for checking for the actual binaries in the
841
path given by DirectoriesPackagePrograms (Reference:
842
DirectoriesPackagePrograms) for the respective package. For example the
843
example GAP package could use the following function to test whether the
844
binary hello has been compiled; it will issue a warning if not, and will
845
only load the package if the binary is indeed available:
846
847
 Example 
848
...
849
AvailabilityTest := function()
850
 local path,file;
851
 # test for existence of the compiled binary
852
 path:= DirectoriesPackagePrograms( "example" );
853
 file:= Filename( path, "hello" );
854
 if file = fail then
855
 LogPackageLoadingMessage( PACKAGE_WARNING,
856
 [ "The program `hello' is not compiled,",
857
 "`HelloWorld()' is thus unavailable.",
858
 "See the installation instructions;",
859
 "type: ?Installing the Example package" ] );
860
 fi;
861
 return file <> fail;
862
 end,
863
...
864

865
866
However, if you look at the actual PackageInfo.g file of the example
867
package, you will see that its AvailabilityTest function always returns
868
true, and just logs the warning if the binary is not available (which may be
869
later viewed with DisplayPackageLoadingLog (Reference:
870
DisplayPackageLoadingLog)). This means that the binary is not regarded as
871
essential for this package.
872
873
You might also have to cope with the situation that external binaries will
874
only run under UNIX (and not, say, under Windows), or may not compile with
875
some compilers or default compiler options. See 'Reference: Testing for the
876
System Architecture' for information on how to test for the architecture.
877
878
Last but not least: do not print anything in the AvailabilityTest function
879
of the package via Print or Info. Instead one should call
880
LogPackageLoadingMessage (Reference: LogPackageLoadingMessage) to store a
881
message which may be viewed later with DisplayPackageLoadingLog (Reference:
882
DisplayPackageLoadingLog) (the latter two functions are introduced in
883
GAP 4.5)
884
885
886
A.10-3 Calling of and Communication with External Binaries
887
888
There are two reasons for this: the input data has to be passed on to the
889
stand-alone program and the stand-alone program has to be started from
890
within GAP.
891
892
There are two principal ways of doing this.
893
894
The first possibility is to write all the data for the stand-alone to one or
895
several files, then start the stand-alone with Process (Reference: Process)
896
or Exec (Reference: Exec) which then writes the output data to file, and
897
finally read in the standalone's output file.
898
899
The second way is interfacing via input-output streams, see
900
Section 'Reference: Input-Output Streams'.
901
902
Some GAP packages use kernel modules (see 'Reference: Kernel modules in GAP
903
packages') instead of external binaries. A kernel module is implemented in C
904
and follows certain conventions to comply with the GAP kernel interface,
905
which we plan to document later. In the meantime, we advise you to look at
906
existing examples of such packages and get in touch with GAP developers if
907
you plan to develop such a package.
908
909
910
A.11 Having an InfoClass
911
912
It is a good idea to declare an InfoClass for your package. This gives the
913
package user the opportunity to control the verbosity of output and/or the
914
possibility of receiving debugging information (see 'Reference: Info
915
Functions'). Below, we give a quick overview of its utility.
916
917
An InfoClass is defined with a DeclareInfoClass( InfoPkgname ); statement
918
and may be set to have an initial InfoLevel other than the zero default
919
(which means no Info statement is to output information) via a SetInfoLevel(
920
InfoPkgname, level ); statement. An initial InfoLevel of 1 is typical.
921
922
Info statements have the form: Info( InfoPkgname, level, expr1, expr2, ...);
923
where the expression list expr1, expr2, ... appears just like it would in a
924
Print statement. The only difference is that the expression list is only
925
printed (or even executed) if the InfoLevel of InfoPkgname is at least
926
level.
927
928
929
A.12 The Banner
930
931
Since GAP 4.4, the package banner, if one is desired, should be provided by
932
assigning a string to the BannerString field of the record argument of
933
SetPackageInfo in the PackageInfo.g file.
934
935
It is a good idea to have a hook into your package documentation from your
936
banner. The banner of the Example package suggests to the GAP user:
937
938
 Example 
939
For help, type: ?Example package
940

941
942
In order for this to display the introduction of the Example package the
943
index-entry <Index>Example package</Index> was added just before the first
944
paragraph of the introductory section in the file example.xml. The Example
945
package uses GAPDoc (see Section A.2) for documentation (you will need some
946
different scheme to achieve this using the gapmacro.tex system).
947
948
949
A.13 Version Numbers
950
951
Version numbers are strings containing nonnegative integers separated by
952
non-numeric characters. They are compared by CompareVersionNumbers
953
(Reference: CompareVersionNumbers) which first splits them at non-digit
954
characters and then lexicographically compares the resulting integer lists.
955
Thus version "2-3" is larger than version "2-2-5" but smaller than "4r2p3"
956
or "11.0".
957
958
It is possible for code to require GAP packages in certain versions. In this
959
case, all versions, whose number is equal or larger than the requested
960
number are acceptable. It is the task of the package author to provide
961
upwards compatibility.
962
963
Loading a specific version of a package (that is, not one with a larger
964
version number) can be achieved by prepending = to the desired version
965
number. For example, LoadPackage( "example", "=1.0" ) will load version
966
"1.0" of the package "example", even if version "1.1" is available. As a
967
consequence, version numbers must not start with =, so "=1.0" is not a valid
968
version number.
969
970
Package authors should choose a version numbering scheme that admits a new
971
version number even after tiny changes to the package, and ensure that
972
version numbers of successive package versions increase. The automatic
973
update of package archives in the GAP distribution will only work if a
974
package has a new version number.
975
976
It is a well-established custom to name package archives like
977
name-version.tar.gz, name-version.tar.bz2 etc., where name is the lower case
978
name, and version is the version (another custom is that the archive then
979
should extract to a directory that has exactly the name name-version).
980
981
It is very important that there should not ever be, for a given GAP package,
982
two different archives with the same package version number. If you make
983
changes to your package and place a new archive of the package onto the
984
public server, please ensure that a new archive has a new version number.
985
This should be done even for very minor changes.
986
987
For most of the packages it will be inappropriate to re-use the date of the
988
release as a version number. It's much more obvious how big are the changes
989
between versions "4.4.12", "4.5.1" and "4.5.2" than between versions
990
"2008.12.17", "2011.04.15" and "2011.09.14".
991
992
Since version information is duplicated in several places throughout the
993
package documentation, for GAPDoc-based manuals you may define the version
994
and the release manual in the comments in PackageInfo.g file close to the
995
place where you specified its Version and Date components, for example
996
997
 Example 
998
## <#GAPDoc Label="PKGVERSIONDATA">
999
## <!ENTITY VERSION "3.3">
1000
## <!ENTITY RELEASEDATE "11/11/2011">
1001
## <#/GAPDoc>
1002

1003
1004
notify MakeGAPDocDoc (GAPDoc: MakeGAPDocDoc) that a part of the document is
1005
stored in PackageInfo.g (see example/makedocrel.g), read this data into the
1006
header of the main document via <#Include Label="PKGVERSIONDATA"> directive
1007
and then use them via &VERSION; and &RELEASEDATE; entities almost everywhere
1008
where you need to refer to them (most commonly, in the title page and
1009
installation instructions).
1010
1011
1012
A.14 Testing a GAP package
1013
1014
1015
A.14-1 Tests files for a GAP package
1016
1017
The (optional) tst directory of your package may contain as many tests of
1018
the package functionality as appears appropriate. These tests should be
1019
organised into test files similarly to those in the tst directory of the GAP
1020
distribution as documented in 'Reference: Test Files'.
1021
1022
For a deposited package, a test file with a basic test of the package (for
1023
example, to check that it works as expected and/or that the manual examples
1024
are correct) may be specified in the component TestFile in the PackageInfo.g
1025
to be included in the GAP standard test suite. This file can either consist
1026
of Test (Reference: Test) calls (in this case, it is common to call it
1027
testall.g) or be itself a test file having an extension .tst and supposed to
1028
be read via Test (Reference: Test). It is assumed that the latter case
1029
occurs if and only if the file contains the substring
1030
1031
 "gap> START_TEST("
1032
1033
(with exactly one space after the GAP prompt).
1034
1035
For deposited packages, these tests are run by the GAP Group regularly, as a
1036
part of the standard GAP test suite. For the efficient testing it is
1037
important that the test specified in the PackageInfo.g file does not display
1038
any output (e.g. no test progress indicators) except reporting discrepancies
1039
if such occur and the completion report as in the example below:
1040
1041
 Example 
1042
gap> Test("tst/testall.tst");
1043
Example package: testall.tst
1044
GAP4stones: 3333
1045
true
1046

1047
1048
Tests which produce extended output and/or requires substantial runtime are
1049
not supposed to be a part of the GAP standard test suite but may be placed
1050
in the tst directory of the packages with further instructions on how to run
1051
them elsewhere.
1052
1053
1054
A.14-2 Testing GAP package loading
1055
1056
To test that your package may be loaded into GAP without any problems and
1057
conflicts with other packages, test that it may be loaded in various
1058
configurations:
1059
1060
 starting GAP with no packages (except needed for GAP) using -r -A
1061
options and calling LoadPackage("your-package-name");
1062
1063
 starting GAP with no packages (except needed for GAP) using -r -A
1064
options and calling LoadPackage("your-package-name" : OnlyNeeded );
1065
1066
 starting GAP in the default configuration (with no options) and
1067
calling LoadPackage("your-package-name");
1068
1069
 starting GAP in the default configuration (with no options) and
1070
calling LoadPackage("your-package-name" : OnlyNeeded );
1071
1072
 finally, together with all other packages using LoadAllPackages
1073
(A.14-3) (see below) in four possible combinations of starting GAP
1074
with/without -r -A options and calling LoadAllPackages (A.14-3)
1075
with/without Reversed option.
1076
1077
The test of loading all packages is the most subtle one. Quite often it
1078
reveals problems which do not occur in the default configuration but may
1079
cause difficulties to the users of specialised packages.
1080
1081
For your convenience, make testpackagesload called in the GAP root directory
1082
will run all package loading tests listed in this subsection and write their
1083
output in its dev/log directory.
1084
1085
It will produce four files with test logs, corresponding to the four cases
1086
above (the letter N in the filename stands for needed, A stands for
1087
autoloaded):
1088
1089
 dev/log/testpackagesload1_...
1090
1091
 dev/log/testpackagesloadN1_...
1092
1093
 dev/log/testpackagesloadA_...
1094
1095
 dev/log/testpackagesloadNA_...
1096
1097
Each file contains small sections for loading individual packages: among
1098
those, you need to find the section related to your package and may ignore
1099
all other sections. For example, the section for the Example package looks
1100
like
1101
1102
 Example 
1103
%%% Loading example 3.3.3
1104
[ ]
1105
### Loaded example 3.3.3
1106

1107
1108
so it has clearly passed the test. If there are any error messages displayed
1109
between Loading ... and Loaded ... lines, they will signal on errors during
1110
loading of your package.
1111
1112
Additionally, this test collects information about variables created since
1113
the library was read (obtained using NamesUserGVars (Reference:
1114
NamesUserGVars)) with either short names (no more than three characters) or
1115
names breaking a recommended naming convention that the GAP core system and
1116
GAP packages should not use global variables starting in the lowercase (see
1117
Section A.6). Their list will be displayed in the test log (in the example
1118
above, Example packages does not create any such variables, so an empty list
1119
is displayed). It may be hard to attribute a particular identifier to a
1120
package, since it may be created by another package loaded because of
1121
dependencies, so when a more detailed and precise report on package
1122
variables is needed, it may be obtained using ShowPackageVariables
1123
(Reference: ShowPackageVariables) (also, make testpackagesvars called in the
1124
GAP root directory produces such reports for each package and writes them to
1125
a file dev/log/testpackagesvars_...).
1126
1127
Finally, each log file finishes with two large sections for loading all
1128
packages in the alphabetical and reverse aplhabetical order (to check more
1129
combinations of loading one package after another). We are aiming at
1130
releasing only collections of package which do not break LoadAllPackages
1131
(A.14-3) in any of the four configurations, so if it is broken when you plug
1132
in the development version of your package into the released version of GAP,
1133
it is likely that your package triggers this error. If you observe that
1134
LoadAllPackages (A.14-3) is broken and suspect that this is not the fault of
1135
your package, please contact the GAP Support.
1136
1137
A.14-3 LoadAllPackages
1138
1139
LoadAllPackages( : Reversed )  function
1140
1141
loads all GAP packages from their list sorted in alphabetical order (needed
1142
and suggested packages will be loaded when required). This is a technical
1143
function to check packages compatibility, so it should NOT be used to run
1144
anything except tests; it is known that GAP performance is slower if all
1145
packages are loaded. To introduce some variations of the order in which
1146
packages will be loaded for testing purposes, LoadAllPackages accepts
1147
version Reversed to load packages from their list sorted in the reverse
1148
alphabetical order.
1149
1150
1151
A.14-4 Testing a GAP package with the GAP standard test suite
1152
1153
The tst directory of the GAP installation contains a selection of test files
1154
and two scripts, testinstall.g and testall.g which are a part of the GAP
1155
standard test suite.
1156
1157
It is important to check that your package does not break GAP standard
1158
tests. To perform a clean test and avoid interfering with other packages,
1159
first you must start a new GAP session with the following command (assuming
1160
that gap starts GAP in your system):
1161
1162
 Example 
1163
gap -N -A -x 80 -r -m 100m -o 512m
1164

1165
1166
After that load your package and run either testinstall.g or testall.g as
1167
demonstrated below.
1168
1169
The quicker test, testinstall.g, requires about 512MB of memory and runs for
1170
about one minute on an Intel Core 2 Duo / 2.53 GHz machine. It may be
1171
started with the command
1172
1173
 Example 
1174
gap> Read( Filename( DirectoriesLibrary( "tst" ), "testinstall.g" ) );
1175

1176
1177
You will get a large number of lines with output about the progress of the
1178
tests.
1179
1180
 Example 
1181
test file GAP4stones time(msec)
1182
-------------------------------------------
1183
testing: .../gap4r5/tst/zlattice.tst
1184
zlattice.tst 0 0
1185
testing: .../gap4r5/tst/gaussian.tst
1186
gaussian.tst 0 10
1187
... further lines deleted ...
1188

1189
1190
The more thorough test is testall.g which exercises more of GAP's
1191
capabilities, containing all test files from testinstall.g as a subset. It
1192
requires about 512MB of memory, runs for about one hour on an Intel Core 2
1193
Duo / 2.53 GHz machine, and produces an output similar to the testinstall.g
1194
test. To run it, also start a new GAP session with gap -N -A -x 80 -r -m
1195
100m -o 512m and then call
1196
1197
 Example 
1198
gap> Read( Filename( DirectoriesLibrary( "tst" ), "testall.g" ) );
1199

1200
1201
You may repeat the same check loading your package with OnlyNeeded option.
1202
Remember to perform each subsequent test in a new GAP session.
1203
1204
Also you may perform individual tests from the tst directory of the GAP
1205
installation loading them with Test (Reference: Test), for example, the file
1206
bugfix.tst.
1207
1208
1209
A.15 Access to the GAP Development Version
1210
1211
We are aiming at providing a stable platform for package development and
1212
testing with official GAP releases. However, when it may be of benefit to
1213
obtain access to the GAP development version, please contact the GAP team by
1214
mailing to mailto:[email protected].
1215
1216
1217
A.16 Selecting a license for a GAP Package
1218
1219
It is advised to make clear in the documentation of the package the basis on
1220
which it is being distributed to users. GAP itself is distributed under the
1221
GNU Public License version 2 (version 2 or later). We would encourage you to
1222
consider the GPL for your packages, but you might wish to be more
1223
restrictive (for instance forbidding redistribution for profit) or less
1224
restrictive (allowing your software to be incorporated into commercial
1225
software). See Choosing a License for the Distribution of Your Package from
1226
http://www.gap-system.org/Packages/Authors/authors.html for further details.
1227
1228
In the past many GAP packages used the text We adopt the copyright
1229
regulations of GAP as detailed in the copyright notice in the GAP manual or
1230
a similar statement. We now advise to be more explicit and make the exact
1231
reference to the GPL license, for example:
1232
1233
 package-name is free software; you can redistribute it and/or modify it
1234
under the terms of the GNU General Public License
1235
(http://www.fsf.org/licenses/gpl.html) as published by the Free Software
1236
Foundation; either version 2 of the License, or (at your option) any later
1237
version. 
1238
1239
1240
A.17 Wrapping up a GAP Package
1241
1242
Currently, the GAP distribution provides archives in four different formats.
1243
1244
.tar.gz
1245
a standard UNIX tar archive, compressed with gzip
1246
1247
.tar.bz2
1248
a standard UNIX tar archive, compressed with bzip2
1249
1250
.zip
1251
an archive in zip format, where text files should have UNIX style line
1252
breaks
1253
1254
-win.zip
1255
an archive in zip format, where text files should have DOS/Windows
1256
style line breaks
1257
1258
For convenience of possible users it is sensible that you provide an archive
1259
of your package in at least one of these formats.
1260
1261
For example, if you wish to supply a .tar.gz archive, you may create it with
1262
the command
1263
1264
 tar -cvzf package-name-version.tar.gz package-name
1265
1266
The etc directory obtained from tools.tar.gz (described above in
1267
Section A.2) contains a file packpack which provides a more versatile
1268
packing-up script.
1269
1270
Because the release of the GAP package is independent of the version of GAP,
1271
a GAP package should be wrapped up in separate file that can be installed
1272
onto any version of GAP. In this way, a package can be upgraded any time
1273
without the need to wait for new GAP releases. To ensure this, the package
1274
should be archived from the GAP pkg directory, that is all files are
1275
archived with the path starting at the package's name.
1276
1277
The archive of a GAP package should contain all files necessary for the
1278
package to work. In particular there should be a compiled documentation,
1279
which includes the manual.six, manual.toc and manual.lab file in the
1280
documentation subdirectory which are created by TeXing the documentation, if
1281
you use GAPDoc or the gapmacro.tex document formats. (The first two files
1282
are needed by the GAP help system, and the manual.lab file is needed if the
1283
main manuals or another package is referring to your package. Use the
1284
command GAPDocManualLab( packagename ); to create this file for your help
1285
books if you use GAPDoc.)
1286
1287
For packages which are redistributed via the GAP Web site, we offer an
1288
automatic conversion of any of the formats listed above to all the others
1289
(note that this, as well as wrapping the GAP distribution as a single
1290
archive containing the core system and all currently redistributed packages,
1291
will change file timestamps, so one should not rely on them anywhere in the
1292
package).
1293
1294
To use the conversion and repackaging service, you can provide any of the
1295
four archive formats or even more than one, however you should adhere to the
1296
following rule: text files in .tar.gz and .tar.bz2 archives must have UNIX
1297
style line breaks, while text files in -win.zip archives must have
1298
DOS/Windows line breaks.
1299
1300
The package wrapping tools for the GAP distribution and web pages then will
1301
use a sensible list of file extensions to decide if a file is a text file
1302
(being conservative, it may miss a few text files). These rules may be
1303
prepended by the application of rules from the PackageInfo.g file:
1304
1305
 if it has a .TextFiles component, then consider the given files as
1306
text files before GAP defaults will be applied;
1307
1308
 if it has a .BinaryFiles component, then consider given files as
1309
binary files before GAP defaults will be applied;
1310
1311
 if it has a .TextBinaryFilesPatterns component, then apply it before
1312
GAP defaults will be applied;
1313
1314
The etc directory obtained from tools.tar.gz (described above in
1315
Section A.2) contains a file classifyfiles.py and two files
1316
patternscolor.txt and patternstextbinary.txt implementing GAP default rules
1317
used to classify files in packages. For most of the packages these default
1318
rules perfecty detect binary and text files, so there is no need for them to
1319
use any of the three optional components. However, .TextBinaryFilesPatterns,
1320
or .TextFiles, or .BinaryFiles will become useful if the package has e.g.
1321
data files which are recognised as binary files by the default rules, or if
1322
the package uses standard extensions in a non-standard way (this is not
1323
recommended, of course). If things will go wrong, it is possible that one
1324
(or indeed all) created archives have wrong line breaks.
1325
1326
Utility functions available in gap4r7/lib/lbutil.g, namely
1327
DosUnixLinebreaks, UnixDosLinebreaks, MacUnixLinebreaks may be helpful. They
1328
are described in the comments to their source code.
1329
1330
1331
A.18 The WWW Homepage of a Package
1332
1333
If you want to distribute your package you should create a WWW homepage
1334
containing some basic information, archives for download, the README file
1335
with installation instructions, and a copy of the package's PackageInfo.g
1336
file.
1337
1338
The responsibility for this WWW homepage is with the package
1339
authors/maintainers.
1340
1341
If you tell us about your package (say, by mail to
1342
mailto:[email protected]) we may consider either
1343
1344
 adding a link to your package homepage from the GAP website (thus, the
1345
package will be an undeposited contribution);
1346
1347
 or redistributing the current version of your package as a part of the
1348
GAP distribution (this, the package will be deposited), also ;
1349
1350
In the latter case we can also provide some services for producing several
1351
archive formats from the archive you provide (e.g., you produce a .tar.gz
1352
version of your archive and we produce also a .tar.bz2 and a -win.zip
1353
version from it).
1354
1355
Please also consider submitting your package to the GAP package refereeing
1356
process (see http://www.gap-system.org/Contacts/submit.html for further
1357
information).
1358
1359
1360
A.19 Upgrading the package to work with GAP 4.5
1361
1362
1363
A.19-1 Changes in GAP 4.5 from the packages perspective
1364
1365
Here we list only those changes which may have some implications for the
1366
packages.
1367
1368
 Changing the distribution format providing one archive with the core
1369
system and all currently redistributed packages.
1370
1371
 The GAP kernel is now compiled by default to use the GMP large integer
1372
arithmetic library, speeding up arithmetic by a factor of 4 or more in
1373
many cases. This slightly changes the build process, affecting mainly
1374
packages with dynamically loaded modules (see
1375
http://www.gap-system.org/Download/ for GAP installation
1376
instructions).
1377
1378
 The GAP documentation has been converted to the GAPDoc format and
1379
extensively reviewed. Now it has only two books: the Tutorial and the
1380
Reference Manual. The two other books, Extending GAP and Programming
1381
Tutorial became parts of the Reference Manual. Packages that refer to
1382
parts of the GAP documentation may need to rebuild their manuals to
1383
update references.
1384
1385
Some packages still use the old gapmacro format for their manuals, for
1386
which support may be discontinued in the future. There is no urgent
1387
need to convert such manuals into the GAPDoc format before GAP 4.5
1388
release, but we encourage you very much to consider doing this at some
1389
later point.
1390
1391
 The old concept of an autoloaded package has been integrated with the
1392
needed and suggested mechanism that already exists between packages.
1393
GAP itself now needs certain packages (for instance GAPDoc) and
1394
suggests others (typically the packages that were autoloaded). The
1395
decisions which packages GAP should need or suggest are made by
1396
developers based on technical criteria. They can be easily overridden
1397
by a user using the new gap.ini (see 'Reference: The gap.ini and gaprc
1398
files'). The default file ensures that all previously autoloaded
1399
packages are still loaded if present.
1400
1401
 Optional ~/.gap directory for user's customisations which may contain
1402
e.g. locally installed packages (see 'Reference: GAP Root
1403
Directories'). If package installation instructions explain how to
1404
install the package in a non-standard location, they may need an
1405
update. This is intended to replace .gaprc files, but those are still
1406
supported for backwards compatibility (see 'Reference: The former
1407
.gaprc file').
1408
1409
 Various improvements in the packages loading mechanism make it more
1410
informative, while avoiding confusing the user with warning and error
1411
messages for packages they didn't know they were loading. For example,
1412
many messages are stored but not displayed using the function
1413
LogPackageLoadingMessage (Reference: LogPackageLoadingMessage) and
1414
there is a function DisplayPackageLoadingLog (Reference:
1415
DisplayPackageLoadingLog) to show log messages that occur during
1416
package loading. Packages are encouraged to use these mechanisms to
1417
report problems in loading (e.g. binaries not compiled), rather than
1418
printing messages directly.
1419
1420
 Since GAP 4.5 a package may place global variables into a local
1421
namespace as explained in 'Reference: Namespaces for GAP packages' in
1422
order to avoid name clashes and preserve compatibility.
1423
1424
 In GAP 4.5 the internal representation of a record has changed, as
1425
well as some of the basic functions to manipulate records. This speeds
1426
up considerably the creation of and access to records with many
1427
components. Record components are now internally stored in the order
1428
in which they were used first, and this means that the internal
1429
ordering of components (returned by RecNames (Reference: RecNames) and
1430
so the ordering of records, depends on the GAP session. Therefore,
1431
within each session everything is consistent, so one can efficiently
1432
remove duplicates with Set (Reference: Set), sort lists of records,
1433
find records with binary search, etc., but a care should be taken not
1434
to rely on RecNames (Reference: RecNames) always returning names of
1435
components in the same order.
1436
1437
1438
A.20 Checklists
1439
1440
1441
A.20-1 Package release checklist
1442
1443
The following checklist may be used by package authors, members of the GAP
1444
team responsible for package updates, package editors and referees.
1445
1446
 Test that the package:
1447
1448
 does not break testinstall.g and testall.g and does not slow
1449
them down noticeably (see A.14-4);
1450
1451
 may be loaded in various configurations (see A.14-2);
1452
1453
 follows the guidelines of Section A.6 about names of functions
1454
and variables;
1455
1456
 Package documentation:
1457
1458
 is built and included in the package archive together with its
1459
source files;
1460
1461
 states the version, release date and package authors;
1462
1463
 has the same version, release date and package authors details
1464
as stated in the PackageInfo.g file;
1465
1466
 is searchable using the GAP help system;
1467
1468
 is clear about the license under which the package is
1469
distributed;
1470
1471
 PackageInfo.g file:
1472
1473
 has the same version, release date and package authors details
1474
as stated in the package manual;
1475
1476
 has all mandatory components and also optional components where
1477
appropriate;
1478
1479
 in particular, contains hints to distinguish binary and text
1480
files in case of non-standard file names and extensions;
1481
1482
 is validated using ValidatePackageInfo (Reference:
1483
ValidatePackageInfo);
1484
1485
 Package archive(s):
1486
1487
 have correct permisisons for all files and directories after
1488
their unpacking (755 for directories and executables, if any;
1489
644 for other files);
1490
1491
 contain files with correct line breaks for the given format (see
1492
A.17);
1493
1494
 contain no hidden system files and directories that are not
1495
supposed to be included in the package, e.g. .cvsignore, .git
1496
etc.;
1497
1498
 Package availability:
1499
1500
 not only the package archive(s), but also the PackageInfo.g and
1501
README files are available online;
1502
1503
 the URL of the PackageInfo.g file is validated using the online
1504
tool available from
1505
http://www.gap-system.org/Packages/Authors/authors.html;
1506
1507
1508
A.20-2 Checklist for package upgrade to work with GAP 4.5
1509
1510
The following checklist will help you to check how well your package is
1511
ready to work with GAP 4.5.
1512
1513
 Mandatory changes needed for package upgrade to work with GAP 4.5:
1514
1515

1516
Check that the package works as expected:
1517

1518
 verify that the package functionality works as required,
1519
that examples in the manual are correct and that test
1520
files show no discrepancies;
1521
1522
 if necessary, update manual examples and test files
1523
because the order in which record components are printed
1524
has changed (but now it will be more consistent and less
1525
dependent on how the record was created);
1526
1527
 check the usage of names of record components in the code:
1528
take care not to rely on RecNames (Reference: RecNames)
1529
always returning names of components in the same order
1530
(see A.19)
1531
1532

1533
Revise package dependencies:
1534

1535
Check the the PackageInfo.g has the correct list of needed and
1536
suggested packages (see A.7).
1537
1538

1539
Revise licensing information:
1540

1541
Check that the package states clearly under which conditions it
1542
is distributed (see A.16).
1543
1544

1545
Rebuild the package documentation:
1546

1547
whenever your package documentation is GAPDoc or
1548
gapmacro.tex-based, GAP 4.5 contains new versions of both tools.
1549
This will ensure that cross-references from the package manual
1550
to the main GAP manuals are correct and that the GAP help system
1551
will be able to navigate to the more precise location in the
1552
package manual. This will also improve the layout of the package
1553
documentation. In particular, GAPDoc has a better .css file and
1554
is capable of producing the HTML version with MathJax support to
1555
display nicely mathematical formulae.
1556
1557
Note that it's not possible for a package to have an HTML manual
1558
which contains correct links to both GAP 4.4 and GAP 4.5 main
1559
manuals.
1560
1561
 Optional changes recommended for package upgrade to work with GAP 4.5:
1562
1563
 When the AvailabilityTest component in PackageInfo.g differs
1564
from ReturnTrue (Reference: ReturnTrue), use
1565
LogPackageLoadingMessage (Reference: LogPackageLoadingMessage)
1566
to store a message which may be viewed later with
1567
DisplayPackageLoadingLog (Reference: DisplayPackageLoadingLog)
1568
instead of calling Print or Info directly (see A.10-2).
1569
1570
 It is recommended not to call LoadPackage (Reference:
1571
LoadPackage) from a package file while this file is read:
1572
instead one should list the package in question in the lists of
1573
needed or suggested packages. To verify whether such calls occur
1574
in the package first load it and then call
1575
DisplayPackageLoadingLog( PACKAGE_WARNING );. If there is a
1576
genuine need to decide whether some package will be available at
1577
runtime, use the function IsPackageMarkedForLoading (Reference:
1578
IsPackageMarkedForLoading) introduced in GAP 4.5.
1579
1580
 Check if the package still relies on some obsolete variables
1581
(see 'Reference: Replaced and Removed Command Names') and try to
1582
get rid of their usage.
1583
1584
1585