#16401·ruff

Ignore specific comments when formatting

Author: toewenCreated Feb 26, 2025Updated Sep 27, 2026
Labelsconfigurationformatter

Summary

I have python scripts I execute on a slurm cluster.

To give some configurations to the cluster the script starts with comments in a specific style. For example

python
#!/bin/python
#SBATCH -n 5
#SBATCH -N 1

When formatting this file the Shebang is left as is but the other comments get treated as regular comments and a space is inserted between # and SBATCH. Unfortunately this space prevents the slurm cluster from recognizing the comments.

My current solution is

python
#!/bin/python
# fmt: off
#SBATCH -n 5
#SBATCH -N 1
# fmt: on

I would like an option to ignore these comments when formatting a file.