Dear Community,
I am currently restructuring some existing code, which is set up to be a package. When moving around some files into a (for me) logic new structure, I got entangled with problems related to Package directories. I think this question belongs in “New to Julia” because I am most interested in understanding why my approach does not work and good practices for setting up my code structure.
A minimal working example looks like this: I considered it sensible to implement the following package structure:
- MyPkg
- src
- pkg
- ‘MyPkg.jl’
- …
- examples
- …
- pkg
- Project.toml
- src
Hence, I wanted to create a subfolder pkg, which holds the module file with ‘MyPkg.jl’ to separate it from other code that is not necessarily invariant to user inputs.
The Project.toml file looks like this:
name = "MyPkg"
uuid = "d6f8d3e6-0b6f-11e9-4e3f-3b5f3d3f3b3e"
version = "0.1.0"
[deps]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
I included the dependency of Printf for no particular reason. The MyPkg.jl file just contains a very simple function hello().
module MyPkg
export hello
using Printf
function hello()
@printf "Hello, world! \n"
end
end # module
When I now try to use the package, by first running ] activate .
followed by ] instantiate
, I get the error ERROR: expected the file `src/MyPkg.jl` to exist for package `MyPkg` at `SomeDirectory\MyPkg`
.
If I delete the uuid and the version in the Project.toml file, I do not have any issue with the instantiate.
After reading a bit into The Manual regarding Code loading I understand that this should not work.
First, I am curious to understand why moving the ‘MyPkg.jl’ file with the module into a subfolder does not work and potentially is not supposed to work. Second, and conditional on “maybe it can/should work”, is there a way to get around this, or is this simply not desirable?
Thank you very much for helping me understand.
Files of the MWE are attached.
Project.toml (135 Bytes)
MyPkg.jl (107 Bytes)