Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadPackage fails for hard to determine reason #3308

Open
mikestillman opened this issue Jun 16, 2024 · 3 comments
Open

loadPackage fails for hard to determine reason #3308

mikestillman opened this issue Jun 16, 2024 · 3 comments

Comments

@mikestillman
Copy link
Member

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
Copy link
Member

mahrud commented Jun 17, 2024

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 get needsPackage 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 #3307 (comment).

@mahrud
Copy link
Member

mahrud commented Aug 7, 2024

Here's a proposal:

Currently we have load and needs, and you can call either on the same file however many times, but the difference being that needs only calls load if the timestamp of the file newer than when it was last loaded. However, loadPackage and needsPackage don't have the same relationship. Perhaps we should deprecate Reload, have loadPackage always dismiss the package and reload it, and needsPackage should call loadPackage only if the location and/or timestamp (of the top package file, or any file therein also?) has changed.

(in particular, a local copy of a package in the current directory will have a different location, so needsPackage will reload it)

@mahrud
Copy link
Member

mahrud commented Aug 20, 2024

This was the suggestion in #3225, by the way. Any feedback or whether or not you agree with change would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants