Is package a library?

I am new to Julia, and I wonder what a package is.

I am quite familiar with Rust. In Rust, a crate can either be a library or an executable. As far as I read, the examples interpreting what package is are all about libraries, which another file can re-use the code in this package.

So if I just want to make a project for myself to use (which is much like an executable, but in interpreting languages, I can’t come up with a good name) rather than a library for others to use, should I make this project a package?

I know I can just use julia xxx.jl to run a Julia file, but I prefer Project.toml and Manifest.toml to make it more re-productable.

1 Like

as you already know Project.toml and Manifest.toml gives you reproducibility. You’re totally free to make your own utility package, just create a pkg at somewhere and ]dev path_to_your_pkg and then you can just using MyPkg like normal.

Note that julia --project=/path/to/project script.jl will run the package in a specific project.
If you are not developing a package, you can just activate that project in the REPL and add the packages you need.

1 Like

Does this mean that “package” is more of a utility, and the main() function of my project is encouraged to write in a plain file that uses that package?

I would just put it all in one module and have the module export the function main(). But yes, in general a “project” that isn’t intended to be used by others should still look like the packages you see on github, imo.

I want to avoid using REPL since the code may develop in many days but codes in REPL can’t persist.

julia --project=/path/to/project script.jl

I can’t quite understand which is what in this command. To be more specific, I have a Julia file

import PackageA
import PackageB

function utility()
# ...
end

function main_logic()
# ...
end

which part should I put into /path/to/project and which part should be put into script.jl?

path/to/project is where your Project.toml and Manifest.toml is at, since you already have a project for that.

In this specific case, you could create a script.jl:

include(“utility file”)
main_logic() # or move the body of main_logic here

since everything in a julia file is executed. In contrast, only main is executed in C.

If you are interested, VideoIO.jl contains an executable independent of the main package.

I like to think to a julia package as a software “piece” (in Julia, a module) plus the metadata to facilitate its discovering and interation with other software “pieces” (the Project.toml and Manifest.toml) and a conventional structure to facilitate its testing and documentation.