This repository provides a template for an xnat plugin including:
- github actions for automated release (as a github release with attached jars, as well as to Github Packages )
- github actions for linting with pre-commit
- github actions + python files for running automated tests via
xnat4tests - A framework for downloading test data from Zenodo with
poochand caching with github actions
See the xnat-mrd or
xnat-interfile repositories, for
examples of plugins that use this template.
This template was created as part of the SyneRBI project.
Click the green 'Use this template' button at the top right of the repository main page to make a new repository.
Update your plugin details in build.gradle:
-
Change the group from
group "org.nrg.xnatx.plugins"to a value appropriate for your project. Follow the standard naming conventions. -
Update the
descriptionto describe what your plugin does. -
At the bottom of the file, update the publishing url to match the github organisation and repository name of your project.
publishing { publications { ... } repositories { maven { // UPDATE THIS URL LINE url = "https://maven.pkg.github.com/ORGANISATION/REPOSITORY" ... } } }
Update the rootProject.name in the settings.gradle file.
Fill the /src directory with your plugin files. You can find examples in the
official
xnat-template-plugin repository,
or in the xnat-mrd /
xnat-interfile repositories.
These files handle spinning up xnat in a Docker container (via xnat4tests),
and running automated tests. This uses
xnatpy to handle calls to the xnat
API.
Update python/tests/conftest.py:
-
update the
jar_pathfixture to match the name of your built jar:# e.g. to match a jar called test-VERSION-xpl.jar, update to: jar_path = list(jar_dir.glob("test-*xpl.jar"))[0]
-
update the
plugin_versionfixture to match the jar path:# e.g. to match a jar called test-VERSION-xpl.jar, update to: match_version = re.search("test-(.+?)-xpl.jar", jar_path.name)
Update python/tests/test_server.py:
-
In
test_server.py, a single example test is provided to verify the installed plugin version. You will need to update"xnatPlugin"and the expected value ofxnat_plugin.nameto match thevalue/nameset in your@XnatPluginjava class (part of the plugin files in the/srcdirectory). -
Expand
test_server.pywith additional automated tests for your plugin. E.g. see thexnat-mrd/xnat-interfilerepositories for further test examples.
Update python/pyproject.toml. Note: this handles dependencies installed via
pip. If your tests depend on packages only available via conda, you will
need to specify those dependencies separately. See the
xnat-interfile repository for an
example of a project with conda dependencies.
-
Update the author email / name
-
Update the description / name (optional)
-
Add any extra python dependencies needed for your tests. These can be added to the
dependenciesordevlists.
Update python/src/xnat_plugin/fetch_datasets.py:
- If you don't need test datasets, you can remove this file.
- Otherwise, edit the examples in this file to use your own
zenododoi links and image names. See thexnat-mrd/xnat-interfilerepositories for examples of how to use these test datasets in tests.
-
For the
.github/workflows/linting.yamlworkflow, you need to follow the instructions for setting up the pre-commit.ci lite add-on for theAuto-fixes commit and push (pre-commit-ci-lite)step. -
For
.github/workflows/test.yamlto pass successfully, you will need to make one release onmain. See the release instructions. -
If you need additional conda dependencies then you can add another step after
Set up Pythonin.github/workflows/test.yaml:
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.12
auto-update-conda: true
environment-file: python/environment.yml
activate-environment: xnat-plugin-envYou would also need to add the following line to the Install dependencies and
Run tests with pytest steps:
shell: bash -l {0} # required to load conda properlyAn example of this can be found in the xnat-interfile reposistory with the .github/workflows/test.yaml including the steps stated above and the other required python/environment.yml file.
Developer documentation is provided for:
- building the plugin locally
- running tests locally
- making new releases on github
- running pre-commit locally
- updating versions of dependencies