Skip to content

Commit

Permalink
Merge pull request #69 from lsst-sqre/tickets/DM-43173
Browse files Browse the repository at this point in the history
DM-43173: Format codebase with ruff
  • Loading branch information
jonathansick authored Mar 7, 2024
2 parents b4e382a + 0a44b51 commit f0f657a
Show file tree
Hide file tree
Showing 33 changed files with 1,238 additions and 1,048 deletions.
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

21 changes: 6 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@ repos:
hooks:
- id: check-yaml
- id: check-toml
- id: trailing-whitespace

- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: isort
additional_dependencies:
- toml

- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
17 changes: 17 additions & 0 deletions changelog.d/20240305_122219_jsick_DM_43173.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Delete the sections that don't apply -->

### Backwards-incompatible changes

-

### New features

-

### Bug fixes

-

### Other changes

- The code base now uses Ruff for linting and formatting, replacing black, isort, and flake8. This change is part of the ongoing effort to standardize SQuaRE code bases and improve the developer experience.
2 changes: 1 addition & 1 deletion docs/_rst_epilog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.. _pytest: https://docs.pytest.org/en/latest/
.. _tox: https://tox.readthedocs.io/en/latest/
.. _httpie: https://httpie.io/cli
.. _`Rubin Science Platform environment`:
.. _`Rubin Science Platform environment`:
2 changes: 1 addition & 1 deletion docs/user-guide/environment-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ See the `Phalanx documentation for Noteburst <https://phalanx.lsst.io/applicatio
(string enum: "debug", "info" [default], "warning", "error", "critical") The application log level.

.. envvar:: NOTEBURST_PATH_PREFIX

(string, default: "/noteburst") The path prefix for the Noteburst application.
This is used to configure the application's URL.

Expand Down
135 changes: 112 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,6 @@ exclude_lines = [
"if TYPE_CHECKING:",
]

[tool.black]
line-length = 79
target-version = ['py311']
exclude = '''
/(
\.eggs
| \.git
| \.mypy_cache
| \.tox
| \.venv
| _build
| build
| dist
)/
'''
# Use single-quoted strings so TOML treats the string like a Python r-string
# Multi-line strings are implicitly treated by black as regular expressions

[tool.isort]
profile = "black"
line_length = 79
known_first_party = ["noteburst", "tests"]
skip = ["docs/conf.py"]

[tool.pytest.ini_options]
asyncio_mode = "strict"
Expand Down Expand Up @@ -110,3 +87,115 @@ format = "md"
md_header_level = "2"
new_fragment_template = "file:changelog.d/_template.md.jinja"
skip_fragments = "_template.md.jinja"

# The rule used with Ruff configuration is to disable every lint that has
# legitimate exceptions that are not dodgy code, rather than cluttering code
# with noqa markers. This is therefore a reiatively relaxed configuration that
# errs on the side of disabling legitimate lints.
#
# Reference for settings: https://beta.ruff.rs/docs/settings/
# Reference for rules: https://beta.ruff.rs/docs/rules/
[tool.ruff]
exclude = [
"docs/**",
]
line-length = 79
target-version = "py312"

[tool.ruff.lint]
ignore = [
"ANN101", # self should not have a type annotation
"ANN102", # cls should not have a type annotation
"ANN401", # sometimes Any is the right type
"ARG001", # unused function arguments are often legitimate
"ARG002", # unused method arguments are often legitimate
"ARG005", # unused lambda arguments are often legitimate
"BLE001", # we want to catch and report Exception in background tasks
"C414", # nested sorted is how you sort by multiple keys with reverse
"D102", # sometimes we use docstring inheritence
"D104", # don't see the point of documenting every package
"D105", # our style doesn't require docstrings for magic methods
"D106", # Pydantic uses a nested Config class that doesn't warrant docs
"D205", # our documentation style allows a folded first line
"EM101", # justification (duplicate string in traceback) is silly
"EM102", # justification (duplicate string in traceback) is silly
"FBT003", # positional booleans are normal for Pydantic field defaults
"FIX002", # point of a TODO comment is that we're not ready to fix it
"G004", # forbidding logging f-strings is appealing, but not our style
"RET505", # disagree that omitting else always makes code more readable
"PLR0911", # often many returns is clearer and simpler style
"PLR0913", # factory pattern uses constructors with many arguments
"PLR2004", # too aggressive about magic values
"PLW0603", # yes global is discouraged but if needed, it's needed
"S105", # good idea but too many false positives on non-passwords
"S106", # good idea but too many false positives on non-passwords
"S107", # good idea but too many false positives on non-passwords
"S603", # not going to manually mark every subprocess call as reviewed
"S607", # using PATH is not a security vulnerability
"SIM102", # sometimes the formatting of nested if statements is clearer
"SIM117", # sometimes nested with contexts are clearer
"TCH001", # we decided to not maintain separate TYPE_CHECKING blocks
"TCH002", # we decided to not maintain separate TYPE_CHECKING blocks
"TCH003", # we decided to not maintain separate TYPE_CHECKING blocks
"TID252", # if we're going to use relative imports, use them always
"TRY003", # good general advice but lint is way too aggressive
"TRY301", # sometimes raising exceptions inside try is the best flow

# The following settings should be disabled when using ruff format
# per https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
]
select = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"src/noteburst/handlers/**" = [
"D103", # FastAPI handlers should not have docstrings
"D401", # FastAPI handler docstrings may be API docs
]
"tests/**" = [
"C901", # tests are allowed to be complex, sometimes that's convenient
"D101", # tests don't need docstrings
"D103", # tests don't need docstrings
"PLR0915", # tests are allowed to be long, sometimes that's convenient
"PT012", # way too aggressive about limiting pytest.raises blocks
"S101", # tests should use assert
"S106", # tests are allowed to hard-code dummy passwords
"SLF001", # tests are allowed to access private members
"T201", # tests are allowed to use print
]

[tool.ruff.lint.isort]
known-first-party = ["noteburst", "tests"]
split-on-trailing-comma = false

# These are too useful as attributes or methods to allow the conflict with the
# built-in to rule out their use.
[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = [
"all",
"any",
"help",
"id",
"list",
"type",
]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.lint.pydocstyle]
convention = "numpy"
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pytest-cov
uvicorn
respx
types-PyYAML
ruff

# Documentation
documenteer[guide]>=1.0.0
Expand Down
Loading

0 comments on commit f0f657a

Please sign in to comment.