neuromodulation / py_neuromodulation

Real-time analysis of intracranial neurophysiology recordings.
https://neuromodulation.github.io/py_neuromodulation/
MIT License
42 stars 9 forks source link

Change formatter from Black to Ruff #309

Closed toni-neurosc closed 5 months ago

toni-neurosc commented 5 months ago

So Ruff is a formatter/linter that is developed by the same guys that develop Rye: https://docs.astral.sh/ruff/formatter/

It's way faster than black, formats very similarly, and it seems to be trending these days.

Also Black bracket style kinda sucks IMHO, that's one of the very few changes that Ruff makes, particularly the way it breaks square brackets. Example

Black:

                features_compute[
                    f"{ch_name}_bursts_{fband_name}_duration_max"
                ] = (np.max(burst_length) if len(burst_length) != 0 else 0)
                features_compute[
                    f"{ch_name}_bursts_{fband_name}_amplitude_max"
                ] = (
                    np.max([np.max(a) for a in burst_amplitude])
                    if len(burst_amplitude) != 0
                    else 0
                )

Ruff:

                features_compute[f"{ch_name}_bursts_{fband_name}_duration_max"] = (
                    np.max(burst_length) if len(burst_length) != 0 else 0
                )
                features_compute[f"{ch_name}_bursts_{fband_name}_amplitude_max"] = (
                    np.max([np.max(a) for a in burst_amplitude])
                    if len(burst_amplitude) != 0
                    else 0
                )

@timonmerk what do you think?

timonmerk commented 5 months ago

Makes sense! Let's switch to ruff. Seems like Rust packages supporting Python development are taking over :)

We should somehow put that also in a contributing guideline. Some other packages have that, so in IDEs people could select that to have the same formatting.

toni-neurosc commented 5 months ago

Ok, I will add the formatting as a commit in the refactoring branch with the big PR. Maybe you can open an issue about the contributing guidelines so we can add that to our backlog.

Makes sense! Let's switch to ruff. Seems like Rust packages supporting Python development are taking over :)

It sure does! I had a quick look an there's even a Python interpreter written in Rust . I guess is useless for science work since all the number crunching packages are written in C but it's cool nonetheless.

toni-neurosc commented 5 months ago

Closed with the merge of #305