Skip to content

Conversation

@grische
Copy link
Contributor

@grische grische commented Sep 19, 2025

This is a basic CI for checking formatting with black, together with a dependabot configuration to keep it updated.
I will try to expand it using ruff or pylint or flake8 in the coming days.

Line length of 80 vs 88

I removed the line-length of 80 from the pyproject.toml, as it reduced the changes down to 60% (182 vs 117 inserts):

With a line-length of 80:

All done! ✨ 🍰 ✨
5 files reformatted, 2 files left unchanged.
 morgan/__init__.py     |  91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
 morgan/configurator.py |  39 ++++++++++++++++++++-------------------
 morgan/metadata.py     |  34 +++++++++++++++++++++-------------
 morgan/server.py       | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------------
 morgan/utils.py        |  13 +++++++------
 pyproject.toml         |   7 +++++++
 6 files changed, 182 insertions(+), 117 deletions(-)

With black's default (=88):

All done! ✨ 🍰 ✨
5 files reformatted, 2 files left unchanged.
 morgan/__init__.py     |  18 ++++++++----------
 morgan/configurator.py |  39 ++++++++++++++++++++-------------------
 morgan/metadata.py     |  34 +++++++++++++++++++---------------
 morgan/server.py       | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------
 morgan/utils.py        |  13 +++++++------
 pyproject.toml         |   8 +++++++-
 6 files changed, 117 insertions(+), 108 deletions(-)

Ruff instead of Black

Alternatively, we can also use ruff for formatting. It includes auto-formatting of includes which is usually very nice.
In the code that is formatted with both black and ruff, it is usually compatible with black. This code base would only have this difference:

diff --git a/morgan/server.py b/morgan/server.py
index d92197c..fbef175 100644
--- a/morgan/server.py
+++ b/morgan/server.py
@@ -155,9 +155,7 @@ class RequestHandler(http.server.BaseHTTPRequestHandler):
                             hashval,
                             file["filename"],
                             newline,
-                        ).encode(
-                            "utf-8"
-                        ),
+                        ).encode("utf-8"),
                     )
                 else:
                     self.wfile.write(

I'm happy to change this PR to ruff if you prefer.

@grische grische changed the title Add basic Github Action add basic Github Action Sep 19, 2025
@grische grische changed the title add basic Github Action add Github Action for black formatting Sep 23, 2025
@grische
Copy link
Contributor Author

grische commented Oct 14, 2025

I am marking this as a draft until all outstanding PRs have been merged to avoid unnecessary merge conflicts.

@grische grische marked this pull request as draft October 14, 2025 14:40
@ido50
Copy link
Owner

ido50 commented Oct 17, 2025

I did actually move to use ruff in my other projects. Let's do that if you don't mind.

@shamilbi
Copy link
Collaborator

Could you please consider adding to pyproject.toml:

[tool.black]
skip-string-normalization = true

to help prevent excessive changes?

@grische
Copy link
Contributor Author

grische commented Nov 6, 2025

I did actually move to use ruff in my other projects. Let's do that if you don't mind.

@ido50 I replaced black with ruff and did a tree-wide formatting using ruff.

@grische grische marked this pull request as ready for review November 6, 2025 14:45
@grische grische changed the title add Github Action for black formatting add Github Action for ruff formatting Nov 6, 2025
@shamilbi
Copy link
Collaborator

shamilbi commented Nov 6, 2025

Could you please consider adding to pyproject.toml:

[tool.ruff.format]
quote-style = "preserve"

to help prevent excessive changes?

@grische
Copy link
Contributor Author

grische commented Nov 6, 2025

Could you please consider adding to pyproject.toml:

[tool.ruff.format]
quote-style = "preserve"

to help prevent excessive changes?

The difference is ~30 changed lines. I wouldn't call that excessive and it really impairs readability and long-term maintainability if you do not have a unified code style.

@ido50 ido50 merged commit 8747162 into ido50:main Dec 29, 2025
7 checks passed
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

Successfully merging this pull request may close these issues.

3 participants