Suggestion violates cauality

Anyone seen this before:

ERROR: LoadError: ArgumentError: Package Pkg not found in current path:
- Run `import Pkg; Pkg.add("Pkg")` to install the Pkg package.

Any ideas what I might have done to cause it?

I’m using a custom workspace because I’m relying on a change to NativeSVG that hasn’t been promoted yet and because of some trouble I had with matching compatible versions of UnitfulCurrency with Unitful.

My code can be found at

My only local change from GitHub is to use an absolute path in the Pkg.activate call at the beginning of test/runtests.jl.

Also, any advice about a more streamlined way to test my package would be appreciated.

Thanks.

4 Likes

A similar problem is discussed in this topic Problem with Pkg: cannot be found in current path.

Thanks. Unfortunately, I have no clue what the value of LOAD_PATH is when the error occurs since it happens during Pkg.test:

using Pkg
Pkg.activate("c:/Users/Mark Nahabedian/.julia/dev/PanelCutting")
  Activating environment at `c:\Users\Mark Nahabedian\.julia\dev\PanelCutting\Project.toml`
using PanelCutting
LOAD_PATH
3-element Vector{String}:
 "@"
 "@v#.#"
 "@stdlib"
Pkg.test("PanelCutting")
     Testing PanelCutting
      Status `C:\Users\Mark Nahabedian\AppData\Local\Temp\jl_RWQoyO\Project.toml`
...
33 dependencies successfully precompiled in 86 seconds (94 already precompiled)
     Testing Running tests...
ERROR: LoadError: ArgumentError: Package Pkg not found in current path:
- Run `import Pkg; Pkg.add("Pkg")` to install the Pkg package.

(sorry for the lack of prompts and other boiler plate. I’m running from an emacs shell and prompts, etc. don’t seem to get displayed).

Unfortunately the temporary workspace directory that gets constructed for the test gets deleted before I can examine it.

Am I correct in assuming that Pkg.test (or maybe Test.runtests) starts a separate process for testing?

I’m not entirely sure what you’re doing here, but you shouldn’t need to activate in your tests. Instead, get the package manager itself to handle that using one of the two methods listed here: Creating Packages: Adding tests to the package.

Note that when you load a package it has a slightly more restrictive view of the world than when you are working with it interactively. Thus, yes, if a package uses Pkg you need to add Pkg to its project. This error message when this happens is different than what you’re seeing, though, so I’m not fully sure… But regardless I think this is a bit of a red herring — I’d try to avoid using Pkg.activate in the first place.

Thans for referring me to that description of the pre and post Julia 1.2 ways of describing test dependencies.

I’m using julia version 1.6.0.

I’m going with the pre-1.2 single Project.toml approach for now. This got all of my tests to pass.

I stilll have some questions though:

In the post Julia 1.2 structure, how can one ensure that the test workspace is using the same package versions as the package being tested?

In the pre Julia 1.2 structue, why do I need to duplicate dependencies from the deps section of my package’s Project.toml file in the extras section of that file? To my mind the word “extra” suggests that it is for dependencies beyond those of the package itself.

Also, is there a way to run my package’s tests without activating my package’s workspace first? When I don’t it complaiins

ERROR: LoadError: LoadError: ArgumentError: Package PanelCutting does not have Markdown in its dependencies

but Mardown is listed as a dependency in my Project.toml file.