How to pack jl files into a local module?

Hi, all. I have several .jl files. I want to pack them into a local module and install it into my environment via pkg. How can I make it?

1 Like

There are some instructions on how to create a package in this documentation: 5. Creating Packages · Pkg.jl
For the more basic structure of a module that is the base of a package, you can read the Julia documentation: Modules · The Julia Language

if you mean you wan to create a package you can take a look at

1 Like

Start with creating a project:

julia -e "using Pkg; Pkg.generate("My_Project)")"
cd My_Project
julia

This will create a small directory tree, including a Project.toml in the first level, which is what keep tracks of dependencies. In the src directory will be My_Project.jl as a Hello, World. Edit this to bring in your .jl files, which should all be functions

using Pkg
Pkg.activate(@__DIR__)
Pkg.add("DataFrames")
using My_Project
check_julia_version()
add_dependencies()
display_readme()

Edit My_Project.jl

include("src/utils.jl")
# etc

utils.jl and each other should end with

export with_commas, with_percent # etc

Stay flat and bring everything into My_Project and avoid using macros in function definitions; reserve them for scripts. Otherwise, you will fall into circular dependency hell.

2 Likes