joouha / euporie

Jupyter notebooks in the terminal
https://euporie.readthedocs.io
MIT License
1.54k stars 36 forks source link

Autoformat is not working #104

Closed danielcs88 closed 3 months ago

danielcs88 commented 3 months ago

Autoformat (Settings -> Code tools -> ✓ Autoformat) is not working for me.

I have this long line function

def solution(df: pd.DataFrame) -> pd.DataFrame:
    return df.loc[df['language'].isin(['english', 'german', 'french', 'spanish'])].groupby('company_id', as_index=False).agg({"user_id":"nunique"})

If autoformatted (with Black) this would convert into:

def solution(df: pd.DataFrame) -> pd.DataFrame:
    return (
        df.loc[df["language"].isin(["english", "german", "french", "spanish"])]
        .groupby("company_id", as_index=False)
        .agg({"user_id": "nunique"})
    )

My config file is

{
  "notebook": {
    "syntax_theme": "dracula",
    "autocomplete": true,
    "autoformat": true,
    "format_black": true,
    "line_numbers": true,
    "background_pattern": 4,
    "enable_language_servers": true,
    "expand": false,
    "color_scheme": "default"
  }
}
joouha commented 3 months ago

Hi Daniel,

With 2.8.0, euporie changed to use external tools for formatting to allow formatting languages other than Python.

If you want to use black, you'll need to update your config as follows:

{
  "notebook": {
    "syntax_theme": "dracula",
    "autocomplete": true,
    "autoformat": true,
    "line_numbers": true,
    "background_pattern": 4,
    "enable_language_servers": true,
    "expand": false,
    "color_scheme": "default"
  }, 
  "formatters": [
    {
      "command": ["black", "-"],
      "languages": ["python"]
    }
  ]
}

I'm planning on making it possible to configure in the UI in the future 👍

danielcs88 commented 3 months ago

Worked flawlessly, thanks @joouha !