I’d like to announce the first ‘stable’ version of antsibull-nox (code), antsibull-nox 0.3.0. Antsibull-nox is a Nox helper library for Ansible collections.
Nox…?
Nox is a test runner, similar to tox, hatch, and pre-commit, that can be programmed in Python (instead of using some DSL). Antsibull-nox allows to run various tests using a TOML based config (with a minimal Python noxfile.py
), and provides powerful tools to add own sessions to noxfile.py
that need collection dependencies present and/or the collection itself in an importable manner. Antsibull-nox will download/install required collections if necessary, and create temporary tree structures to allow importing and running tools like ansible-test
no matter where you clone the collection’s repository.
Examples
Antsibull-nox is somewhat opinionated in the selection of sessions it offers, but tries to be highly customizable. For an example antsibull-nox.toml
config file, see community.dns/antsibull-nox.toml at 067401de97e19871cc782a88f0abf72b41d5c361 · ansible-collections/community.dns · GitHub. The corresponding noxfile.py
is community.dns/noxfile.py at 067401de97e19871cc782a88f0abf72b41d5c361 · ansible-collections/community.dns · GitHub, which loads the antsibull-nox.toml
config file and adds two special sessions that are community.dns specific.
The config file generates sessions for:
- linting (including code formatting, Python code linting, YAML linting, type checking),
- docs checking,
- license checking,
- extra tests like no unwanted files and action group checking (never forget to add modules to an action group again, or forget to document that a module is part of an action group),
- Galaxy import checking,
- running Ansible-lint (not present in that example),
- and running ansible-test sanity, unit, and integration tests.
Antsibull-nox comes with a GitHub Action and a reusable workflow that simplifies calling nox and creating CI matrices for ansible-test:
- Workflow: community.dns/.github/workflows/nox.yml at 067401de97e19871cc782a88f0abf72b41d5c361 · ansible-collections/community.dns · GitHub
- Resulting CI run: Release 3.2.3. · ansible-collections/community.dns@067401d · GitHub
Design decisions
-
Why use nox instead of tox, hatch, pre-commit, …? The main reason is that I wasn’t able to do what I wanted (setting up collections and composing commands to run) with tox and hatch; I only managed to do it with nox in a sane way (i.e. without monkeypatching). The main reason not to use pre-commit is that the main idea there is to run everything in a pre-commit hook. Some of the sessions antsibull-nox offers are fine for that, while others (like running
ansible-test xxx --docker
) are not. (You should be able to combine antsibull-nox with pre-commit though.)Not having this flexibility would result in users having to clone the repository into a special directory structure (so that ansible-test can run, for example, or that importing things works when setting the Python path programmatically), take care of installing dependent collections in the same tree structure (for example ansible-test won’t find them otherwise), etc. Being able to simply run
nox -R
orpipx run noxfile.py -R
oruv run noxfile.py -R
in a collection directory to run all tests (the-R
reuses venvs that nox creates, which will make this faster if you run it more than once). -
Why use a TOML configuration file instead of, say, YAML? TOML has the big advantage of being simpler and having better tooling for programmatically modifying it while keeping the original formatting. There is partial support for YAML for doing that as well (using ruamel.yaml), but it’s not perfect.
Automatically updating is very useful if versions of dependencies are pinned in the config file, and you want these to be automatically bumped (similar to Dependabot), for example.
(Also if there’s a huge demand, we can still add support for a YAML config file as well.)
How does the roadmap look like?
The current 0.3.0 release is the first “stable” release in the sense that I do not want any breaking changes until 1.0.0 is there (and since antsibull-nox should adhere to semantic versioning, there won’t be breaking changes until 2.0.0). I’m using quotes for “stable” since there is still a certain risk for breaking changes since the tool is rather new, and we might notice once more folks start using it that some decisions I made weren’t so great, and not fixing them in a breaking way would be really bad. I hope that won’t happen, but I cannot guarantee that until 1.0.0 is out.
I still think it’s ready to use, and I’ve started using it in all collections I’m maintaining (community.general, community.crypto, community.dns, community.docker, community.hrobot, community.internal_test_tools, community.library_inventory_filtering_v1, community.routeros, community.sops, felixfontein.acme). Until a few days ago it was just three of them, to avoid too much work when introducing breaking changes (there were a few). Me using it in all these collections should also tell you that I’m really serious about trying to avoid breaking changes
About adding support for more sessions: I’m absolutely open for that! I mainly added the sessions which I use/need so far (that apply to more than a single collection) (only exception: running basic EE tests)
Ideas? Questions? Feedback?
I’m happy to hear about that! If you want to chat, you can also take a look at the #antsibull:ansible.com Matrix room.