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: modernize Ruff config, use ruff-format #536

Merged
merged 2 commits into from
Nov 27, 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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
Expand Down
7 changes: 2 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ repos:
- id: debug-statements
- id: end-of-file-fixer

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black-jupyter

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.6"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
Expand Down
5 changes: 1 addition & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

|Scikit-HEP| |PyPI version| |Conda-forge version| |Zenodo DOI|

|GitHub Actions Status: CI| |Code Coverage| |Code style: black|
|GitHub Actions Status: CI| |Code Coverage|

|Binder|

Expand Down Expand Up @@ -489,8 +489,5 @@ are those of the authors and do not necessarily reflect the views of the Nationa
.. |Code Coverage| image:: https://codecov.io/gh/scikit-hep/particle/graph/badge.svg?branch=master
:target: https://codecov.io/gh/scikit-hep/particle?branch=master

.. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black

.. |Binder| image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/scikit-hep/particle/master?urlpath=lab/tree/notebooks/ParticleDemo.ipynb
42 changes: 22 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ warn_unused_ignores = true
python_version = "3.9"
files = "src"
strict = true
show_error_codes = true
warn_unreachable = true
enable_error_code = [
"ignore-without-code",
Expand All @@ -98,6 +97,7 @@ minversion = "6.0"
testpaths = ["tests"]
junit_family = "xunit2"
log_cli_level = "info"
xfail_strict = true
addopts = [
"--benchmark-disable",
"-ra",
Expand Down Expand Up @@ -143,9 +143,11 @@ messages_control.disable = [


[tool.ruff]
select = [
"E", "F", "W", # flake8
"B", "B904", # flake8-bugbear
src = ["src"]

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
Expand All @@ -163,23 +165,23 @@ select = [
"YTT", # flake8-2020
]
ignore = [
"B905",
"E402",
"E501",
"RUF001", # Ambiguous unicode
"RUF002", # Ambiguous unicode docstring
"PLR", # Design related pylint codes
"PT013", # Importing approx from pytest is fine
]
src = ["src"]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
"RUF001", # Ambiguous unicode
"RUF002", # Ambiguous unicode docstring
"PLR2004", # Magic value used in comparison
"PLR09", # Too many X
"ISC001", # Conflicts with the formatter
"E741", # Ambiguous variable name
]
isort.required-imports = ["from __future__ import annotations"]
mccabe.max-complexity = 24

[tool.ruff.mccabe]
max-complexity = 24

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"src/particle/__main__.py" = ["T20"]
"tests/**.py" = [
"PT013", # Importing approx from pytest is fine
"E402", # Module level import not at top of file (doesn't recognise pytest.importorskip)
]


[tool.repo-review]
ignore = ["RTD"]
17 changes: 12 additions & 5 deletions src/particle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@

# Direct access to Particle literals
# Direct access to Particle (the CSV file is not read until a particle is accessed)
from .particle import InvalidParticle, Particle, ParticleNotFound, literals
# Direct access to handy LaTeX to HTML particle name conversions
# Direct access to kinematics functions
from .particle import (
InvalidParticle,
Particle,
ParticleNotFound,
latex_to_html_name,
lifetime_to_width,
literals,
width_to_lifetime,
)
from .particle.enums import Charge, Inv, Parity, SpinType, Status

# Direct access to PDGID and other ID classes
Expand All @@ -23,12 +33,9 @@
# Convenient access to the version number
from .version import version as __version__

# Literals direct access
sys.modules["particle.literals"] = literals

# Direct access to handy LaTeX to HTML particle name conversions
# Direct access to kinematics functions
from .particle import latex_to_html_name, lifetime_to_width, width_to_lifetime

__all__ = (
"Charge",
"Corsika7ID",
Expand Down
2 changes: 1 addition & 1 deletion src/particle/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class Particle:
minus_one, converter=_none_or_positive_converter
)
_three_charge: Charge | None = attr.ib(Charge.u, converter=Charge) # charge * 3
I: float | None = attr.ib(none_float, converter=_isospin_converter) # noqa: E741
I: float | None = attr.ib(none_float, converter=_isospin_converter)
# J = attr.ib(None) # Total angular momentum
G = attr.ib(Parity.u, converter=Parity) # Parity: '', +, -, or ?
P = attr.ib(Parity.u, converter=Parity) # Space parity
Expand Down