Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
330 stars 226 forks source link

loadPackage fails for hard to determine reason #3308

Open mikestillman opened 2 weeks ago

mikestillman commented 2 weeks ago

Sometimes, calling loadPackage can fail, saying it cannot be reloaded.

This error occurred in a set of packages I wrote a few years ago. I have boiled it down to its essence:

In A.m2, place the code

newPackage("A", Headline => "A")

In B.m2, place the code

needsPackage "A"
newPackage("B", Headline => "B")

Now after creating these files, try the following code.

elapsedTime installPackage "A"
elapsedTime installPackage "B"
restart
loadPackage "A"

This last line fails, since the package ''A" has been loaded when "B" is being scanned for its newPackage code (I think), and so has already been loaded. This is very hard to determine, as any installed package could do this and cause the package to simply be loaded already... Using needsPackage works fine.

Also, the time to install the package "A" seems to take 4-5 seconds on my machine, which seems quite large. (Same with "B").

mahrud commented 1 week ago

I've heard of this complaint from a lot of people, and the answer has always been

¯\_(ツ)_/¯ yeah loadPackage is weird, just add Reload => true or use needsPackage!

I'd be in favor of ditching loadsPackage (or making it a synonym of needsPackage), but the trouble is that it's hard to getneedsPackage` to reload a local copy of a package (e.g. a modified copy in the same directory) if a distributed version already exists on the system. This is related to the same issue I described in https://github.com/Macaulay2/M2/issues/3307#issuecomment-2171790406.