How to start writing a new Julia package?

@ChrisRackauckas: When I ran my first test on the package, it failed. What could be a possible error for the tests to fail?
``
test\runtests.jl, in expression starting on line 5```

Where in line 5, I have @test 1 == 2

I guess the problem is that 1 is not equal to 2 :wink:

3 Likes

Oh, those docs use mkdocs? Might need to write an up to date tutorial for the native render. Essentially, you just define the documentation structure like here:

https://github.com/JuliaDiffEq/DiffEqDocs.jl/blob/master/docs/make.jl

That setup should build it without mkdocs.

Should open an issue to Documenter.jl to document the native render.

@giordano: Lol, yes it was. Thanks.

Look at the file test\runtests.jl. That’s where the tests go. You’ll notice that by default it makes the test @test 1==2 which will fail. You’ll want to replace that with your testing code.

Do I need to install this separately? Thanks.

Yes, if you go the mkdocs route. (I prefer the native HTML render route, but I guess it’s not documented yet? So do what you think is best. I think it’s just pip install mkdocs)

@ChrisRackauckas: So, this is a python package then??
Iis this where we refer to: http://www.mkdocs.org/ ?

@ChrisRackauckas: Another quick question. How do I store data (like .csv) within a package so that we use the data as sample for the test? Is there a standard practice?
Thanks.

@ChrisRackauckas: How do I clone my Github repo package to another computer? I have two-factor authentication enabled in Github. Using just Pkg.clone() did not work. Thanks.

Yes, mkdocs is. You can use the HTML render as explained above in order to not use mkdocs if you want though.

I think it’s quite common to make an examples folder in the top level for example datasets, Jupyter notebooks, etc.

If the repo is public, Pkg.clone("URL") should work even without authentication. You will only need to authenticate if the package is private. If that’s the case, then you will likely need to use the Git SSH protocol (use the SSH url).

It is a private repo. I tried to clone it using SSH as well, but did not work. Is there any special commands that I need? Thanks.

You need to make sure your Git is authenticated. I would recommend trying to do this directly from the Git CLI (or GitKraken) first. You might need to set up an SSH key? (Note when this is properly setup, Julia’s Pkg will work as well since Pkg just calls the Git CLI)

@ChrisRackauckas: Thanks. When I run the Pkg.test() on the cloned package, it throws an error saying “… is not an installed package”. Any advice to solve this? Thanks.

You need to add dependencies to your REQUIRE file. You’ll find that at the top level.

I have julia 0.5 in REQUIRE right now. Do I need any other dependencies? Thanks.

OK. I added other packages that my package is dependent on. But, it still says the same error. How do I locally install my package and run Pkg.test()

You need to Pkg.add the other packages locally. The REQUIRE file is used to get the dependencies, but only when you add your package the first time. Since you’re developing your package, you never cloned it with the packages in the REQUIRE, so it never triggered the downloading of the dependencies. However, from now on cloning it will get the deps.

Yes, I have installed all the packages needed for my package.Still the same problem.

When I generated package using Pkg.generate() in the first computer. The package was created in ~\v0.5 without the .jl extension on the package name and it worked fine on that computer. However, when I cloned the package from Github to another computer. I see my package folder has .jl extension on it. Is that how it should be?

Also, do I need to clone the package to ~\v0.5? Can I clone it to another location?
Thanks.

julia > Pkg.clone("https:\\...")