Determine whether a project has been instantiated

Is it possible to determine whether a given folder containing a Julia project has been instantiated? The folder is unrelated to the julia process where I want to do this, i.e., I’m not trying to figure out whether the current project has been instantiated, but some other project in some arbitrary folder.

This is in the context of finding a project root for LanguageServer. I’ve been using the existence of a Manifest.toml or JuliaManifest.toml file as a proxy. One problem with that is that this doesn’t actually guarantee that the Pkg.instantiate() has been run. It’s only a good proxy because I typically don’t commit Manifest.toml, so these files only exist after instantiation.

Even if I’m happy to use the existence of manifest files as a relevant proxy, we now also have version-dependent manifests. So I’m not quite sure about all the filenames I would have to check (is JuliaManifest-v1.11.toml supported?).

So, any recommendations for what might be the easist way to determine whether some given folder has been instantiated or not?

1 Like

When you say instantiated you also want to know whether every dependency has been precompiled? Or what is the point?

Either way I think the correct way is using functionality from Pkg.jl and I think it shouldn’t be too hard… if one knows how to do it :sweat_smile:
I think I would read the code of Pkg.instantiate() and all the necessary logic should be in there.

1 Like

There isn’t anything off the shelf & public that I’m aware of, but this works with some internals

julia> import Pkg

julia> env = Pkg.Types.EnvCache("/Users/ian/.julia/environments/v1.11/Project.toml");

julia> Pkg.Operations.is_instantiated(env)
true

julia> all(name_uuid -> Base.isprecompiled(Base.PkgId(name_uuid[2], name_uuid[1])), env.project.deps)
false

The latter being if all Project deps are precompiled.

5 Likes

My understanding is that LanguageServer requires that the project-folder has been instantiated, so that it can analyze all the packages in the environment. So the point is precisely that: to determine whether a given folder is suitable as a project-folder for LanguageServer. I’m not sure what that implies about whether packages have to be precompiled.

I might at some point go further in my wrapper script to say “if the project folder isn’t instantiated yet, run a subprocess with Pkg.instantiate to make sure that it is”. But we’ll see.

2 Likes

It would seem to me that if there are a Project.toml and a Manifest.toml in the folder, it 's instantiated. I don’t see how one creates these files without

instantiate .

Instantiate also check packages are downloaded to .julia/packages and necessary artifacts to .julia/artifacts. And possibly then precompiles the former.

You could commit the manifest, but then when you clone the repo, you still have to re-instantiate it (for LanguageServer to work, I think). If the manifest wasn’t committed, the yeah, the only issue would be reliably figuring out the name of the manifest file, which isn’t as simple as it used to be.