Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black support for Databricks notebook formatting - Ignore lines starting with ! or % #4556

Open
vivek-freddy opened this issue Jan 22, 2025 · 0 comments

Comments

@vivek-freddy
Copy link

I have a .py file which runs as notebook

# Databricks notebook source
!pip install -U dspy python-dotenv
!pip install torchmetrics
dbutils.library.restartPython() 
# COMMAND ----------
from tqdm.notebook import tqdm
tqdm.pandas()
import logging
# COMMAND ----------
!pip install matplotlib seaborn

The above is python file which runs as notebook where each cell is defined by # COMMAND in databricks. When applying black formatting I want to skip the pip install related lines. I tried using noqa but still above is causing warnings. How do I skip checking lines which have ! or % as starting character?

My pre-commit file config is

repos:
  - repo: https://github.com/psf/black
    rev: 23.3.0
    hooks:
      - id: black
        name: black
        description: "Black: The uncompromising Python code formatter"
        entry: black
        language: python
        minimum_pre_commit_version: 2.9.2
        require_serial: true
        types_or: [ python, pyi ]
      - id: black-jupyter
        name: black-jupyter
        description:
          "Black: The uncompromising Python code formatter (with Jupyter Notebook support)"
        entry: black
        language: python
        minimum_pre_commit_version: 2.9.2
        require_serial: true
        types_or: [ python, pyi, jupyter ]
        additional_dependencies: [ ".[jupyter]" ]

On running

pre-commit run --all-files

Warnings which I get is

Cannot parse: 7:0: !pip install -U dspy python-dotenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant