From 71d1901831ee246b9d972398b2afef3973d239ac Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 3 Feb 2025 20:56:05 -0800 Subject: [PATCH] update pyproject.toml for `ruff format` (#48823) Add ruff configuration to `pyproject.toml`. This allows `ruff format` in the Spack repository to format all the files we care about, with our line length of 99, the exceptions we already put in place, and excluding things we don't auto-format, like vendored dependencies. Right now it'll reformat 175 or so files, but only slightly, in places where `ruff` differs from `black`. For the most part I like the ruff format decisions better than `black`, but none of the changes seem too severe. This does not change `spack style` -- I figure that can come later but this at least will let people start playing with `ruff`. --------- Signed-off-by: Todd Gamblin --- lib/spack/spack/package.py | 2 +- pyproject.toml | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 910ba1b62e1..bf2056d826d 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) -# flake8: noqa: F401 +# flake8: noqa: F401, E402 """spack.package defines the public API for Spack packages, by re-exporting useful symbols from other modules. Packages should import this module, instead of importing from spack.* directly to ensure forward compatibility with future versions of Spack.""" diff --git a/pyproject.toml b/pyproject.toml index 66c384f6fac..04dfa47ebcf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [project] name="spack" description="The spack package manager" +requires-python=">=3.6" dependencies=[ "clingo", "setuptools", @@ -67,9 +68,42 @@ features = [ "ci", ] +[tool.ruff] +line-length = 99 +extend-include = ["bin/spack"] +extend-exclude = ["lib/spack/external", "*.pyi"] + +[tool.ruff.format] +skip-magic-trailing-comma = true + +[tool.ruff.lint] +extend-select = ["I"] +ignore = ["E731", "E203"] + +[tool.ruff.lint.isort] +split-on-trailing-comma = false +section-order = [ + "future", + "standard-library", + "third-party", + "archspec", + "llnl", + "spack", + "first-party", + "local-folder", +] + +[tool.ruff.lint.isort.sections] +spack = ["spack"] +archspec = ["archspec"] +llnl = ["llnl"] + +[tool.ruff.lint.per-file-ignores] +"var/spack/repos/*/package.py" = ["F403", "F405", "F811", "F821"] +"*-ci-package.py" = ["F403", "F405", "F821"] + [tool.black] line-length = 99 -target-version = ['py36', 'py37', 'py38', 'py39', 'py310'] include = '(lib/spack|var/spack/repos)/.*\.pyi?$|bin/spack$' extend-exclude = 'lib/spack/external' skip_magic_trailing_comma = true