Convert project code to a package (and maintain git commit history)

I have some code in a project directory that is being tracked by git. The project directory looks like this:

MyProj/
├── .gitignore
├── .git
│   └── # .git folder
├── Manifest.toml
├── Project.toml
├── examples
│   ├── example1.jl
│   └── example2.jl
├── run
│   ├── run1.jl
│   └── run2.jl
└── src
    ├── code1.jl
    └── code2.jl

The Project.toml file looks like this:

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DecisionTree = "7806a523-6efd-50cb-b5f6-3fa6f1930dbb"
LIBSVM = "b1bec4e5-fd48-53fe-b0cb-9723c09d164b"
MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7"
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
MLJLinearModels = "6ee0df7b-362f-4a72-a706-9e79364fb692"
MLJModels = "d491faf4-2d78-11e9-2867-c94bc002c0b7"
XGBoost = "009559a3-9522-5dbb-924b-0b6ed2b22bb9"

What would be the most robust way to turn this project into a package? Of course I want to maintain my git history by continuing to use the same git repository.

I could be wrong but I’m first so that makes it ok.

I think you just need to create a MyProj.jl file under src which defines a Module of the same name. You should also add the identifier lines to the top of the Project.toml file

name = "MyProj"
uuid = "a-long-uuid"
authors = "Your Name "
version = "0.1.0"

the only thing I can’t exactly remember is how to manually generate the uuid. There is a function in Pkg.jl that does it, look for it there. If you can’t find it, just make a fake package elsewhere with the same name, and copy its uuid over lol (only half joking).

Of course adding docs and test toplevel folders (with content) is also recommended.

4 Likes

Thanks! It looks like the Pkg docs recommend using UUIDs.uuid4() to generate a UUID. UUIDs is a module in the standard library, so the UUID can be generated like this:

using UUIDs
id = uuid4()
4 Likes