where to put a non-python file, so it can be accessed at runtime

53 views
Skip to first unread message

Martin R

unread,
Apr 3, 2026, 4:01:11 PM (7 days ago) Apr 3
to sage-devel
In https://github.com/sagemath/sage/pull/41901 I have finally succeeded to put together a sensible FriCAS interface.  I admit that I am quite proud of it.

To make it work, I need one extra file which contains "spad" code, i.e., code in FrICAS native language, which should be compiled when the interface is first invoked.  It is about 70 lines of code and takes a millisecond to compile.

I do not want to precompile this with the rest of sage, because one may want to use a separate install of FriCAS, and that one might change.

How can I achieve this?

The only idea I had so far is to put it into a string, write the string into a temporary file, and compile that.

Best wishes,

Martin

Michael Orlitzky

unread,
Apr 3, 2026, 6:04:06 PM (7 days ago) Apr 3
to 'Martin R' via sage-devel
On 2026-04-03 13:01:11, 'Martin R' via sage-devel wrote:
> In https://github.com/sagemath/sage/pull/41901 I have finally succeeded to
> put together a sensible FriCAS interface. I admit that I am quite proud of
> it.
>
> To make it work, I need one extra file which contains "spad" code, i.e.,
> code in FrICAS native language, which should be compiled when the interface
> is first invoked. It is about 70 lines of code and takes a millisecond to
> compile.

There is an example in sage/graphs/generators/distance_regular.pyx
where we find and load

shortened_000_111_extended_binary_Golay_code_graph.pickle.xz

at runtime. The data file sits somewhere in the source tree and is
installed by meson using install_sources. Then at runtime you find it
using

from importlib.resources import as_file, files
with as_file(files('sage.foo.bar').joinpath("your-file")) as f:
do_stuff_with(f)
...

If you need to store the compiled result somewhere, $DOT_SAGE/fricas?
We do something similar with the GAP workspace in $DOT_SAGE/gap.

Martin R

unread,
Apr 4, 2026, 3:27:45 AM (7 days ago) Apr 4
to sage-devel
Thank you, that worked!

Martin R

unread,
Apr 4, 2026, 3:29:51 AM (7 days ago) Apr 4
to sage-devel
could someone please test this on MacOS and MS Windows, and perhaps using the sage install of fricas?


(it won't be tested by the CI, because it requires fricas)
Reply all
Reply to author
Forward
0 new messages