New question on Julia related forum:
What are the steps to create your own package in Julia?
I am not a package developer but I think something that’s important in the Julia ecosystem is the use of Project.toml
and Manifest.toml
files that define an environment. It took me a very long time to understand how environments work in Julia so it might be worth your while to understand it well.
Second, is the use of multithreading and distributed parallel computing. Likely your code wont use distributed computing (i.e. addprocs
, pmap
, spawn
and family of functions), but likely can use multithreading to speed up code. What happens when the user tries to run your function across many threads and your function itself is also using threads. There was a great video on how this “nested” parallelism works, but I can’t seem to find it right now
There are two very convenient tools for that:
- setting files up via GitHub - invenia/PkgTemplates.jl: Create new Julia packages, the easy way
- registration via JuliaHub
What does new package needs to provide in order to be officially accepted?
How to use existing packages while building your own new package?
The General Registry is not a curated list, so there is minimal moderation. There are some automatic tests your code has to pass. These include checking the version, name, dependencies are all according to the guidelines and it builds and runs.
Your package should have a Project.toml
file and that file should have a dependency section where you specify which existing packages you are using. 10. Project.toml and Manifest.toml · Pkg.jl
In addition to those minimal tests, there is also a default waiting period of 3 days. After you register your package (and a PR is submitted to JuliaRegistries/General), you have to wait that much for your package to be automatically merged.
Have you checked the relevant section of the manual?
Please do not double-post (cf Has anyone used Yao.jl for creating their own Julia package?).
Also, it is unclear if you want this question answered, or if you are just plugging that forum (which doesn’t appear to have a lot of activity for Julia, and may not be the ideal venue for Julia-specific questions).
I want the answer to question.
Yes, I have. But it’s kind of generic post.
If 1 hour is too much and 4 minutes is too little, you can do it in 10 minutes too:
Thanks. I’ll read it and let you know my feedback.
A lot of the answers here and elsewhere concern building a package from scratch. In my case, I have basically built a beta of my package and uploaded it to Github. However, the package has none of the “structure” of a package (e.g. the .toml
files and package metadata), and I would like to create these files and add my existing code to the package registry without creating a new Github repository, if possible.
How can I “convert” an existing project into a registered package while working within the same Github repository?
Specifically, what I currently have in the root directory is a main Foo.jl
file that defines a bunch of functions, a readme.md
, and a bunch of example code and graphs in subdirectories.
Something along these lines should work:
- Create a
src/
folder. Move yourFoo.jl
there. (Note that the name of this file fixes the package name to “Foo”.). - Make sure that the
Foo.jl
file defines a moduleFoo
and exports all the functions that your package should export. - In the root of your repo, start
julia --project=.
and] add SomePackages
all the dependencies of your package. This will create aProject.toml
andManifest.toml
. As a starting point,] add
all the packages that you areusing
in yourFoo.jl
. - Edit the top of the
Project.toml
to specify a version etc., see here for an example. - Add the
Manifest.toml
to your.gitignore
file. (In contrast to a project, for a package you don’t want to commit theManifest.toml
.) - Create a
LICENSE
file. (For example something like this)
That’s the “mandatory” part. You should now have a valid package. But of course you should also add tests in a test/runtests.jl
and documentation etc. For your example code (i.e. scripts) you could create a examples/
subdirectory which you make a project by (within this directory) starting Julia as julia --project=.
and adding the dependencies via ] add
(your scripts may depend on more packages than those required for “Foo” to work). Here, you keep both TOML files such that a user can ] instantiate
the precise versions of all packages that you used when creating you examples.
Hope this helps. (I might have forgotten 1 or 2 things but people will probably point this out )
Although it is somewhat directed to scientific projects, I found DrWatson.jl to be quite useful for package development.
Thank you!
When adding dependencies, should I list just those that are needed for the module’s core functionality, or any that are used anywhere in the project? For instance, in several of my example files I use Plots
.
Or is there a way to annotate these different degrees of dependency?
Edit: Also, how do I add the module to my own Julia path before it has been registered?
Just the ones needed for the module’s core functionality. In the examples
folder of my packages I have another environment (this is, another Project.toml
and Manifest.toml
) with all the packages needed by the examples themselves.
This is important for creating the environment (i.e., .toml
files) of the examples
folder, as often your examples will depend on your package. What I do is to:
julia> import Pkg
julia> Pkg.activate(".")
julia> Pkg.dev("..")
inside the examples
folder. So you are saying to your examples that they depend on the package which they are themselves inside.
But you must not copy the uuid
from somewhere else. Create a new one with
using UUIDs
uuid4()
I recently wrote a guide A to Z to package development… this should answer the questions in this thread: 11 - Developing Julia packages - Julia language: a concise tutorial
It is not the only way to create and publish a package, but it works