This lesson is in the early stages of development (Alpha version)

Creating Packages

Overview

Teaching: 15 min
Exercises: 15 min
Questions
  • How to create a package?

Objectives
  • Learn setting up a project using modules.

  • Learn common package structure.

  • Learn to browse GitHub or juliahub for packages and find documentation.

Melissa is now confident that her module fine and she wants to make it available for the rest of her physics club. She decides to put it in a package. This way she can also locally use Julia’s package manager for managing her module.

From project to package

The path from having a module to having a package is actually very short: Packages need a name and a uuid field in their Project.toml.

A UUID is a universally unique identifier. Thankfully Julia comes with the UUIDs package, that can generate uuids for Melissa via UUIDs.uuid4().

In addition Melissa needs to have a specific directory structure. She looks at the example package Example.jl which has the following structure:

├── docs
│   ├── make.jl
│   ├── Project.toml
│   └── src
│       └── index.md
├── LICENSE.md
├── Project.toml
├── README.md
├── src
│   └── Example.jl
└── test
    └── runtests.jl

Make it a package

Open your Project.toml and add name = <your name>, uuid = <your uuid> and optionally an authors field, each on a separate line.

Now Melissa can use

pkg> dev . # or path to package instead of `.`

instead of needing to includet MelissasModule.jl, and she can write using MelissasModule instead of .using MelissasModule.

Register a package

In order for her friends to be able to get the package, Melissa registers the package in the general registry. This can be done either via JuliaHub or by making a pull request on GitHub which can also be automated by the Julia Registrator.

Creating a new package

Melissa thinks next time she will start with a package right away.

Browsing the packages she found PkgTemplates.jl and PkgSkeleton.jl which makes setting up the typical folder structure very easy.

Create your own package

Look at the documentation of the package creation helper packages and create a new package using generate.

Key Points

  • The general registry is hosted on GitHub.

  • Packaging is easy