Julia, New Package, Github and VSCode

I have several projects I was looking at porting to Julia. I needed to understand how to properly create a new Package and publish it to GitHub and code from Codium.

I read all I could find. I read all the tutorials I could find. It was all doable and semi-reproducable but still wasn’t what I was looking for. It was still go to GitHub website and create a repo. Create a Julia Package with Pkg or PkgTemplates. Mess with remotes, deal with histories, merges, etc. All for brand new code on both ends. It seemed there had to be something easier.

I can understand the above when dealing with existing code on one or both ends. But when starting clean, there should be a clean and simple way.

I searched this forum to find what I am about to say to see if it was already there. I did not find it so I want to share the manner in which I have found to most simply, cleanly create a new Package and GitHub Repository. There may be similar for other repositories, but alas, I do not know.

open Terminal

name@compname: ~
$ cd .julia/dev

$ julia # open julia in terminal

Create package in Julia with PkgTemplates

julia> using PkgTemplates
julia> t = Template()
julia> t("NameOfPackage")
julia> using Pkg
julia> Pkg.upgrade_manifest()
julia> ;
shell> cd NameOfPackage
shell> rm -rf .git #This removes all .git PkgTemplates created.
shell> codium -n .
shell> Ctrl-D #exit Julia, to start fresh on other side.

Codium
	Source Control
		Publish to GitHub
			make sure to add the ".jl" to the package URL 

start coding

open Terminal that we were using

$ cd NameOfPackage
$ julia
julia> ]
(v1.9) pkg> activate .    #change environment
(NameOfPackage) pkg> hit Backspace key #in new environment
(NameOfPackage) julia>  #explore, experiment

To those who are Julia pros, this may or may not be easier than your currently established rhythms. I was looking for mine. And this is it. I just wanted to share, hoping it could make someone else’s journey a bit easier.

Jimmie

7 Likes

If you want to create a new package, this should work just fine:

$ julia
julia> using Revise
julia> ]
(v1.9) pkg> generate NameOfPackage.jl
(v1.9) pkg> activate NameOfPackage.jl
(NameOfPackage) pkg> hit Backspace key #in new environment
(NameOfPackage) julia>  using NameOfPackage

This creates a new package with the proper file structure and initializes a Project.toml

You can pass !Git() in your template to skip this stuff, but

This must generate a new .git directory, so I’m not certain why you need the previous step. Where are you running into merge conflicts? Does source control make the GitHub repo for you? If you’re making it manually, be sure not to initialize it with a README or LICENSE.

You can do `t(“NameOfPackage.jl”) here, and skip the rename also

1 Like

Most of these steps match what I’d do, but there is definitely some extra. You shouldn’t have to quit or of Julia for example - I thought PkgTemplates switches to and activates the new package, but even if not, you can use shell mode to cd, or cd("NameOfPackage.jl").

When I’m at a computer today, I’ll try to demo the way I do this…

@kevbonham Thanks for the reply.

Yes. If you remove all of the current .git folder which was created with PkgTemplates, the VS Code (Codium) will with the Publish to GitHub button, generate the repository on GitHub. Every tutorial and everything I read has multiple steps.

t = Template()
t("PackageName")

Then go to GitHub website. Create the repo and associated docs.

Then return to terminal and do all kinds of commandline git commands to link the current .git folder with the newly created GitHub repo. Then reconcile the two branches. Via whatever commands necessary.

If you simply delete the local .git folder. Then VS Code (Codium) creates the repo on GitHub and automatically sets the remote. And no reconciliation of any kind is necessary.

I find it easier to understand and simpler to do, than all the other required machinations. If, you are starting clean all the way around. New local project, new GitHub repo.

I have read and done all on this page.

11 - Developing Julia packages

If had existing code. I would do this. But in this case I don’t and all is new.