As you might have noticed, if you followed my last few posts, I am currently exploring the new programming language called Mojo.
Specifically the CSV package is quite useful, as I like to collect the results of a benchmark in a tabular form and CSV is the simplest and most portable format for it.
So it makes sense to reference the CSV package from other projects in order to use it in benchmark scripts. Sadly Mojo does not provide any package management tools yet. This is why I decided to invest a few hours into a simple solution until the official package manager makes its debut.
What you see above is a bash script which lets you checkout specific folders from a git repository.
check_out_remote_module "https://github.com/mzaks/mojo-csv" "csv"
Here we say that we would like to checkout the
csv folder which represents a Mojo module from a Github repository. The
csv folder will end up in your root project folder, which will make it accessible in your code. The script uses
sparse-checkout, which means that only the desired folders are checked out. This is useful as in the case of
mojo-csv, the repo also contains large csv files for benchmarking, which we don’t want to check out into our projects.
After the code is checked out, the script generates a
.checkoutinfo file in every folder, which contains a timestamp the source URL and the path to the folder:
Sun Oct 29 20:07:58 CET 2023
If a repo contains multiple modules, it is possible to check out multiple folders:
check_out_remote_module "https://github.com/mzaks/mojo-trees" "fiby_tree" "left_child_right_sibling=lcrs_tree"
As you can see above, I am checking out
mojo-trees repo. In case of
left_child_right_sibling module I also decided to rename the module, so I append
=lcrs_tree to the source folder name, which means that I want the target folder to be named
It is also possible to pick a nested module as you can see it in following example:
check_out_remote_module "https://github.com/tairov/llama2.mojo" "read/libc/stdio=file_io"
And last but not least, it is also very simple to pick a module form a specific branch, or tag as you can see below:
check_out_remote_module "-b v0.2.0 https://github.com/gabrieldemarmiesse/mojo-stdlib-extensions" "stdlib_extensions/builtins=list"
While I was implementing this solution, I had some ideas for an official Mojo package manager, but this is a topic for another blog post.
Please let me know, if you find this script useful and if there is a need for another blog post to explain things like how to structure your repo to increase module accessibility.