USEPA / harmonize-wq

Standardize, clean, and wrangle Water Quality Portal data into more analytic-ready formats
https://usepa.github.io/harmonize-wq/
MIT License
12 stars 5 forks source link

Setup for automated code quality #58

Closed Batalex closed 1 month ago

Batalex commented 5 months ago

As discussed in https://github.com/pyOpenSci/software-submission/issues/157, here is a suggestion on how to automate code quality (but not limited to!) tasks.

The setup is simple, as we use only ruff to both format and lint the files. I suggest using nox as the task runner.

Running the formatter + linter is just as simple as

nox

for short, or

nox -s format

for the long version.

Tests are also included:

nox -s tests

Now, for the configuration itself, I have added some entries to pyproject.toml with what, I think, is a good first setup for harmonize_wq.

There are things to discuss, so I'll keep this PR as a draft for now.

jbousquin commented 1 month ago

Starting to close the loop on this by copying over what I've mentioned elsewhere. The suggested settings have been working well in the pyproject.toml for running ruff locally without nox. I have pre-commits mostly working, but without the settings. I'm trying to work out if there is an easy way to do that from what is in the toml without nox. A lot of pieces I don't have a full grasp on though. What I'm aiming for is to have pre-commit make basic ruff changes on a PR, but to fail for not fixable changes. The idea being a contributor wouldn't have to get ruff/nox running locally to leverage it.

jbousquin commented 1 month ago

Specific to the settings - I appreciated quote-style = "single", at least for now to give me time to ensure it won't matter. Outside of that the only ones I'm not sure of are: (1) adding space between some import types (I001 - isn't specific to order vs spacing so I may just have to deal with a couple extra empty lines), and (2) E501 Line too long, where I was already linting for this, but not in docs examples where those lines get compared to doctest (as long as I can find a way to fix without failing doctests no issue).

jbousquin commented 1 month ago

TLDR - implemented w/ PR #89 .

To follow-up on this: part of the discrepancy between local and the pre-commit ended up being that format wasn't being run locally, I used quote-style = "preserve" during initial updates to differentiate where is was just '' vs "". In the end since it was somewhat arbitrary the default "" is used. # noqa: worked on docstring in the end but I tried to resolve using any other means first, over many attempts. All this was merged on PR 89. This PR was very helpful in providing initial settings in the pyproject.toml - thank you! Really the only difference for the merged PR is that it uses pre-commits to run it as part of checks instead of setting up nox to run it local.

jbousquin commented 1 month ago

whoops - meant to close w/ last comment