Code cleanup: Apply Ruff for formatting and linting - #173
Conversation
…ed to be built as packages
There was a problem hiding this comment.
Pull request overview
This PR applies Ruff formatting/linting across the repository and includes a handful of small refactors needed to satisfy the chosen Ruff ruleset (notably around imports, logging, test determinism, and shell-out usage).
Changes:
- Standardize formatting/linting via Ruff (including import sorting) and add per-folder Ruff configs for
tests/andexamples/. - Refactor several modules/tests for determinism and safer operations (e.g., pytest RNG fixture, avoid
os.system, structured logging). - Restructure/clarify public exports via
__all__in key packages and adjust some simulator factory entrypoints.
Reviewed changes
Copilot reviewed 171 out of 173 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Lockfile updated for new deps (e.g., ffmpeg-python, future, typing-extensions). |
| pyproject.toml | Adds deps (ffmpeg-python, typing-extensions), expands Ruff to select=["ALL"], and adjusts line length/excludes. |
| justfile | Adds format/check tasks and makes pytest invocation more verbose. |
| README.md | Adds MacOS-specific pystencils/OpenMP troubleshooting section. |
| .gitignore | Ignores .vscode/. |
| .coveragerc | Adjusts omit list (no longer omits rod_viz.py). |
| tests/ruff.toml | Ruff config for tests (extends root; ignores docstyle/namespace/assert rules). |
| tests/conftest.py | Adds deterministic rng fixture for tests. |
| tests/test_utils/test_restart.py | Uses helper cleanup, f-strings, and formatting updates. |
| tests/test_utils/test_precision.py | Formatting-only update to pytest.raises. |
| tests/test_simulator/test_immersed_body/test_immersed_body_forcing_grid.py | Strengthens logging assertions by checking emitted logger records. |
| tests/test_simulator/test_immersed_body/rigid_body/test_derived_rigid_bodies.py | Avoids mutable default args; asserts warnings via log records; formatting updates. |
| tests/test_simulator/test_immersed_body/cosserat_rod/test_cosserat_rod_flow_interaction.py | Import order formatting. |
| tests/test_simulator/test_flow/test_passive_transport_flow_simulators.py | Uses rng fixture instead of global np.random; minor formatting. |
| tests/test_simulator/test_flow/test_flow_simulators_3d.py | Switches to create_unbounded_flow_simulator_3d, adds rng usage, and updates cfl kwarg. |
| tests/test_simulator/test_flow/test_flow_simulators_2d.py | Switches to create_unbounded_flow_simulator_2d and adds rng usage. |
| tests/test_numeric/test_immersed_boundary_ops/test_brinkmann_boundary_forcing.py | Uses rng fixture; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_vorticity_stretching_flux_3d.py | Uses injected RNG; reshapes random generation; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_update_vorticity_from_velocity_forcing_3d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_laplacian_filter_3d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_elementwise_ops_3d.py | Import ordering and formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_divergence_3d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_diffusion_timestep_3d.py | Uses injected RNG; small refactors/formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_diffusion_flux_3d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_curl_3d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_char_func_from_level_set_3d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_3d/test_brinkmann_penalise_3d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_update_vorticity_from_velocity_forcing_2d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_penalise_field_boundary_2d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_outplane_field_curl_2d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_inplane_field_curl_2d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_elementwise_ops_2d.py | Import ordering and formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_diffusion_timestep_2d.py | Uses injected RNG; refactors helper solution signature; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_diffusion_flux_2d.py | Uses injected RNG; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_char_func_from_level_set_2d.py | Uses injected RNG; refactors solution signature; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_advection_timestep_2d.py | Uses injected RNG; refactors solution signature; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_stencil_ops_2d/test_advection_flux_2d.py | Uses injected RNG; refactors solution signature; formatting cleanup. |
| tests/test_numeric/test_eulerian_grid_ops/test_poisson_solver_3d/test_fft_kernel_3d.py | Uses injected RNG; import cleanup and formatting. |
| tests/test_numeric/test_eulerian_grid_ops/test_poisson_solver_2d/test_fft_kernel_2d.py | Uses injected RNG; type annotations; formatting cleanup. |
| sopht/init.py | Adds NullHandler to avoid “No handler found” warnings. |
| sopht/utils/restart_sim.py | Uses pathlib and module logger; avoids print; improves exception messages. |
| sopht/utils/pyst_kernel_config.py | Improves error messages/types; minor signature typing; formatting cleanup. |
| sopht/utils/precision.py | Simplifies control flow; improves error message handling; formatting cleanup. |
| sopht/utils/post_process.py | Replaces shelling-out with ffmpeg-python + pathlib cleanup/moves. |
| sopht/utils/lab_cmap.py | Import order + small return simplification. |
| sopht/utils/field.py | Normalizes TODO comment formatting. |
| sopht/utils/init.py | Adds __all__ and reorganizes exports. |
| sopht/simulator/immersed_body/rigid_body/rigid_body_flow_interaction.py | Uses explicit imports, typing updates, and override. |
| sopht/simulator/immersed_body/rigid_body/derived_rigid_bodies.py | Logging cleanup, override, super() modernization, and message formatting. |
| sopht/simulator/immersed_body/rigid_body/init.py | Removes re-exports; replaces with module docstring. |
| sopht/simulator/immersed_body/immersed_body_forcing_grid.py | Uses module logger; updates warning formatting. |
| sopht/simulator/immersed_body/immersed_body_flow_interaction.py | Logging restructuring; typing updates; minor return simplification. |
| sopht/simulator/immersed_body/flow_forces.py | Import refactor and override usage; formatting cleanup. |
| sopht/simulator/immersed_body/cosserat_rod/cosserat_rod_flow_interaction.py | Uses explicit imports, typing updates, and override. |
| sopht/simulator/immersed_body/cosserat_rod/init.py | Removes re-exports; replaces with module docstring. |
| sopht/simulator/immersed_body/cosserat_rod_cpp/cosserat_rod_cpp_forcing_grids.py | Removes unused/dead module content. |
| sopht/simulator/immersed_body/cosserat_rod_cpp/cosserat_rod_cpp_flow_interaction.py | Removes unused/dead module content. |
| sopht/simulator/immersed_body/cosserat_rod_cpp/init.py | Removes re-exports for deleted CPP modules. |
| sopht/simulator/immersed_body/init.py | Replaces star exports with explicit exports and __all__. |
| sopht/simulator/flow/flow_simulators_3d.py | Renames factory to create_unbounded_flow_simulator_3d and switches CFL→cfl. |
| sopht/simulator/flow/flow_simulators_2d.py | Renames factory to create_unbounded_flow_simulator_2d and switches CFL→cfl. |
| sopht/simulator/flow/init.py | Reworks exports and adds __all__. |
| sopht/simulator/init.py | Replaces star exports with explicit exports and __all__. |
| sopht/numeric/immersed_boundary_ops/VirtualBoundaryForcing.py | Replaces assert with ValueError; formatting cleanup. |
| sopht/numeric/immersed_boundary_ops/experimental/BrinkmannBoundaryForcing.py | Replaces assert with ValueError; formatting cleanup. |
| sopht/numeric/immersed_boundary_ops/experimental/init.py | Adds module docstring. |
| sopht/numeric/immersed_boundary_ops/init.py | Adds explicit __all__ and export ordering. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/vorticity_stretching_timestep_3d.py | Imports cleanup + typing (collections.abc.Callable) + formatting. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/vorticity_stretching_flux_3d.py | Imports cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/divergence_3d.py | Imports cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/diffusion_timestep_3d.py | Imports cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/diffusion_flux_3d.py | Imports cleanup + improved error message handling. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/curl_3d.py | Imports cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/char_func_from_level_set_3d.py | Simplifies to direct return of compiled kernel; imports cleanup. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/brinkmann_penalise_3d.py | Imports cleanup + improved error message handling. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/advection_timestep_3d.py | Imports cleanup + improved error message handling. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/advection_flux_3d.py | Imports cleanup + comment formatting updates. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_3d/init.py | Removes re-export surface (keeps docstring only). |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/update_vorticity_from_velocity_forcing_2d.py | Imports cleanup + TODO comment normalization. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/penalise_field_boundary_2d.py | Replaces assert with ValueError; imports/formatting cleanup. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/outplane_field_curl_2d.py | Imports cleanup + TODO comment normalization. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/inplane_field_curl_2d.py | Minor signature formatting and kernel expression formatting. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/diffusion_timestep_2d.py | Imports cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/diffusion_flux_2d.py | Imports cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/char_func_from_level_set_2d.py | Simplifies to direct return of compiled kernel; imports cleanup. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/brinkmann_penalise_2d.py | Improved error message handling; formatting cleanup. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/advection_timestep_2d.py | Imports cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/advection_flux_2d.py | Imports cleanup + TODO comment normalization. |
| sopht/numeric/eulerian_grid_ops/stencil_ops_2d/init.py | Removes re-export surface (keeps docstring only). |
| sopht/numeric/eulerian_grid_ops/poisson_solver_3d/UnboundedPoissonSolverPYFFTW3D.py | Formatting cleanup + TODO comment normalization. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_3d/scipy_fft_3d.py | Formatting cleanup. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_3d/FFTPyFFTW3D.py | Formatting cleanup. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_3d/FastDiagPoissonSolver3D.py | Typing import cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_3d/init.py | Removes re-export surface (keeps docstring only). |
| sopht/numeric/eulerian_grid_ops/poisson_solver_2d/UnboundedPoissonSolverPYFFTW2D.py | Formatting cleanup + TODO comment normalization. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_2d/scipy_fft_2d.py | Formatting cleanup. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_2d/FFTPyFFTW2D.py | Formatting cleanup. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_2d/FastDiagPoissonSolver2D.py | Typing import cleanup + formatting improvements. |
| sopht/numeric/eulerian_grid_ops/poisson_solver_2d/init.py | Removes re-export surface (keeps docstring only). |
| scripts/cluster/submit.py | Formatting-only whitespace tweak. |
| examples/ruff.toml | Ruff config for examples (extends root; ignores docstyle/namespace/print rules). |
| examples/3d_examples/PointSourceAdvectAndDiffuseCase/point_source_helpers.py | Formatting-only cleanup. |
| examples/3d_examples/PointSourceAdvectAndDiffuseCase/point_source_advection_diffusion.py | Uses f-strings for filenames/progress; import ordering. |
| examples/3d_examples/OctopusSwimming/oscillation_activation_functions.py | Signature cleanup (drops unused system arg) + formatting. |
| examples/3d_examples/OctopusSwimming/octopus_initializer_functions.py | Formatting-only cleanup. |
| examples/3d_examples/OctopusArmCase3D/arm_functions_3d.py | Signature cleanup (drops unused system arg) + formatting. |
| examples/3d_examples/HillSphericalVortexCase/hill_sphere_vortex_helpers.py | Formatting cleanup + minor variable unused cleanup. |
| examples/3d_examples/HillSphericalVortexCase/hill_sphere_vortex_case.py | Adds noqa for private member access; formatting cleanup. |
| examples/3d_examples/FlowThroughPipeCase/flow_through_circular_pipe_case.py | Formatting cleanup + f-string filenames/progress. |
| examples/3d_examples/FlowPastSphereCase/flow_past_sphere_case.py | Formatting cleanup + f-string filenames/progress. |
| examples/3d_examples/FishSwimmingCase/elastic_fish_utils/fish_geometry.py | Replaces assert with explicit ValueError; formatting cleanup. |
| examples/3d_examples/FishSwimmingCase/elastic_fish_utils/fish_connection.py | super() modernization + override usage + formatting. |
| examples/3d_examples/FishSwimmingCase/elastic_fish_utils/carling_fish_bc.py | Import order cleanup. |
| examples/2d_examples/OctopusArmCase/run_coupling_tapered_arm_and_cylinder.py | Formatting cleanup + f-string filenames/progress; drops unused vars. |
| examples/2d_examples/OctopusArmCase/arm_functions_2d.py | Signature cleanup (drops unused system arg) + formatting. |
| examples/2d_examples/LidDrivenCavityCase/lid_driven_cavity_grid.py | Formatting cleanup; simplifies assignments; removes redundant pass statements. |
| examples/2d_examples/LidDrivenCavityCase/lid_driven_cavity_case.py | Formatting cleanup + f-string filenames/progress. |
| examples/2d_examples/LambOseenVortexCase/lamb_oseen_vortex.py | Formatting cleanup + f-string filenames/progress. |
| examples/2d_examples/LambOseenVortexCase/lamb_oseen_helpers.py | Formatting cleanup. |
| examples/2d_examples/ImmersedFlexiblePendulumCases/immersed_flexible_pendulum_with_rigid_cylinder.py | Formatting cleanup + f-string filenames/progress. |
| examples/2d_examples/ImmersedContinuumSnakeCase/immersed_continuum_snake.py | Formatting cleanup + minor step loop simplification. |
| examples/2d_examples/FlowPastRodCase/flow_past_rod.py | Formatting cleanup + f-string filenames/progress. |
| examples/2d_examples/FlowPastCylinderCase/flow_past_cylinder.py | Import order cleanup + f-string filenames/progress. |
| examples/2d_examples/FishSwimmingCase/elastic_fish_utils/fish_geometry_2d.py | Replaces assert with explicit ValueError; formatting cleanup. |
| examples/2d_examples/FishSwimmingCase/elastic_fish_utils/fish_connection_2d.py | super() modernization + override usage + formatting. |
| examples/2d_examples/FishSwimmingCase/elastic_fish_utils/carling_fish_bc_2d.py | Import order cleanup. |
| examples/2d_examples/FishSwimmingCase/elastic_fish_swimming_case_2d.py | Switches to new 2D flow factory; formatting cleanup + f-string filenames/progress. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/SophT-Team/SophT/sessions/4b8e5733-6675-44c9-b3e5-1dfc0dc76438 Co-authored-by: sy-cui <47127977+sy-cui@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 171 out of 173 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 171 out of 173 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 170 out of 172 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
The goal of this PR is to use
Ruffto reformat the code. This includes:Several fixes related to this change:
sopht/simulatorisortis handled natively byruffAdd isort for sorting imports #83Work in progress
The following compiles a list of rules listed by Ruff that
sophthas yet to comply to. This PR may not resolve all of themAdditional notes
sophtpackage (we can be lenient withexamplesandtests). This should be resolved together with Documentation for SophT #115