diff --git a/.cruft.json b/.cruft.json index db1d057..c5adb0a 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/sunpy/package-template", - "commit": "2a6434a5c749ecde69d00b937a3fef27ecbad656", + "commit": "632ed04aee0058dd88dc6b7972ca8f8061fbd6da", "checkout": null, "context": { "cookiecutter": { @@ -36,7 +36,7 @@ ".github/workflows/zizmor.yml" ], "_template": "https://github.com/sunpy/package-template", - "_commit": "2a6434a5c749ecde69d00b937a3fef27ecbad656" + "_commit": "632ed04aee0058dd88dc6b7972ca8f8061fbd6da" } }, "directory": null diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 13e23a1..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,16 +0,0 @@ -[settings] -balanced_wrapping = true -skip = - docs/conf.py - streamtracer/__init__.py -default_section = THIRDPARTY -include_trailing_comma = true -known_astropy = astropy, asdf -known_sunpy = sunpy -known_first_party = streamtracer -length_sort = false -length_sort_sections = stdlib -line_length = 110 -multi_line_output = 3 -no_lines_before = LOCALFOLDER -sections = STDLIB, THIRDPARTY, ASTROPY, SUNPY, FIRSTPARTY, LOCALFOLDER diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 49f3ad3..dd1a746 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,10 +8,7 @@ repos: types: [python] # Define here once and then reference using YAML anchor exclude: &exclude_dirs ^streamtracer/(data|extern)/ - - repo: https://github.com/PyCQA/isort - rev: 8.0.1 - hooks: - - id: isort + - id: ruff-format types: [python] exclude: *exclude_dirs - repo: https://github.com/pre-commit/pre-commit-hooks @@ -55,13 +52,6 @@ repos: types: [python] exclude: *exclude_dirs additional_dependencies: [types-setuptools] - # Python code formatting - - repo: https://github.com/psf/black - rev: 24.4.2 - hooks: - - id: black - types: [python] - exclude: *exclude_dirs # Rust code formatting - repo: https://github.com/FeryET/pre-commit-rust rev: v1.1.0 @@ -73,6 +63,12 @@ repos: types: [rust] - id: fmt types: [rust] + - repo: https://github.com/sphinx-contrib/sphinx-lint + rev: v1.0.2 + hooks: + - id: sphinx-lint + types_or: [python, rst] + exclude: *exclude_dirs ci: autofix_prs: false autoupdate_schedule: "quarterly" diff --git a/.ruff.toml b/.ruff.toml index c5b9068..2342fe5 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -14,6 +14,7 @@ select = [ "W", "UP", "PT", + "I", "BLE", "A", "C4", @@ -56,7 +57,8 @@ extend-ignore = [ "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 + "I", # isort ] "docs/*.py" = [ "INP001", # File is part of an implicit namespace package. @@ -70,6 +72,7 @@ extend-ignore = [ "F401", # Unused import "F403", # from {name} import * used; unable to detect undefined names "F405", # {name} may be undefined, or defined from star imports + "I", # isort ] "test_*.py" = [ "E402", # Module level import not at top of cell @@ -80,3 +83,21 @@ extend-ignore = [ [lint.pydocstyle] convention = "numpy" + +[lint.isort] +default-section = "third-party" +section-order = [ + "future", + "standard-library", + "third-party", + "astropy", + "sunpy", + "first-party", + "local-folder", +] +known-first-party = ["streamtracer"] +no-lines-before = ["local-folder"] + +[lint.isort.sections] +"astropy" = ["astropy", "asdf", "gwcs", "reproject"] +"sunpy" = ["sunpy"] diff --git a/benchmarks/benchmark.py b/benchmarks/benchmark.py index f605ea4..667818e 100644 --- a/benchmarks/benchmark.py +++ b/benchmarks/benchmark.py @@ -1,5 +1,5 @@ -import time import importlib.metadata +import time import matplotlib.pyplot as plt import numpy as np @@ -32,9 +32,7 @@ times += [np.mean(dts)] -pd.DataFrame({"nseeds": seedlist, "time": times}).to_csv( - f"v{__version__.replace('.', '')}.csv" -) +pd.DataFrame({"nseeds": seedlist, "time": times}).to_csv(f"v{__version__.replace('.', '')}.csv") fig, ax = plt.subplots() diff --git a/python/streamtracer/streamline.py b/python/streamtracer/streamline.py index ddac445..0113030 100755 --- a/python/streamtracer/streamline.py +++ b/python/streamtracer/streamline.py @@ -45,17 +45,11 @@ def __init__( grid_coords=None, ): if grid_spacing is not None and grid_coords is not None: - raise ValueError( - 'Only one of "grid_spacing" and "grid_coords" can be specified.' - ) + raise ValueError('Only one of "grid_spacing" and "grid_coords" can be specified.') if grid_spacing is None and grid_coords is None: - raise ValueError( - 'One of "grid_spacing" and "grid_coords" must be specified.' - ) + raise ValueError('One of "grid_spacing" and "grid_coords" must be specified.') if grid_coords is not None and origin_coord is not None: - raise ValueError( - 'Specifying both "grid_coords" and "origin_coord" is ambiguous.' - ) + raise ValueError('Specifying both "grid_coords" and "origin_coord" is ambiguous.') self.grid_spacing = grid_spacing self.vectors = vectors self.cyclic = cyclic @@ -74,9 +68,7 @@ def grid_spacing(self, val): if val is not None: val = np.array(val) if val.shape != (3,): - raise ValueError( - f"grid spacing must have shape (3,), got " f"{val.shape}" - ) + raise ValueError(f"grid spacing must have shape (3,), got {val.shape}") self._grid_spacing = val @property @@ -91,9 +83,7 @@ def vectors(self, val): if len(val.shape) != 4: raise ValueError("vectors must be a 4D array") if val.shape[-1] != 3: - raise ValueError( - "vectors must have shape (nx, ny, nz, 3), " f"got {val.shape}" - ) + raise ValueError(f"vectors must have shape (nx, ny, nz, 3), got {val.shape}") self._vectors = val @property @@ -111,10 +101,7 @@ def coords(self, val): for i, dim in zip(range(3), ["x", "y", "z"]): shape = np.array(val[i]).shape if shape != (self.vectors.shape[i],): - raise ValueError( - f"Expected {self.vectors.shape[i]} {dim} " - f"coordinates but got {shape}" - ) + raise ValueError(f"Expected {self.vectors.shape[i]} {dim} coordinates but got {shape}") self._coords = val @property @@ -160,18 +147,13 @@ def origin_coord(self, val): if self.grid_spacing is not None: self._origin_coord = np.array([0, 0, 0]) else: - self._origin_coord = np.array( - [self.xcoords[0], self.ycoords[0], self.zcoords[0]] - ) + self._origin_coord = np.array([self.xcoords[0], self.ycoords[0], self.zcoords[0]]) else: self._origin_coord = np.array(val) def _get_coords(self, i): if self.grid_spacing is not None: - return ( - self.grid_spacing[i] * np.arange(self.vectors.shape[i]) - + self.origin_coord[i] - ) + return self.grid_spacing[i] * np.arange(self.vectors.shape[i]) + self.origin_coord[i] return self.coords[i] @property @@ -263,7 +245,7 @@ def max_steps(self, val): raise ValueError(f"max_steps must be an integer (got {type(val)})") if not val > 0: - raise ValueError("max_steps must be greater than zero " f"(got {val})") + raise ValueError(f"max_steps must be greater than zero (got {val})") self._max_steps = val