I am trying to add dependencies to a package that I am developing, but I get the following error:
(HijriConverter) pkg> add Parameters
Updating registry at `~/.julia/registries/General.toml`
Resolving package versions...
ERROR: expected the file `src/HijriConverter.jl` to exist for package `HijriConverter` at `/home/jafar_isbarov/Documents/projects/hijri/hijri-converter-julia-package/HijriConverter.jl`
Adding a file named HijriConverter
to the src
folder does solve the problem. I have two questions.
(1) Why do I need a file with the same name as the package? Is it supposed to have certain content?
(2) If I add that file, add dependencies, and delete the file afterwards, will that cause any problems?
Thanks.
Because that is the required package structure. It is supposed to have
module HijiriConverter
# package code here
end
in it
1 Like
But HijriConverter is a reasonable name for the package, but not a reasonable one for any of the modules. Is it considered a bad practice to create this module and leave it empty? (FYI, I do have a module named “core”).
A package named “HijriConverter” needs to have a module with that name in order to function properly.
All the content of the package need to be within that module.
1 Like
I see, thanks. What if I want to distribute the package across multiple modules (as it is easily done with, say, Python)? Is there a way to do that? Pkg documentation is not really helpful in this case.
You can absolutely do that. I don’t think it’s quite as idiomatic as in Python (which, iiuc, has a module = file thing going on), but you can. Then you include
the file containing a module, and use import .Submodule
(the period denoting a local/relative module).
But the most common way to split code up is to simply include
the files, making them part of the main package module.
2 Likes
You typically have it like:
HijriConverter.jl
:
module HijriConverter
some_function(x) = ....
include("OtherModule.jl")
end
OtherModule.jl
:
module OtherModule
some_other_function(x) = ...
end
2 Likes