How to start writing a new Julia package?

@andreasnoack: OK. Thanks. I have a quick question. I am writing a Julia package for a stat method that we developed. Is there a good documentation/package to teach writing the package and share it? Thanks.

2 Likes

@andreasnoack: I wonder if there is a Julia package to help developers to write new Julia package of their own to share. Thanks.

Pkg.add("PkgDev")
using PkgDev
PkgDev.generate("PackageName","MIT")

Turning that into a full package:

(slightly old, but mostly minor syntax changes like Pkg → PkgDev)

9 Likes

Thanks. Is this the most common way that people currently follow to develop .jl package? Thanks.

Yup. If you look around, you’ll see that they all have the same high-level file structure, CI (Travis and AppVeyor), documentation (Documenter.jl), and code coverage reporting. This post shows you the most standard way to enable all of those.

@ChrisRackauckas: Great. Thanks a lot.

@ChrisRackauckas: I already have a Github account. Do I need to do the following step in git shell to set up for package?

git config --global user.name "FULL NAME" git config --global user.email “EMAIL”
$ git config --global github.user “USERNAME”

Julia will pull environmental variables these in order to generate your package to be setup with a remote to your Github account.

Though my recommendation these days is to try GitKraken. It’s a GUI for Git. If you open it up, you can just sign in with your Github account and it’ll actually set this up. (After that, it’s a really good GUI for managing Git workflows).

@ChrisRackauckas: I use Windows application for GitHub to communicate to my Github account. Can I instead manually create a repo in GitHub, clone it to my computer, and do Pkg.generate() within that folder?

No, I believe it needs the folder to not exist yet. A good way to do this instead is:

  1. Create a blank repo with the right name on Github (needs the .jl)
  2. PkgDev.generate the folder
  3. push it to origin (it’ll be setup with your remote)

That should initialize the repo and give you a blank Julia package.

@ChrisRackauckas: Does PkgDev.generate() generates files in .\pkgs-0.5.1.1\v0.5\pkgName? Is that where we want to save the generated files?
Thanks.

Yes. Well, it’ll be in .julia\v0.5\PkgName. This is the load path Julia uses, so after that using PkgName will work.

(You’ll notice that all of the folders in there are actually git repos)

@ChrisRackauckas: Yes, they are all Git repos. Now, how do I easily push this folder to the Github repo that I created with the same PkgName.jl?

Another quick question. So, my package name is sAUC.jl. Is this name accepted in Julia community as package name? I
Thanks.

If you setup the environment variables before, it should already have origin set to your username/package name, in which case you just push origin. If not, you may need to set a remote for it. (Again, GitKraken is easiest for this if you aren’t comfortable with CLI Git)

http://docs.julialang.org/en/release-0.5/manual/packages/#guidelines-for-naming-a-package

I have no idea what that standards for, so that’s probably a sign that the answer is no.

@ChrisRackauckas : Thanks. sAUC stands for semi-parametric Area Under the Curve (sAUC). Thanks.

@ChrisRackauckas: Maybe, I may want to call it SemiparametricAUC. How do we handle uppercase abbreviations in package name?
thanks.

You might want to open up an issue here to talk about naming before you get set on one.

https://github.com/JuliaLang/METADATA.jl/issues

Usually this stuff comes up when someone is registering the package for the first time, but opening an issue and getting it squared away for is probably a better idea.

@ChrisRackauckas: Can you explain this install mkdocs step a bit more? Finalizing Your Julia Package: Documentation, Testing, Coverage, and Publishing - Stochastic Lifestyle

Oh, that’s a little old now. Instead I’d recommend doing the mkdocs-free version. It’s described here. Everything is the same except the make.jl file and the way you setup the hosting (but it’s very similar)

https://juliadocs.github.io/Documenter.jl/latest/man/hosting.html

2 Likes

Sorry, what do you mean by “mkdocs-free version” here?