Skip to content

Commit

Permalink
STYLE: Transition to ruff to enforce import statement sorting
Browse files Browse the repository at this point in the history
Prefer using `ruff` instead of `isort` to enforce import statement
sorting.

`ruff`'s import sorting rules are near-equivalent to isort's when using
`isort`'s `profile="black"`:
https://docs.astral.sh/ruff/faq/#how-does-ruffs-import-sorting-compare-to-isort

Change the `tool.isort` section in `pyproject` so that the correspoding
tasks fall under the responsibility of `flake8`.

Adapt accordingly the pre-commit hook config file to apply the import
sorting to local files prior to commits.

Add a GHA workflow to apply the pre-commit hooks in order to ensure that
files modified across commits/in PRs comply with the expected
formatting.

Add the `--allow-missing-credentials` flag to the
`detect-aws-credentials` hook in the `pre-commit` config file so that
`pre-commit` does not complain about not finding AWS credentials if none
exist.

Make the necessary style changes to make the `ruff` linter happy.
  • Loading branch information
jhlegarreta committed Apr 22, 2024
1 parent a4d6792 commit 33ee086
Show file tree
Hide file tree
Showing 99 changed files with 408 additions and 373 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/check_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: code format

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
pre-commit:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
requires: ['latest']

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install and run pre-commit hooks
uses: pre-commit/[email protected]
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ repos:
# rev: v0.9.1
# hooks:
# - id: blue
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
Expand All @@ -49,3 +45,9 @@ repos:
- importlib_resources
args: ["fury"]
pass_filenames: false
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
# Run the linter
- id: ruff
args: [ --fix ]
2 changes: 1 addition & 1 deletion docs/examples/viz_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
the main functions using the following modules.
"""

import numpy as np
from dipy.data.fetcher import fetch_bundles_2_subjects, read_bundles_2_subjects

###############################################################################
Expand All @@ -36,6 +35,7 @@
#
# First we need to fetch and load some datasets.
from dipy.tracking.streamline import Streamlines
import numpy as np

from fury import actor, ui, window

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/viz_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
which provides metrics and bundles.
"""

import numpy as np
from dipy.data import fetch_bundles_2_subjects, read_bundles_2_subjects
from dipy.tracking.streamline import length, transform_streamlines
import numpy as np

from fury import actor, window

Expand Down
7 changes: 3 additions & 4 deletions docs/examples/viz_dt_ellipsoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
"""
import itertools

import numpy as np

from dipy.io.image import load_nifti
import numpy as np

from fury import window, actor, ui
from fury.actor import _fa, _color_fa
from fury import actor, ui, window
from fury.actor import _color_fa, _fa
from fury.data import fetch_viz_dmri, read_viz_dmri
from fury.primitive import prim_sphere

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/viz_fiber_odf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
orientation distribution functions (ODF) using fury's odf_slicer.
"""

from dipy.data import get_sphere
from dipy.reconst.shm import sh_to_sf_matrix
import nibabel as nib

# First, we import some useful modules and methods.
import numpy as np
from dipy.data import get_sphere
from dipy.reconst.shm import sh_to_sf_matrix

from fury import actor, ui, window
from fury.data import fetch_viz_dmri, fetch_viz_icons, read_viz_dmri
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/viz_multithread.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
adds and removes elements from the scene.
"""

import time
from threading import Thread
import time

import numpy as np

Expand Down
4 changes: 1 addition & 3 deletions docs/examples/viz_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

import numpy as np

from fury import actor
from fury import colormap as cmap
from fury import window
from fury import actor, colormap as cmap, window
from fury.data import fetch_viz_wiki_nw

###############################################################################
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/viz_network_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import numpy as np

from fury import actor
from fury import colormap as cmap
from fury import window
from fury import actor, colormap as cmap, window
from fury.utils import compute_bounds, update_actor, vertices_from_actor

###############################################################################
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/viz_no_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# multiprocessing.set_start_method('spawn')
import numpy as np

from fury import actor
from fury import colormap as cmap
from fury import window
from fury import actor, colormap as cmap, window
from fury.data.fetcher import fetch_viz_wiki_nw
from fury.stream.client import FuryStreamClient
from fury.stream.server.main import web_server_raw_array
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/viz_roi_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from dipy.reconst.shm import CsaOdfModel

try:
from dipy.tracking.local import LocalTracking
from dipy.tracking.local import (
LocalTracking,
ThresholdTissueClassifier as ThresholdStoppingCriterion,
)
except ImportError:
from dipy.tracking.stopping_criterion import ThresholdStoppingCriterion
from dipy.tracking.local_tracking import LocalTracking
from dipy.tracking.stopping_criterion import ThresholdStoppingCriterion

from dipy.tracking import utils
from dipy.tracking.streamline import Streamlines
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/viz_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import os

import nibabel as nib
from dipy.data import fetch_bundles_2_subjects
import nibabel as nib

from fury import actor, ui, window

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/viz_spinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
First, some imports.
"""
import numpy as np

