Nox runs commands via nox.Session.run
. For example, this is a typical nox command:
import nox
@nox.session(venv_backend="none")
def black(session: nox.Session):
session.run("black", "--check", ".")
Some tools are not amenable to running as a simple command, for example, clang-format
. It is typically run as a find
on C files and a pipe |
into clang-format
, like this:
find . -name "*.c" -print0 | xargs -0 clang-format --style=file --dry-run
How do I run this in Nox?
Plopping that in as one string does not work obviously:
@nox.session(venv_backend="none")
def clang_format(session: nox.Session):
session.run('find . -name "*.c" -print0 | xargs -0 clang-format --style=file --dry-run')
Splitting it up into arguments does not work either obviously:
@nox.session(venv_backend="none")
def clang_format(session: nox.Session):
session.run('find', '.', '-name', '"*.c"', '-print0', '|', 'xargs', '-0', 'clang-format', '--style=file', '--dry-run')
I understand why this does't workâthe pipe is handled by the shell, not the OS. Is there a "shell mode" for Nox that is not documented? Or some other way to pipe commands in Nox?