Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ruff as the central tool for linting, formatting, and import sorting #702

Merged
merged 12 commits into from
Oct 3, 2024

Conversation

tomvothecoder
Copy link
Collaborator

@tomvothecoder tomvothecoder commented Oct 2, 2024

Description

Why ruff?

  • Meets most of our needs out-of-the-box (linter, formatter, import sorting)
  • Adopting ruff simplifies DevOps tooling and configuration
  • It is significantly faster for linting, formatting, and import sorting compared to flake8, black, and isort
  • Mostly interoperable and configured to replicate flake8, black, and isort out-of-the-box
  • Is easily extensible with tools like flake8-docstrings and flake8-bugbear
  • Rapidly growing popularity on GitHub, adopted by other major Python packages

Summary of changes

What do contributors need to do?

  1. Recreate their development environment after this PR is merged
    • conda env create -f conda/dev.yml
  2. Reinstall pre-commit hooks into their xcdat repo: pre-commit install
    • pre-commit install

Future TODOs

  • Enable flake8-docstring for ruff in pyproject.toml and fix docstring issues

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

If applicable:

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass with my changes (locally and CI/CD build)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have noted that this is a breaking change for a major release (fix or feature that would cause existing functionality to not work as expected)

@github-actions github-actions bot added type: devops Testing, CI/CD, systems configuration type: docs Updates to documentation labels Oct 2, 2024
Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (563e267) to head (03d350e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #702   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines         1546      1546           
=========================================
  Hits          1546      1546           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator Author

@tomvothecoder tomvothecoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My self-review

@@ -847,7 +847,7 @@ def test_add_monthly_bounds_for_end_of_month_set_to_true(self):
# Get time axis and create new axis with time set to first day of month.
time = ds_with_bnds.time
new_time = []
for i, t in enumerate(time.values):
for _, t in enumerate(time.values):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -663,7 +668,7 @@ def test_map_latitude_coarse_to_fine(self):
np.testing.assert_allclose(x, y)

for x2, y2 in zip(weights, expected_weigths):
np.testing.assert_allclose(x, y)
np.testing.assert_allclose(x2, y2)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1254,7 +1259,7 @@ def test_grid(self):
ValueError,
match=r".*lon\d?.*lon\d?.*",
):
ds_multi.regridder.grid
ds_multi.regridder.grid # noqa: B018
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -44,7 +44,7 @@
def open_dataset(
path: str | os.PathLike[Any] | BufferedIOBase | AbstractDataStore,
data_var: Optional[str] = None,
add_bounds: List[CFAxisKey] | None = ["X", "Y"],
add_bounds: List[CFAxisKey] | Tuple[CFAxisKey, ...] | None = ("X", "Y"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 127 to 131
def add_missing_bounds( # noqa: C901
self, axes: List[CFAxisKey] = ["X", "Y", "T"]
self, axes: List[CFAxisKey] | Tuple[CFAxisKey, ...] = ("X", "Y", "T")
) -> xr.Dataset:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +151 to +154
except KeyError as e:
raise RuntimeError(
"Could not determine 'Z' coordinate in output dataset"
) from e
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +170 to +174
except KeyError as e:
if self._target_data is not None and isinstance(self._target_data, str):
raise RuntimeError(
f"Could not find target variable {self._target_data!r} in dataset"
)
) from e
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +221 to +222
except KeyError as e:
raise RuntimeError("Could not determine `Z` coordinate in dataset.") from e
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +236 to +237
except KeyError as e:
raise RuntimeError("Could not determine `Z` bounds in dataset.") from e
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +963 to +968
except (IndexError, ValueError) as e:
raise ValueError(
"Reference periods must be a tuple of strings with the format "
"'yyyy-mm-dd'. For example, reference_period=('1850-01-01', "
"'1899-12-31')."
)
) from e
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomvothecoder tomvothecoder self-assigned this Oct 2, 2024
@tomvothecoder tomvothecoder marked this pull request as ready for review October 2, 2024 21:15
@tomvothecoder
Copy link
Collaborator Author

tomvothecoder commented Oct 2, 2024

@xCDAT/core-developers happy to hear thoughts if any of you care about this like I do.

All you need to do on your end is reinstall your conda dev env and pre-commit hooks if this PR is merged

@pochedls
Copy link
Collaborator

pochedls commented Oct 2, 2024

I trust you.

@tomvothecoder tomvothecoder merged commit e3dda64 into main Oct 3, 2024
5 checks passed
@tomvothecoder tomvothecoder deleted the devops/592-ruff branch October 3, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: devops Testing, CI/CD, systems configuration type: docs Updates to documentation
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[DevOps]: Consider replacing flake8 linter, black formatter, and isort with ruff
2 participants