Get version from info.rkt

hello,

i have an info.rkt file in my package, that contains the version number, how can i retrieve it from my code?.

#lang info
....
(define version "10.3")
.....

i can require the info.rkt file but the definition are not available when i do that:

i only get the version procedure of Racket that return the version of racket (8.14 here)

Regards,

Damien

See API for reading info.rkt files β€” you probably want to use the procedure returned by get-info for your collection:

(require setup/getinfo)

(define info-getter (get-info '("my-collection"))) ; note collection, not package name!

(cond
  [(procedure? info-getter) (info-getter 'version)]
  [else info-getter])

This will result in "1.0" (e.g.) if all goes well, or #f if the info.rkt could not be found, or an exception if it is found but version isn’t defined in it.

1 Like

thank, this worked exactly.

(require setup/getinfo)
(define info-getter (get-info '("Scheme+")))
(cond ((procedure? info-getter) (info-getter 'version)) (else info-getter))
"10.3"

See also the technique for doing it at compile time: https://github.com/benknoble/frosthaven-manager/blob/8c69323bddc1b7b5c576d1fe42a446b91ab408d3/gui/common-menu.rkt#L30, where https://github.com/benknoble/frosthaven-manager/commit/acf849311ecc4d5247b71e64e1370fbf4ebceafc might look right but exhibits some subtle problems (see https://github.com/benknoble/frosthaven-manager/commit/deae4ac544ef0b7be09a9cd11001e54a4609de21).

2 Likes

if i understand (?) the advantage of your solution, and i only use version number to display as info (not critical in code), and as my releases are spaced by months generally, the actual solution should be enough to have version number , not hard coded in text string but retrieved from info.rkt file.
thank.

The advantage of @benknoble's solution is that, for some ways of building an executable, the info.rkt file might not actually be present at runtime. Doing the lookup at compile time makes that work seamlessly.

Another caveat is that, if you have a multi-collection package, the package info.rkt file is not part of any collection. (In a single-collection package, the package info.rkt file is also a collection info.rkt file.) The APIs are there to find such a file, too, it just has to be done differently.

This all reminds me that I've wished for something like PLaneT's (this-package-version) for non-PLaneT packages, particularly to use as the #:version argument to @title{}. To be useful, it should probably allow providing a package name or a module path to look up, since documentation is often in a different package with an irrelevant version number.

1 Like

thank you for the explanation. I think it could take sense in one of two release of my Scheme+ and SRFI-105 because at some point i will made a lot of the job from Scheme+ to SRFI-105 reader and i will melt the 2 projects (collection/package) in a single one (package with perheaps 2 collections) and the 2 info.rkt will be only one (and only one common version number at this time) but will be in a place in the package at an upper level than the collection place where info.rkt files are now.

note about API doc: i had read the doc before posting but can not figure out how to make the code, some examples like this would be useful for user to understand the APIs