ryantam626 / jupyterlab_code_formatter

A JupyterLab plugin to facilitate invocation of code formatters.
MIT License
822 stars 52 forks source link

Suppress stderr in call to ruff and add ruff formatter #333

Open felix-cw opened 5 months ago

felix-cw commented 5 months ago

This PR adds the fix I suggested in #331 to ensure compatibility with ruff 0.1.0+. I've confirmed it works with version 0.1.15.

I also added the ruff formatter itself, as a substitute for black, called "ruffformat". The formatter simply called "ruff" is for applying automatic fixes for diagnostics. For example, isort-style import sorting.

MordorianGuy commented 3 months ago

Would it be more adaptive to initialise the command depending on the ruff version which may be acquired via subprocess.run? By the way, could you, please, elucidate a little how to install the package during development? When I install the released version of package via pip into a hollow environment (mamba create -n test pip) it installs without any problem. But when I am trying to install it either from my fork repository (via git+[link] notation) or directly from a local path (pip install -e [path]) the installation fails.

felix-cw commented 3 months ago

Hi. Thanks for the comment. I believe the added flags for the ruff --fix command will work for versions pre 0.1.0 so no change required. Since ruff formatting was added more recently, the ruff command would fail for previous versions that do not support it. Since using these formatters is opt-in, we might expect someone who turns it on to have a compatible ruff version installed. Is there a way to warn the user they need to update their ruff version to use the feature?

On the installation, honestly I just edited the files in my conda env and transcribed the changes here. I know that's not right! The doc site has a page about installing it for development but I haven't tried it yet.