from fury import actor, ui, utils, window
from fury.data import fetch_viz_icons
import numpy as np

##############################################################################
# First we need to fetch some icons that are included in FURY.
Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import vtk
from vtk.util import numpy_support

import fury.primitive as fp
from fury import actor, window
import fury.primitive as fp
from fury.utils import (
get_actor_from_polydata,
numpy_to_vtk_colors,
Expand Down
4 changes: 1 addition & 3 deletions docs/experimental/viz_molecular_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

import numpy as np

from fury import actor
from fury import molecular as mol
from fury import ui, window
from fury import actor, molecular as mol, ui, window

###############################################################################
# Downloading the PDB file of the protein to be rendered (the user can change
Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_multisdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import vtk
from vtk.util import numpy_support

from fury import actor, window
import fury.primitive as fp
import fury.shaders as fs
from fury import actor, window
from fury.utils import get_actor_from_primitive

verts, faces = fp.prim_box()
Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_canvas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import vtk
from scipy.spatial import Delaunay
import vtk
from vtk.util import numpy_support

from fury.utils import (
Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_canvas_sk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import vtk
from viz_shader_canvas import cube, disk, rectangle, rectangle2, square
import vtk

from fury import actor, window

Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_faces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import vtk
from viz_shader_canvas import glyph_dot
import vtk

from fury import actor, window

Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_parallax_truchet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vtk
from viz_shader_canvas import cube
import vtk

from fury import window

Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_perlin_noise.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import vtk
from scipy.spatial import Delaunay
from viz_shader_canvas import surface
import vtk

from fury import window

Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_sines_1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vtk
from viz_shader_canvas import cube
import vtk

from fury import window

Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_square.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import vtk
from viz_shader_canvas import cube, square
import vtk

from fury import actor, window

Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_texture.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import vtk
from viz_shader_canvas import cube
import vtk

from fury import window
from fury.utils import rgb_to_vtk
Expand Down
2 changes: 1 addition & 1 deletion docs/experimental/viz_shader_wave.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vtk
from viz_shader_canvas import cube, disk, rectangle, square
import vtk

from fury import actor, window

Expand Down
4 changes: 2 additions & 2 deletions docs/source/_static/css/comp-soft.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
width: var(--s);
min-width: var(--s);
margin: var(--m) var(--m) 0;
height: var(--s);
height: var(--s);
font-size:initial;
border-radius: 50%;
background: white;
Expand All @@ -73,4 +73,4 @@

.comp-soft-image-holder img {
max-width: 80%;
}
}
4 changes: 2 additions & 2 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ html[data-theme="light"] {
--pst-color-navbar-link-hover: rgb(77, 171, 207);

}
/* Log:3/3/24
/* Log:3/3/24
With updating the pydata-theme, there was issue with the <a> elements (They were underlined and colored by default, unlike previously), adding this code snippet helped fix the issue.
You wouldn't want the links to be colored as there is a dark mode now, which will conflict with the color that pydata is assigning*/

Expand All @@ -171,4 +171,4 @@ a, a:visited {
}
a:hover, a:active {
text-decoration: underline;
}
}
2 changes: 1 addition & 1 deletion docs/source/_static/css/sponsors.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
.cite-wrapper {
margin: 20px 20px 0;
}
}
}
2 changes: 1 addition & 1 deletion docs/source/_static/css/util.css
Original file line number Diff line number Diff line change
Expand Up @@ -2961,4 +2961,4 @@ iframe {border: none;}
.g-m-rows-3 {
grid-template-rows: repeat(3, 1fr);
}
}
}
2 changes: 1 addition & 1 deletion docs/source/_static/vendor/display-card.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

.h-card__divider {
margin-top: -10px;

}

.h-card__data-background {
Expand Down
Loading

0 comments on commit 33ee086

Please sign in to comment.