Keeping local Manifest.toml's up to date

Generally, I do not commit Manifest.toml, docs/Manifest.toml and test/Manifest.toml (where applicable) to git repositories for packages.

However, as a result, sometimes these become out of date for local clones of packages repos. I can of course always update them manually, but I am wondering if there is a semi-automated solution that would at least give a warning about them being outdated whenever I activate any of these projects.

(Bonus question: should docs/ and test/ projects ] dev ..?)

At least for the docs, I do update them when running the make.jl. I do not yet do a separate test/ manifest.

Concerning the bonus question, instead of a dev I switched to providing the parent folder as a source for the package.

2 Likes

Nowadays I use

[sources]
MainPackage = {path = ".."}

in my Project.toml files for both docs/ and test/. This makes docs CI simpler (no need to add the package) and works as long as you build your docs on 1.11. It doesn’t matter for ] test MainPackage so CI tests work also for older juila versions. It is very convenient for cases where you ] activate MainPackage/test (which is the environment I have activated 99% of the time when developing MainPackage).

3 Likes

Great idea! It appears that in 1.12 dev automatically does that.

I am now experimenting with the following pre-commit git hook:

#!/bin/bash
if [[ -n "$CI" ]]; then
   echo "In CI, skipping updates."
   exit 0
fi
if [ `git rev-parse --is-bare-repository` == "true" ]; then
   echo "In bare repository, skipping updates."
   exit 0
fi
JULIA=`which julia`
if [ -z "$JULIA" ]; then
   echo "Julia executable not found, skipping updates."
   exit 1
fi
cat <<"EOF" | $JULIA --startup-file=no -q
import Pkg
let # wrap to minimize clutter printed
    function maybe_update_project(dir;
                                  old_manifest_days = 10)
        isfile(joinpath(dir, "Project.toml")) || return
        manifest = joinpath(dir, "Manifest.toml")
        isfile(manifest) && (time() - stat(manifest).mtime) < (60*60*24*old_manifest_days) && return
        Pkg.activate(dir)
        Pkg.update()
    end
    maybe_update_project(".")
    maybe_update_project("test/")
    maybe_update_project("docs/")
    nothing
end
EOF

It only updates every 10 days. Firing up a Julia process has a tiny cost, but I prefer to script in Julia.

1 Like

This doesn’t exactly warn about outdated manifests, or even remove the need for “manual” updating, but I would recommend that all projects include a Makefile for dev-tasks.

I use make distclean to remove all Manifest.toml files in the project:

I’m in the habit of typing make distclean on a somewhat regular basis, e.g., after switching between non-trivial branches or before making releases.

2 Likes

Here is an updated script that does the testing in Bash.

(Disclaimer: I am not very good at programming Bash. Suggestions welcome.)