Skip to content

Commit

Permalink
use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Mar 17, 2024
1 parent 88ff491 commit 1e2e70d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
17 changes: 5 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,12 @@ repos:
hooks:
- id: black

# Python docstring formatting
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
# Ruff linter, replacement for flake8, pydocstyle, isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.3.3'
hooks:
- id: pydocstyle
files: src/pyhepmc/[^_].*\\.py

# Python linter (Flake8)
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
exclude: ^(docs/.*|tests/.*)$
- id: ruff
args: [--fix, --show-fixes]

# C++ formatting
- repo: https://github.com/pre-commit/mirrors-clang-format
Expand Down
48 changes: 30 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [
"setuptools>=46.4",
"setuptools_scm[toml]>=6.2",
"cmake>=3.13",
"wheel"
"wheel",
]
build-backend = "setuptools.build_meta"

Expand All @@ -12,11 +12,11 @@ name = "pyhepmc"
description = "Pythonic interface to the HepMC3 C++ library licensed under LGPL-v3."
maintainers = [
{ name = "Hans Dembinski" },
{ email = "[email protected]" }
{ email = "[email protected]" },
]
readme = "README.rst"
requires-python = ">=3.8"
license = {text = "BSD 3-Clause License"}
license = { text = "BSD 3-Clause License" }
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: BSD License",
Expand All @@ -25,7 +25,7 @@ classifiers = [
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Topic :: Scientific/Engineering",
"Intended Audience :: Developers"
"Intended Audience :: Developers",
]
dependencies = ["numpy"]
dynamic = ["version"]
Expand All @@ -35,18 +35,8 @@ repository = "https://github.com/scikit-hep/pyhepmc"
documentation = "https://scikit-hep.org/pyhepmc"

[project.optional-dependencies]
test = [
"pytest",
"particle",
"matplotlib"
]
doc = [
"sphinx",
"sphinx-rtd-theme",
"nbsphinx",
"ipython",
"ipykernel",
]
test = ["pytest", "particle", "matplotlib"]
doc = ["sphinx", "sphinx-rtd-theme", "nbsphinx", "ipython", "ipykernel"]

[tool.setuptools_scm]

Expand Down Expand Up @@ -75,8 +65,30 @@ source = ["pyhepmc"]
[tool.coverage.report]
exclude_lines = ["pragma: no cover"]

[tool.pydocstyle]
convention = "numpy"
[tool.ruff]
src = ["src"]

[tool.ruff.lint]
select = [
"E",
"F", # flake8
"D", # pydocstyle
]
unfixable = [
"F841", # Removes unused variables
]
extend-ignore = [
"D212", # multi-line-summary-first-line
]
pydocstyle.convention = "numpy"

[tool.ruff.lint.per-file-ignores]
"test_*.py" = ["B", "D"]
"bench/*.py" = ["D"]
"docs/*.py" = ["D"]
"cmake_ext.py" = ["D"]
"generate_*.py" = ["D"]
"setup*.py" = ["D"]

[tool.cibuildwheel]
# update skip when numpy wheels become available
Expand Down
1 change: 0 additions & 1 deletion setup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def merge_license_files():
This follows the approach of Scipy and is to keep LICENSE in repo as an
exact BSD 3-clause, to make GitHub state correctly how pyhepmc is licensed.
"""

l1 = "LICENSE"
l2 = "LICENSES_bundled"

Expand Down
3 changes: 2 additions & 1 deletion src/pyhepmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def __getattr__(name: str) -> Any:

if name in dir(io):
warnings.warn(
f"importing {name} from pyhepmc is deprecated, please import from pyhepmc.io",
f"importing {name} from pyhepmc is deprecated, "
"please import from pyhepmc.io",
category=VisibleDeprecationWarning,
stacklevel=2,
)
Expand Down
6 changes: 3 additions & 3 deletions src/pyhepmc/_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
class _SetupMeta(type):
@property
def print_errors(cls) -> bool:
"Whether to print errors or not."
"""Whether to print errors or not."""
return _Setup_print_errors() # type:ignore

@property
def print_warnings(cls) -> bool:
"Whether to print warnings or not."
"""Whether to print warnings or not."""
return _Setup_print_warnings() # type:ignore

@property
def debug_level(cls) -> int:
"Access debug level."
"""Access debug level."""
return _Setup_debug_level() # type:ignore

def __setattr__(self, name: str, value: Any) -> None:
Expand Down
8 changes: 5 additions & 3 deletions src/pyhepmc/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,22 @@ def __iter__(self: Any) -> _Iter:

# add contextmanager interface to IO classes
class ReaderAscii(ReaderAsciiBase, ReaderMixin): # type:ignore
pass
"""Reader for HepMC3 ASCII files."""


class ReaderAsciiHepMC2(ReaderAsciiHepMC2Base, ReaderMixin): # type:ignore
pass
"""Reader for HepMC2 ASCII files."""


class ReaderLHEF(ReaderLHEFBase, ReaderMixin): # type:ignore
"""Reader for LHEF files."""

_read_event_unpatched = ReaderLHEFBase.read_event
read_event = _read_event_lhef_patch


class ReaderHEPEVT(ReaderHEPEVTBase, ReaderMixin): # type:ignore
pass
"""Reader for HEPEVT files."""


WriterAscii.__enter__ = _enter
Expand Down
4 changes: 1 addition & 3 deletions src/pyhepmc/view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Visualization for GenEvent.
"""
"""Visualization for GenEvent."""

from __future__ import annotations
from pyhepmc._graphviz import Digraph
Expand Down

0 comments on commit 1e2e70d

Please sign in to comment.