I am wondering what’s best practice to locally test a pack with SWI. This is typically the way to go when you clone the repository of a pack locally and want to execute the included tests. In this case, use_module(library(my_pack)) does not work, since it’s missing the link in ~/.local/share/swi-prolog/pack/my_pack.
For instance, I am the maintainer of several packs, including tap. It comes with several tests. Once installed via ?- pack_install(tap), they can be executed as follows:
This adds the local prolog directory to the search path and worked in SWI-Prolog upto version 8.0.x. Since version 8.1, the asserta(user:file_search_path(library, 'prolog')) has no effect (maybe that’s a regression?). So what’s the preferred way to test a without further dependencies locally?
thank you for the quick response! Maybe you are right, though I’m not sure how to exactly use this predicate, since attach_packs/2 attaches all packages in the subdirectories. So given that I clone via git clone git@github.com:fnogatz/tap.git ~/Development/swipl-tap, I have to call ?- attach_packs('~/Development').. This leads to all packages being loaded from ~/Development instead of just ~/Development/swipl-tap. It looks like what I’m really looking for is attach_package/2. Maybe it’s worth to consider exporting this predicate from packs.pl, too? (And maybe another attach_package/1 with default options.)
Looks like you are right. Can you try and make a PR? I don’t think we really need an attach_package/1 as this doesn’t seem to be the most common thing to do.
I see. Using a $-name is not good I propose to add this as pack_attach/1,2 to library(prolog_pack). Do you want me to do so or do you want to make a PR?
Yeah, I see, I still was not able to get this working with the $-name in the Makefile (oh my gosh, what a hell of escape sequences! ). Would be nice to have this added to library(prolog_pack). I am not sure what’s the best way to add this without duplicating too much code from boot/packs.pl, so it would be nice if you could create the PR
Okay, there is just another problem I still face, even with the shiny new attach_pack/2: Where do I call attach_pack/2 to test a locally installed pack? Here’s my scenario with library(xsd):
library(xsd) comes with more than 1000 (!) tests which are executed via library(tap).
library(xsd) comes with a CLI to validate an XML Document against a given XML Schema. As part of its installation, we create the saved state qlf file cli.exe from library(xsd)'s cli.pl, using SWI-Prolog’s -c flag. The cli.pl calls :- use_module(library(xsd)). at some point.
As part of a CI workflow with GitHub Actions, I want to automatically run the tests defined via library(tap) as well as just call the created cli.exe with some example XML+XSD file to ensure it’s working correctly. These tests are defined in the project’s Makefile. I just uploaded my first try to get this working with GitHub Actions in the branch 16-migrate-to-github-actions. It locally installs SWI-Prolog v8.0 with the help of swivm, installs the dependent packs via pack_install(tap) and pack_install(regex). Our library(xsd), which is subject to be tested, is checked out locally. Now I face the problem that I can’t call ./cli.exe, because it relies on the locally installed library(xsd), so it fails with the error message source_sink library(xsd) does not exist.
My guess was to try to call absolute_file_name(pack('.'),D) (as suggested in this thread) first, then create a symbolic link via ln -s $(pwd) $(swipl -q -g "absolute_file_name(pack('.'),D),writeln(D)" -t 'halt(1)'), and run the test thereafter. However, GitHub’s CI infrastructure apparently comes without a ~/lib directory, so ?- absolute_file_name(pack('.'),D) just returns false
@jan, any idea how I could solve this? I try to avoid changing the code of :- use_module(library(xsd)) in cli.pl and hope to get SWI-Prolog to just find the correct path to the module.
Its a bit hard to see all the details. One tip may help. attach_packs/0 as called on startup attaches the pack subdirs for all solutions for the pack(.) directories. So, you can start Prolog as `swipl -p pack=somedir …, where somedir is the parent dir of the packs you want to have access to. Does that help?