Skip to content

Commit

Permalink
Extended ruff linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Nov 11, 2024
1 parent 6ced580 commit ef9a519
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/sunpy/package-template",
"commit": "51fb616094a4d7577c8898445aa50effb89afa31",
"commit": "75f84c4adf1753af67967930c3335bc73bca9bf5",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -16,7 +16,7 @@
"enable_dynamic_dev_versions": "n",
"include_example_code": "n",
"include_cruft_update_github_workflow": "y",
"use_extended_ruff_linting": "n",
"use_extended_ruff_linting": "y",
"_sphinx_theme": "sunpy",
"_parent_project": "",
"_install_requires": "",
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/label_sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Label Sync
on:
workflow_dispatch:
schedule:
# ┌───────── minute (0 - 59)
# │ ┌───────── hour (0 - 23)
# │ │ ┌───────── day of the month (1 - 31)
# │ │ │ ┌───────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────── day of the week (0 - 6 or SUN-SAT)
- cron: '0 0 * * *' # run every day at midnight UTC

# Give permissions to write issue labels
permissions:
issues: write

jobs:
label_sync:
runs-on: ubuntu-latest
name: Label Sync
steps:
- uses: srealmoreno/label-sync-action@850ba5cef2b25e56c6c420c4feed0319294682fd
with:
config-file: https://raw.githubusercontent.com/sunpy/.github/main/labels.yml
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# This should be before any formatting hooks like isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.1"
rev: "v0.7.2"
hooks:
- id: ruff
args: ["--fix"]
Expand Down
63 changes: 45 additions & 18 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,72 @@ select = [
"W",
"UP",
"PT",
"BLE",
"A",
"C4",
"INP",
"PIE",
"T20",
"RET",
"TID",
"PTH",
"PD",
"PLC",
"PLE",
"FLY",
"NPY",
"PERF",
"RUF",
]
extend-ignore = [
# pycodestyle
# pycodestyle (E, W)
"E501", # ignore line length will use a formatter instead
"E712", # Avoid equality comparisons to True; use if {cond}: for truth checks
"E721", # type comparison Use is and is not for type comparisons, or isinstance() for isinstance checks
# upgrades
# pyupgrade (UP)
"UP038", # Use | in isinstance - not compatible with models and is slower
# pytest (PT)
"PT001", # Always use pytest.fixture()
"PT004", # Fixtures which don't return anything should have leading _
"PT011", # except(ValueRaises) is too broad
"PT023", # Always use () on pytest decorators
# flake8-pie
# flake8-pie (PIE)
"PIE808", # Disallow passing 0 as the first argument to range
# flake8-use-pathlib
# flake8-use-pathlib (PTH)
"PTH123", # open() should be replaced by Path.open()
# Ruff
# Ruff (RUF)
"RUF003", # Ignore ambiguous quote marks, doesn't allow ' in comments
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF013", # PEP 484 prohibits implicit `Optional`
"RUF015", # Prefer `next(iter(...))` over single element slice
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF013", # PEP 484 prohibits implicit `Optional`
"RUF015", # Prefer `next(iter(...))` over single element slice
]

[lint.per-file-ignores]
# Part of configuration, not a package.
"setup.py" = ["INP001"]
"conftest.py" = ["INP001"]
"setup.py" = [
"INP001", # File is part of an implicit namespace package.
]
"conftest.py" = [
"INP001", # File is part of an implicit namespace package.
]
"docs/conf.py" = [
"E402" # Module imports not at top of file
"E402" # Module imports not at top of file
]
"docs/*.py" = [
"INP001", # Implicit-namespace-package. The examples are not a package.
"INP001", # File is part of an implicit namespace package.
]
"examples/**.py" = [
"T201", # allow use of print in examples
"INP001", # File is part of an implicit namespace package.
]
"__init__.py" = [
"E402", # Module level import not at top of cell
"F401", # Unused import
"F403", # from {name} import * used; unable to detect undefined names
"F405", # {name} may be undefined, or defined from star imports
]
"test_*.py" = [
"E402", # Module level import not at top of cell
]
"benchmarks/*.py" = [
"NPY002", # TODO: Generator API
]
"__init__.py" = ["E402", "F401", "F403"]
"test_*.py" = ["B011", "D", "E402", "PGH001", "S101"]

[lint.pydocstyle]
convention = "numpy"
1 change: 0 additions & 1 deletion benchmarks/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
dts.append(time.time() - t)
assert len(tracer.xs) == nseeds
times += [np.mean(dts)]
print(nseeds, times[-1] / nseeds, times[-1])


pd.DataFrame({"nseeds": seedlist, "time": times}).to_csv(
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/benchmark_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
"210dev0": "v2.1 (Rust Parallel)",
}

files = Path(".").glob("v*.csv")
files = Path().glob("v*.csv")

for file in files:
label = version_names.get(file.stem[1:], file.stem)
data = pd.read_csv(file)
print(data)

ax.plot(data["nseeds"], data["time"], label=label, marker="o")

Expand Down
3 changes: 1 addition & 2 deletions python/streamtracer/streamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ def _get_coords(self, i):
self.grid_spacing[i] * np.arange(self.vectors.shape[i])
+ self.origin_coord[i]
)
else:
return self.coords[i]
return self.coords[i]

@property
def xcoords(self):
Expand Down
Empty file.
8 changes: 4 additions & 4 deletions python/streamtracer/tests/test_streamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,18 @@ def test_invalid_max_steps(val, errstr):


# Paramatrize to make sure behaviour is same in x,y,z directions
@pytest.mark.parametrize("dir", [0, 1, 2])
def test_bounds(dir):
@pytest.mark.parametrize("dirs", [0, 1, 2])
def test_bounds(dirs):
v = np.zeros((3, 3, 3, 3))
# Make all vectors point along the specified dimension
v[:, :, :, dir] = 1
v[:, :, :, dirs] = 1
spacing = [1, 1, 1]
grid = VectorGrid(v, spacing)

seed = np.array([[0.5, 0.5, 0.5]])
tracer = StreamTracer(max_steps=10, step_size=1.0)
tracer.trace(seed, grid)
expected = np.roll(np.array([1.5, 0.5, 0.5]), dir)
expected = np.roll(np.array([1.5, 0.5, 0.5]), dirs)
assert (tracer.xs[0][-1, :] == expected).all()
expected = np.array([0.5, 0.5, 0.5])
assert (tracer.xs[0][0, :] == expected).all()
Expand Down

0 comments on commit ef9a519

Please sign in to comment.