Skip to content

Commit 6bd7ba9

Browse files
committed
First draft of instructions for using dvc to store baseline images
1 parent f5e25fe commit 6bd7ba9

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

CONTRIBUTING.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,74 @@ If it's correct, copy it (and only it) to `pygmt/tests/baseline`.
423423
When you run `make test` the next time, your test should be executed and
424424
passing.
425425

426-
Don't forget to commit the baseline image as well.
426+
Don't forget to commit the baseline image as well!
427+
The images should be pushed up into a remote repository using `dvc` (instead of
428+
`git`) as will be explained in the next section.
429+
430+
#### Using data version control ([dvc](https://dvc.org)) to manage test images
431+
432+
As the baseline images are quite large blob files that can change often (e.g.
433+
with new GMT versions), it is not ideal to store them in `git` (which is meant
434+
for tracking plain text files). Instead, we will use [`dvc`](https://dvc.org)
435+
which is like `git` but for data. What `dvc` does is to store the hash (md5sum)
436+
of a file. For example, given an image file like `test_logo.png`, `dvc` will
437+
generate a `test_logo.png.dvc` plain text file containing the hash of the
438+
image. This `test_logo.png.dvc` file can be stored as usual on GitHub, while
439+
the `test_logo.png` file can be stored separately on our `dvc` remote at
440+
https://dagshub.com/GenericMappingTools/pygmt.
441+
442+
To **pull** or sync files from the `dvc` remote to your local repository, use
443+
the commands below. Note how `dvc` commands are very similar to `git`.
444+
445+
dvc status # should report any files 'not_in_cache'
446+
dvc pull # pull down files from DVC remote cache (fetch + checkout)
447+
448+
Once the sync/download is complete, you should notice two things. There will be
449+
images stored in the `pygmt/tests/baseline` folder (e.g. `test_logo.png`) and
450+
these images are technically reflinks/symlinks/copies of the files under the
451+
`.dvc/cache` folder. You can now run the image comparison test suite as per
452+
usual.
453+
454+
pytest pygmt/tests/test_logo.py # run only one test
455+
make test # run the entire test suite
456+
457+
To **push** or sync changes from your local repository up to the `dvc` remote
458+
at DAGsHub, you will first need to set up authentication using the commands
459+
below. This only needs to be done once, i.e. the first time you contribute a
460+
test image to the PyGMT project.
461+
462+
dvc remote modify upstream --local auth basic
463+
dvc remote modify upstream --local user "$DAGSHUB_USER"
464+
dvc remote modify upstream --local password "$DAGSHUB_PASS"
465+
466+
The configuration will be stored inside your `.dvc/config.local` file. Note
467+
that the $DAGSHUB_PASS token can be generated at
468+
https://dagshub.com/user/settings/tokens after creating a DAGsHub account
469+
(can be linked to your GitHub account). Once you have an account set up, please
470+
ask one of the PyGMT maintainers to add you as a collaborator at
471+
https://dagshub.com/GenericMappingTools/pygmt/settings/collaboration before
472+
proceeding with the next steps.
473+
474+
The entire workflow for generating or modifying baseline test images can be
475+
summarized as follows:
476+
477+
# Sync with git and dvc remote
478+
git pull
479+
dvc pull
480+
481+
# Generate new baseline images
482+
pytest --mpl-generate-path=baseline pygmt/tests/test_logo.py
483+
mv baseline/*.png pygmt/tests/baseline/
484+
485+
# Generate hash for baseline image and stage the *.dvc file in git
486+
dvc add pygmt/tests/baseline/test_logo.png
487+
git rm -r --cached 'pygmt/tests/baseline/test_logo.png' # optional
488+
git add pygmt/tests/baseline/test_logo.png.dvc
489+
490+
# Commit changes and push to both the dvc and git remote
491+
git commit -m "Add test_logo.png into DVC"
492+
dvc push --remote upstream
493+
git push
427494

428495
### Documentation
429496

0 commit comments

Comments
 (0)