grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
387 stars 21 forks source link

blue changes `%autoreload 2` in jupyter ntoebooks to random hex #99

Open Vulwsztyn opened 1 year ago

Vulwsztyn commented 1 year ago

How to reproduce:

  1. create a jupyter notebook file with content:

    {
    "cells": [
    {
    "cell_type": "code",
    "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
    ]
    }
    ],
    "metadata": {
    "language_info": {
    "name": "python"
    },
    "orig_nbformat": 4
    },
    "nbformat": 4,
    "nbformat_minor": 2
    }
  2. have blue and black[jupyter] installed,

  3. run blue

Most env agnostic way would be:

  1. run docker container run -it -vpwd:/app -w /app pyfound/black bash
  2. (inside the docker) run pip install black[jupyter]; pip install blue
  3. (inside the docker) run blue .

Current behaviour: The

%load_ext autoreload
%autoreload 2

in jupyter notebook gets formatted as:

""%load_ext autoreload""
'b3d554e307.'

Expected behaviour: it is left unchanged.