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

chore: Move to using Ruff for pre-commit #2124

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

32 changes: 8 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ repos:
# exclude generated files
exclude: ^validation/|\.dtd$|\.xml$

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py38-plus"]

- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
hooks:
- id: absolufy-imports
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.255"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/psf/black
rev: 23.1.0
Expand All @@ -48,18 +43,6 @@ repos:
- id: blacken-docs
additional_dependencies: [black==23.1.0]

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
kratsg marked this conversation as resolved.
Show resolved Hide resolved

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
args: ["--count", "--statistics"]
additional_dependencies: [flake8-encodings==0.5.0.post1]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
# check the oldest and newest supported Pythons
Expand All @@ -78,8 +61,9 @@ repos:
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.3
hooks:
- id: nbqa-pyupgrade
additional_dependencies: [pyupgrade==3.3.1]
- id: nbqa-ruff
additional_dependencies: [ruff==0.0.253]
args: ["--extend-ignore=F821,F401,F841,F811"]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
Expand Down
28 changes: 22 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ precision = 1
sort = "cover"
show_missing = true

[tool.nbqa.mutate]
pyupgrade = 1
Comment on lines -225 to -226
Copy link
Member

Choose a reason for hiding this comment

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

A note to self, the reason this is safe to remove is that the option was deprecated in v1.0.0. c.f. https://github.com/nbQA-dev/nbQA/blob/26f3ce04cd29bdfcda487fefdbae78925e80a5ff/nbqa/cmdline.py#L37


[tool.nbqa.addopts]
pyupgrade = ["--py38-plus"]

[tool.mypy]
files = "src"
python_version = "3.10"
Expand Down Expand Up @@ -278,3 +272,25 @@ module = [
'pyhf.tensor.pytorch_backend.*',
]
ignore_errors = true

[tool.ruff]
select = [
"E", "F", "W", # flake8
"UP", # pyupgrade
"RUF", # Ruff-specific
"TID", # flake8-tidy-imports
]
line-length = 88
ignore = [
"E402",
"E501",
"RUF001", # String contains ambiguous unicode character
"RUF005", # unpack-instead-of-concatenating-to-collection-literal
]
target-version = "py38"
src = ["src"]
typing-modules = ["pyhf.typing"]
unfixable = [
"F841", # Removes unused variables
]
flake8-tidy-imports.ban-relative-imports = "all"
2 changes: 1 addition & 1 deletion src/pyhf/cli/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def inspect(workspace, output_file, measurement):
)

# summary
fmtStr = '{{0: >{0:d}s}} {{1:s}}'.format(maxlen + len('Summary'))
fmtStr = '{{: >{:d}s}} {{:s}}'.format(maxlen + len('Summary'))
henryiii marked this conversation as resolved.
Show resolved Hide resolved
click.echo(fmtStr.format(' Summary ', ''))
click.echo(fmtStr.format('-' * 18, ''))
fmtStr = f'{{0: >{maxlen:d}s}} {{1:s}}'
Expand Down