Skip to content

Cell magics starting with single '%' are not ignored #887

@danielsparing

Description

@danielsparing

For better or worse, some systems use single '%' headers for cell magics, notably Databricks, e.g. %sql and %r.

I successfully used nbQA with %sql cells for a long time (they magically just get ignored), however, with %r cells, nbqa-ruff-check and nbqa-ruff-format has a false positive at the below example (in R, <- is the assignment operator):

nbqa-ruff-check..........................................................Failed
- hook id: nbqa-ruff-check
- exit code: 1

r\install sf.ipynb:cell_3:2:1: B015 Pointless comparison. Did you mean to assign a value? Otherwise, prepend `assert` or remove it.
   |
 9 | # %%NBQA-CELL-SEPe5ddb4
10 | hash(0x96DAFA9D)
11 | var <- 1 + 1
   | ^^^^^^^^^^^^ B015
   |

Found 1 error.

nbqa-ruff-format.........................................................Failed
- hook id: nbqa-ruff-format
- files were modified by this hook

1 file reformatted

and the reformat is:

-    "var <- 1 + 1"
+    "var < -1 + 1"

(if I use %%r, they are ignored -- but %r is the right cell magic in this env.)

I wonder if there's a way to work around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions