Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace black with ruff formatter #101

Closed
jaraco opened this issue Dec 19, 2023 · 3 comments
Closed

Replace black with ruff formatter #101

jaraco opened this issue Dec 19, 2023 · 3 comments

Comments

@jaraco
Copy link
Owner

jaraco commented Dec 19, 2023

In jaraco/pip-run@850cf7c, I've started experimenting with what it will take to replace black with ruff formatter.

Basically, pytest-ruff already supports enforcement with the --ruff-format option, and with the following config,

[format]
preview = true
quote-style = "preserve"

It's pretty comparable to the current black style.

#99 already starts to explore this change.

There are a few things that still need to be addressed:

Should the change introduce import sorting and pyupgrade also?

My instinct is no, let's start with something that's essentially comparable to black and later expand the scope.

Should --ruff-format be added to each and every project or to pytest-enabler?

My instinct is it should be in pytest-enabler, comparable to the black behavior. That's a little complicated because it's a backward-incompatible change and for users with both pytest-ruff and pytest-black installed, it might produce irreconcilable failures.

I'd say we should take it one step at a time, except that introducing it for all projects and then later changing the default for pytest-enabler will result in a lot of flux in pyproject.toml for all projects (along with the possible merge conflicts).

@jaraco jaraco closed this as completed in 131b2ed Dec 22, 2023
jaraco added a commit that referenced this issue Dec 22, 2023
jaraco added a commit that referenced this issue Dec 22, 2023
* Use the ruff formatter, instead of black

Based on:
- ruff-pre-commit README.md | Using Ruff with pre-commit
  https://github.com/astral-sh/ruff-pre-commit/blob/main/README.md
- The Ruff Formatter | Conflicting lint rules
  https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules

Support for the ruff formatter was added to pytest-ruff by commits from
October 2023, released the same day as versions 0.2 and 0.2.1. Hence, it
makes sense to require pytest-ruff ≥ 0.2.1 now.

Support for `quote-style = "preserve"` was added to ruff in the last
couple of weeks, therefore require the latest version, ruff ≥ 0.1.8.
This option is equivalent to `skip-string-normalization` in black.

Closes #101.

---------

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
@bswck
Copy link
Contributor

bswck commented Dec 22, 2023

Based! 🚀

@jaraco
Copy link
Owner Author

jaraco commented Dec 23, 2023

While rolling this out, I've learned that the removal of the black badge triggers merge conflicts due to changes in the subsequent RTD badge (when it's been enabled downstream). The jaraco.develop routine that resolves the conflict ends up discarding the downstream change (causing the RTD badge to be commented out again if it had been uncommented).

@jaraco
Copy link
Owner Author

jaraco commented Dec 23, 2023

This is what the conflict looks like unresolved:

 path main @ git diff
diff --cc README.rst
index c8f71e1,2fabcf3..0000000
--- a/README.rst
+++ b/README.rst
@@@ -11,12 -11,8 +11,17 @@@
      :target: https://github.com/astral-sh/ruff
      :alt: Ruff
  
++<<<<<<< HEAD
 +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
 +   :target: https://github.com/psf/black
 +   :alt: Code style: Black
 +
 +.. image:: https://readthedocs.org/projects/path/badge/?version=latest
 +   :target: https://path.readthedocs.io/en/latest/?badge=latest
++=======
+ .. .. image:: https://readthedocs.org/projects/PROJECT_RTD/badge/?version=latest
+ ..    :target: https://PROJECT_RTD.readthedocs.io/en/latest/?badge=latest
++>>>>>>> b8c6c1530ef937521b60aabb0ecd98a8b5dca761
  
  .. image:: https://img.shields.io/badge/skeleton-2023-informational
     :target: https://blog.jaraco.com/skeleton

jaraco added a commit to jaraco/jaraco.develop that referenced this issue Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants