[WIP] Implement linting with Ruff#674
Conversation
|
In the tests, the protected attributes (like It seems that these changes could have been made in response to warnings from Ruff or due to the use of the --fix option. However, the removal of the leading underscore breaks the logic, since the non-protected version of these attributes may not exist. To fix this:
|
|
To apply ruff in pre-commits and avoid conflicts with other linters, you would need to add ruff to |
Makefile
Outdated
| ############### GLOBAL VARIABLES ###################### | ||
| .DEFAULT_GOAL := help | ||
| SHELL := /bin/bash | ||
| PATH :=. |
There was a problem hiding this comment.
This command breaks the Makefile by overwriting the system's executable search paths, preventing essential commands from being found. Since PATH already exists, it's unnecessary to redefine it.
Makefile
Outdated
| @echo "Applying ruff..." | ||
| @echo "================" | ||
| @echo | ||
| @ruff --fix $(path) |
xdem/ddem.py
Outdated
|
|
||
|
|
||
| class dDEM(Raster): # type: ignore | ||
| class Ddem(Raster): # type: ignore |
There was a problem hiding this comment.
Not sure this change is very wise, as dDEM mirrors the typo of the DEM class. But if you change it, you have to change it everywhere it is used
xdem/_typing.py
Outdated
|
|
||
| # Only for Python >= 3.9 | ||
| if sys.version_info.minor >= 9: | ||
| if sys.version_info.minor >= (3, 9): |
There was a problem hiding this comment.
This causes an error, the system version should not be a tuple
xdem/coreg/base.py
Outdated
| steps = list(self.procstep.pipeline) | ||
| argspec = [inspect.getfullargspec(s.__class__) for s in steps] | ||
| sub_meta = [s._meta["inputs"]["random"]["subsample"] for s in steps] | ||
| sub_meta = [s.meta["inputs"]["random"]["subsample"] for s in steps] |
xdem/spatialstats.py
Outdated
| # Get the arrays for proxy values and explanatory variables | ||
| list_all_arr, gsd = _preprocess_values_with_mask_to_array( | ||
| values=[dvalues] + list_var, include_mask=stable_mask, exclude_mask=unstable_mask, preserve_shape=False | ||
| values=[dvalues, list_var], include_mask=stable_mask, exclude_mask=unstable_mask, preserve_shape=False, |
There was a problem hiding this comment.
This modifications triggered an issue : it creates a nested list where list_var is treated as a single element, resulting in [dvalues, [list_var]].
xdem/spatialstats.py
Outdated
| list_inside_radius = [] | ||
| list_outside_radius: list[float | None] = [] | ||
| binned_ranges = [0.0] + pdist_multi_ranges | ||
| binned_ranges = [0.0, pdist_multi_ranges] |
xdem/spatialstats.py
Outdated
| else: | ||
| first_xmin = 0 | ||
| xscale_range_split = [first_xmin] + xscale_range_split | ||
| xscale_range_split = [first_xmin, xscale_range_split] |
xdem/spatialstats.py
Outdated
|
|
||
| # Plot the histogram manually with fill_between | ||
| interval_var = [0] + list(df.lags) | ||
| interval_var = [0, list(df.lags)] |
xdem/spatialstats.py
Outdated
|
|
||
| # Get the lags bin centers | ||
| bins_center = np.subtract(df.lags, np.diff([0] + df.lags.tolist()) / 2) | ||
| bins_center = np.subtract(df.lags, np.diff([0, df.lags.tolist()]) / 2) |
|
Great! 🤩 Question: I heard that Ruff was a "drop-in replacement" for black, flake8, etc (so producing almost exactly the same output, just much much faster). So most of the changes should arise mostly from updating black and other to more recent versions, or different rules, right? |
| files: ^(xdem|tests) | ||
|
|
||
| # Lint the code using mypy | ||
| - repo: https://github.com/pre-commit/mirrors-mypy |
|
This PR would become much easier to merge if you disable most ruff rules and re-enable them one by one. |
Resolves #550
Description :
The Pull Request implements linting on xDEM in order to guarantee the same code quality as demcompare.
The idea was to limit the number of tools and to apply the same rules as demcompare.
That's why we choose to implement Ruff in Xdem, a fast python linter and code formatter gathering a lot of functionalities and replacing pylint, black, flake8 and isort.
Key changes :
Ruff configuration :
ruff.toml file addded including the following rules :
Ruff added in makefile
Ruff added in CI file
Ruff added in setup.cfg file
Code correction :
Ruff returned a lot of errors related to 108 lint rules :