Skip to content

Add ruff as default linting + formatting option#387

Merged
chrisjkuch merged 9 commits intomasterfrom
add-ruff
Mar 5, 2025
Merged

Add ruff as default linting + formatting option#387
chrisjkuch merged 9 commits intomasterfrom
add-ruff

Conversation

@chrisjkuch
Copy link
Contributor

@chrisjkuch chrisjkuch commented Jun 19, 2024

Closes #374
Closes #388

This PR adds ruff as the default linting and formatting option for new ccds projects.

Implementation notes

  • I've slightly altered the Makefile command tests so that they now run within each venv harness. I check to ensure that linting and formatting run without error and that nothing is reformatted.
    • For whatever reason, I found that ruff piped to stdout and flake8/black/isort piped to stderr. Maybe there's a nuance here or I've done something wrong?
  • I've cleaned up the generated pyproject.toml and removed setup.cfg if using ruff since it's no longer needed.
  • I didn't stray very far from the default ruff config, changing only the line length. If we are opinionated about the default set of linting / formatting options, happy to add those, but I have no strong preferences.

Discussion

As mentioned, this PR makes ruff the default option. I think there's good arguments for this that mostly boil down to "it's simpler + faster":

  • one tool for linting + formatting so fewer dependencies and simpler config
  • no setup.cfg file so everything can live in pyproject.toml
  • ruff is quite fast

However, ruff is still (relatively) new, whereas flake8/black/isort is more mature, and most projects won't notice the speed difference until they get quite large. I could be persuaded that we should introduce ruff without making it the default option.

@chrisjkuch chrisjkuch added this to the v2.1 milestone Jun 19, 2024
@chrisjkuch chrisjkuch requested review from jayqi and pjbull June 19, 2024 16:51
@jayqi
Copy link
Member

jayqi commented Jun 20, 2024

I'm in favor of having the default to be Ruff. It's clear that Ruff is the emerging standard, and they describe themselves as production-ready.

There are major projects that are fully using Ruff for linting and formatting.

Lots of other major projects (e.g., pip, matplotlib, PyTorch) are using Ruff for linting over flake8, though are still using black for now.

@pjbull pjbull mentioned this pull request Jun 22, 2024
@szapp
Copy link

szapp commented Oct 11, 2024

It seems that slight adjustments to the linter rules are necessary to ensure similar behavior as the flake8/black/isort alternative. Most of the rules that flake8 ignores in the setup.cfg are ignored in the defaults of ruff as well, except for E731 if I am not mistaken.

If I am not wrong, these additional lines in pyproject.toml should do.

[tool.ruff.lint]
ignore = [
  "E731"  # lambda-assignment: Do not assign a lambda expression, use a def
]

Update: Additionally, the I (isort) rules should be added according to the readme of the charliermarsh.ruff vscode extension in order to enable organization of imports. It's not enabled by default.

[tool.ruff.lint]
ignore = ["E731"]  # Ignore lambda-assignment
extend-select = ["I"]  # Add sorting imports (isort ruleset) to defaults

@chrisjkuch
Copy link
Contributor Author

@szapp thanks for catching the isort fix! I've opted to keep the default selections in ruff for now - I don't know that we're necessarily aiming for exact parity with black, as opposed to just a good starting point for a project.

@chrisjkuch chrisjkuch modified the milestones: v2.1, v2.0.2 Feb 26, 2025
@pjbull pjbull temporarily deployed to add-ruff - Cookiecutter Data Science PR #387 March 2, 2025 13:02 — with Render Destroyed
@pjbull pjbull temporarily deployed to add-ruff - Cookiecutter Data Science PR #387 March 2, 2025 14:11 — with Render Destroyed
@chrisjkuch chrisjkuch deleted the add-ruff branch March 5, 2025 16:36
chrisjkuch added a commit to GatlenCulp/gatlens-opinionated-template that referenced this pull request Mar 5, 2025
chrisjkuch added a commit that referenced this pull request Mar 5, 2025
* Added light compatibility with my own repository

* Copied over uv harness

* Added uv to ccds.json and ccds-help.json as well as added it to the makefile. Is untested.

* Simplified harness and added it to valid environment managers

* Minor simplifications to harness and virtualenv + Makefile

* Updated uv and requirements.txt to use uv instead of default pip

* Made uv install requested python version

* Added uv to dev-requirements.txt and removed redundant pip install from makefile

* revert gitignore and pyproject.toml changes

* add newline at end of venv harness

* remove uv pip install pip (unnecessary)

* add newline to uv_harness

* add lint and format makefile test commands per #387

---------

Co-authored-by: Chris Kucharczyk <chris.kucharczyk@gmail.com>
jayqi added a commit that referenced this pull request Mar 10, 2025
* Add back isort configuration that was removed in #387

* Fix wrong sorting in code scaffold

---------

Co-authored-by: Jay Qi <jayqi@users.noreply.github.com>
proinsias added a commit to proinsias/cookiecutter-data-science-proinsias that referenced this pull request Nov 3, 2025
* upstream/master: (24 commits)
  Add poetry as an env manager (drivendataorg#460)
  Support pixi as environment manager (drivendataorg#459)
  Docs: Add guidelines for contributing and requesting tools (drivendataorg#456)
  Fix terminal animation generation in docs build (drivendataorg#451)
  Fix failing pipenv installation on Windows GH actions runners (drivendataorg#453)
  Fix typo in using-the-template.md (drivendataorg#448)
  Bump to v2.2.0 [skip ci]
  Update HISTORY.md [skip ci]
  Add option for tests (drivendataorg#447)
  Resolve python version to work with compatible operator (drivendataorg#446)
  Add pyproject.toml as a dependencies file option (drivendataorg#436)
  Make PyPI badges links to PyPI (drivendataorg#440)
  Update to version v2.1.0 (drivendataorg#438)
  Add back isort configuration that was removed in drivendataorg#387 (drivendataorg#439)
  add badges to readme and docs homepage (drivendataorg#434)
  Added support for the uv package and project manager (drivendataorg#408)
  Add ruff as default linting + formatting option (drivendataorg#387)
  Add PyTest IDs for better readability and filtering (drivendataorg#409)
  prepare for 2.0.1 release by bumping version in pyproject.toml and updating change log (drivendataorg#422)
  Fix pre-prompt ccds version error (drivendataorg#426)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ruff lint configuration names are incorrect

4 participants