Skip to content

Commit

Permalink
switch to ruff format and rearragne order of pre-commit hooks (#23)
Browse files Browse the repository at this point in the history
Also ignore less ruff rules
  • Loading branch information
kjmeagher authored Nov 20, 2023
1 parent 4993d4d commit efdfc67
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 172 deletions.
39 changes: 17 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,42 @@ ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v3.1.0
hooks:
- id: prettier
- repo: https://github.com/fsfe/reuse-tool
rev: v2.1.0
hooks:
- id: reuse
- repo: https://github.com/psf/black
rev: 23.9.1
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: black
- id: codespell
- repo: https://github.com/asottile/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
args: [-l 100]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
- id: ruff
args: [--fix, --show-fixes]
- id: mypy
files: simweights
additional_dependencies: [numpy]
exclude: ^contrib/
- repo: https://github.com/pycqa/pylint
rev: v3.0.0
rev: v3.0.1
hooks:
- id: pylint
files: simweights
exclude: ^contrib/
additional_dependencies: [numpy, pandas]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
files: simweights
additional_dependencies: [numpy]
exclude: ^contrib/
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: codespell
args: [-L, livetime]
- id: ruff
args: [--fix, --show-fixes]
- id: ruff-format
- repo: https://github.com/PyCQA/doc8
rev: "v1.1.1"
hooks:
Expand All @@ -67,10 +63,9 @@ repos:
- id: forbid-crlf
- id: forbid-tabs
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
Expand Down
3 changes: 3 additions & 0 deletions contrib/book_simweights_testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# SPDX-License-Identifier: BSD-2-Clause

"""Script to generate the test data used by simweights testing."""

import os.path
import sys
import tarfile
Expand All @@ -15,6 +17,7 @@


def fake_event_header(frame: dict) -> None:
"""Create a fake event header so the splitter can do its thing."""
header = dataclasses.I3EventHeader()
header.run_id = 0
header.event_id = fake_event_header.event_id
Expand Down
2 changes: 2 additions & 0 deletions contrib/print_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# SPDX-License-Identifier: BSD-2-Clause

"""Script to print out values of the specified flux."""

from sys import argv

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: BSD-2-Clause

# Configuration file for the Sphinx documentation builder.
"""Configuration file for the Sphinx documentation builder."""
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
Expand Down
3 changes: 1 addition & 2 deletions examples/tutorial_corsika.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

CORSIKA_DATASET_DIR = Path("/data/sim/IceCube/2016/filtered/level2/CORSIKA-in-ice/20789/")
corsika_filelist = sorted(
str(f)
for f in CORSIKA_DATASET_DIR.glob("0000000-0000999/Level2_IC86.2016_corsika.020789.00000*.i3.zst")
str(f) for f in CORSIKA_DATASET_DIR.glob("0000000-0000999/Level2_IC86.2016_corsika.020789.00000*.i3.zst")
)

weight_keys = [
Expand Down
9 changes: 2 additions & 7 deletions examples/tutorial_nugen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ def get_most_energetic_muon(mmclist: simclasses.I3MMCTrackList) -> float:
emax = 0
for muon in list(mmclist):
particle = muon.particle
if (
particle.type in (dataclasses.I3Particle.MuMinus, dataclasses.I3Particle.MuPlus)
and particle.total_energy > emax
):
if particle.type in (dataclasses.I3Particle.MuMinus, dataclasses.I3Particle.MuPlus) and particle.total_energy > emax:
emax = particle.total_energy
return emax

Expand All @@ -43,9 +40,7 @@ def get_most_energetic_muon(mmclist: simclasses.I3MMCTrackList) -> float:
]

DATASET_DIR = Path("/data/sim/IceCube/2016/filtered/level2/neutrino-generator/21217")
filelist = sorted(
str(f) for f in DATASET_DIR.glob("0000000-0000999/Level2_IC86.2016_NuMu.021217.00000*.i3.zst")
)
filelist = sorted(str(f) for f in DATASET_DIR.glob("0000000-0000999/Level2_IC86.2016_NuMu.021217.00000*.i3.zst"))
MCmuonEnergy_nugen = np.array([])
I3MCWeightDict: dict = {k: [] for k in weight_keys}

Expand Down
48 changes: 24 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,57 @@ Source = "https://github.com/icecube/simweights"
Documentation = "https://docs.icecube.aq/simweights/main"
Collaboration = "https://icecube.wisc.edu"

[tool.black]
line-length = 108
target-version = ['py38']
[tool.pytest.ini_options]
minversion = 7.0
testpaths = ["tests"]
log_cli_level = "INFO"
xfail_strict = true
filterwarnings = ["error"]
addopts = ["-ra", "--strict-config", "--strict-markers", "--cov=simweights", "-W ignore"]

[tool.coverage.run]
source = ["simweights"]
command_line = "-m pytest"
omit = ["*/simweights/cmdline.py"]

[tool.coverage.report]
exclude_also = ["from numpy.typing import"]

[tool.codespell]
skip = '_build'
ignore-words-list = 'livetime'

[tool.mypy]
plugins = "numpy.typing.mypy_plugin"
show_error_codes = true
warn_unreachable = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]

[tool.pylint.format]
max-line-length = "108"
max-line-length = "128"

[tool.pylint.messages_control]
disable = "C0114"

[tool.pytest.ini_options]
minversion = 7.0
testpaths = ["tests"]
log_cli_level = "INFO"
xfail_strict = true
filterwarnings = ["error"]
addopts = ["-ra", "--strict-config", "--strict-markers", "--cov=simweights", "-W ignore"]

[tool.doc8]
max-line-length=108

[tool.ruff]
select = ["ALL"]
fixable = ["I"]
ignore = [
"ANN101", # missing-type-self
"ANN401", # any-type
"FBT", # flake8-boolean-trap
"INP", # flake8-no-pep420
"T20", # flake8-print
"TCH", # flake8-type-checking
"S101", # assert-used
"N801",
"PYI024",
"COM812", #confilcts with ruff formatter
"ISC001", #confilcts with ruff formatter
]
line-length = 108
line-length = 128
target-version = "py38"
namespace-packages = ["examples", "contrib", "docs"]

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.per-file-ignores]
"contrib/*" = ["D"]
"docs/*" = ["D"]
"contrib/*" = ["T201"]
"tests/*" = [
"D", # pydocstyle
"N", # pep8-naming
Expand All @@ -113,4 +109,8 @@ convention = "google"
"examples/*" = [
"D", # pydocstyle
"F401", # unused-import
"T201", # flake8-print
]

[tool.doc8]
max-line-length=128
Loading

0 comments on commit efdfc67

Please sign in to comment.