The cookiecutter
equivalent for Julia is PkgTemplates
(github link), but you can do a ton with the base Pkg
library. As someone who really like kedro
for python (kedro docs), I really want to know the best methods of creating a modular, reproducible analysis using Julia.
Here's the steps I need to understand:
Surprisingly, the best documentation for setting up your project exists in the Pkg
Getting Started With Environments documentation itself.
Instead of creating new environments from the command line with conda
, venv
, pyenv
, poetry
, etc etc you can do it through the Julia REPL or calling the Pkg
library within your script.
Pkg.status()
: See what environment you're usingPkg.activate()
: Activate environmentPkg.generate()
: Generates Pkg.instantiate()
: using Pkg;
Pkg.status()
pwd
- prints the current working directoryreaddir
- just like ls
in bash, lists files in the current directorymkdir
- makes a new directoryrm(path, recursive=true)
- recursively remove a directory readdir()
Pkg.generate
¶Julia gives us a barebones package generator with generate
that will make a Project.toml
config file and a src
directory with a 'hello world' julia file in it.
Pkg.generate("my_package")
See the directory structure of my_package
:
readdir("my_package")
readdir("my_package/src")
Activate the new package after creating the strawman using Pkg.generate
:
Pkg.activate("my_package")
Pkg.status()
You can also open a REPL using your project by navigating to the my_package
directory and calling something like:
# bash
julia --project=. # the '.' says to open julia using the environment in the current directory
And finally, if you open a jupyter notebook in the my_package
directory, it should use the directory's Julia environment by default.
Loading someone else's project after you've activated it, use instantiate
:
Pkg.instantiate()
Pkg.status()
Import your package
using my_package
And call the single function in the package
my_package.greet()
Pkg
¶generate
: Create a new, barebones julia package structureactivate
: Activates a julia environment (or creates one if it doesn't already exist)instantiate
: Install the package and required dependenciesrm("my_package", recursive=true)
readdir()