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

Switch from Black to Ruff formatter #35287

Merged
merged 10 commits into from Oct 31, 2023
Merged

Conversation

jlaneve
Copy link
Contributor

@jlaneve jlaneve commented Oct 31, 2023

This PR switches the formatter we use from Black to Ruff, now that Ruff's introduced a formatter. This PR also upgrades the version of Ruff to the latest.

Running locally:

> time black . --exclude="^.*/.*_vendor/|^tests/dags/test_imports.py|^airflow/contrib/"
All done! ✨ 🍰 ✨
4137 files left unchanged.
black .   5.01s user 1.65s system 97% cpu 6.820 total

> time ruff format . --exclude="^.*/.*_vendor/|^tests/dags/test_imports.py|^airflow/contrib/"
3999 files left unchanged
ruff format .   0.05s user 0.10s system 89% cpu 0.173 total

This represents means Ruff is ~40x faster than Black (when there are no changes - when there are changes, I've seen it even higher).

Note that this doesn't swap the formatter used in inline Python code in the docs as I haven't seen an easy way of getting the Ruff formatter working with it. Because of this, a lot of the Black code hasn't been removed (i.e. the code to upgrade black, etc).


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@jlaneve jlaneve changed the title Switch from Black to Ruff Switch from Black to Ruff formatter Oct 31, 2023
@potiuk
Copy link
Member

potiuk commented Oct 31, 2023

Looks like it works. Care to undraft it ?

.pre-commit-config.yaml Outdated Show resolved Hide resolved
tests/www/views/test_views_base.py Outdated Show resolved Hide resolved
tests/www/views/test_views_base.py Outdated Show resolved Hide resolved
Comment on lines +68 to +70
TEST_ENTRY_PATH: (
str
) = f"projects/{{}}/locations/{TEST_LOCATION}/entryGroups/{TEST_ENTRY_GROUP_ID}/entries/{TEST_ENTRY_ID}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That it also looks less readable rather than black formatting

airflow/www/views.py Show resolved Hide resolved
airflow/www/views.py Show resolved Hide resolved
airflow/models/dag.py Show resolved Hide resolved
airflow/api/common/delete_dag.py Show resolved Hide resolved
@jlaneve jlaneve marked this pull request as ready for review October 31, 2023 14:50
@jlaneve
Copy link
Contributor Author

jlaneve commented Oct 31, 2023

note that I added back inline tuples - turns out they were actually correct. see https://github.com/apache/airflow/actions/runs/6708119087/job/18230292697

airflow/api/common/delete_dag.py Outdated Show resolved Hide resolved
airflow/models/dag.py Outdated Show resolved Hide resolved
@kaxil
Copy link
Member

kaxil commented Oct 31, 2023

The current constraints failure is unrelated and affects other PRs too, example #35312 , merging this PR

@kaxil kaxil merged commit 63cc915 into apache:main Oct 31, 2023
64 of 66 checks passed
@jlaneve jlaneve deleted the use-ruff-formatter branch October 31, 2023 22:52
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Nov 10, 2023
This PR switches the formatter we use from Black to Ruff, now that Ruff's introduced a [formatter](https://docs.astral.sh/ruff/formatter/). The Ruff formatter is ~30x as fast as Black, and we already use Ruff for linting. This PR also upgrades the version of Ruff to the latest.

Note that this doesn't swap the formatter used in inline Python code in the docs as I haven't seen an easy way of getting the Ruff formatter working with it. Because of this, a lot of the Black code hasn't been removed (i.e. the code to upgrade black, etc).
@ephraimbuddy ephraimbuddy added the type:misc/internal Changelog: Misc changes that should appear in change log label Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API area:dev-tools area:lineage area:providers provider:apache-cassandra provider:apache-kafka provider:cncf-kubernetes Kubernetes provider related issues provider:ftp provider:google Google (including GCP) related issues provider:microsoft-azure Azure-related issues provider:openlineage AIP-53 provider:qubole provider:sftp provider:snowflake Issues related to Snowflake provider provider:trino type:misc/internal Changelog: Misc changes that should appear in change log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants