jupyterlab-contrib / jupyterlab_code_formatter

A JupyterLab plugin to facilitate invocation of code formatters.
https://jupyterlab-code-formatter.readthedocs.io/
MIT License
851 stars 55 forks source link

Feat: use entrypoints to extend to other formatters #231

Open agoose77 opened 2 years ago

agoose77 commented 2 years ago

This would:

ryantam626 commented 2 years ago

Sorry for the late reply, was extremely burnt out and just switched off.

I am not quite sure what you mean here, could you please elaborate?

leihao-git commented 2 years ago

like SQL?

agoose77 commented 2 years ago

Oh, I missed this! Sorry to hear that you've been burnt out Ryan, hope you've been able to take a break of some kind :/

Let's say that I wanted to use clang-format (or some other tool). If this plugin supported entry-points, it would be able to discover additional third-party formatters that provided these entry-points. This would mean that you'd end up maintaining the entry-point interface, rather than N plugin implementations. Effectively, this package just becomes a way of launching a formatted and applying the result.

E.g.

pyproject.toml

[project.entry-points.jupyterlab-code-formatter]
isort = "isort-formatter:plugin"

jupyterlab_code_formatter/plugins.py

import importlib.metadata

def load_formatters():
    entry_points = importlib.metadata.entry_points(group="jupyterlab-code-formatter")
    return {
        ep.name: ep.load() for ep in entry_points
    }