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

Setup for automated code quality #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from pathlib import Path

import nox

RUN_DEPS = ["geopandas", "pint", "dataretrieval"]

FORMAT_DEPS = ["ruff >= 0.3.5"]
TESTS_DEPS = ["pytest", "coverage"]
Comment on lines +5 to +8
Copy link
Author

Choose a reason for hiding this comment

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

todo: Ideally, we want to keep those in sync with the deps listed in pyproject.toml.


ROOT_PATH = Path.cwd()
SRC_PATH = ROOT_PATH / "harmonize_wq"
TESTS_PATH = SRC_PATH / "tests"
DOCS_PATH = ROOT_PATH / "docs"

nox.options.reuse_venv = "yes"
nox.options.sessions = ["format"]


@nox.session
def format(session):
"""Apply coding style standards to code."""
session.install(*FORMAT_DEPS)
session.run("ruff", "format", SRC_PATH)
session.run("ruff", "check", "--fix", SRC_PATH)


@nox.session
def tests(session):
"""Run tests and compute code coverage."""
session.install(*RUN_DEPS)
session.install(*TESTS_DEPS)
session.run("coverage", "run", "-m", "pytest", *session.posargs, TESTS_PATH)
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,20 @@ doc = ["sphinx"]
"Homepage" = "https://github.com/USEPA/harmonize-wq"
"Documentation" = "https://usepa.github.io/harmonize-wq/"
"Bug Tracker" = "https://github.com/USEPA/harmonize-wq/issues"


[tool.ruff.lint]
select = [
"E",
"F",
"W",
"I"
]
Comment on lines +41 to +46
Copy link
Author

Choose a reason for hiding this comment

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

suggestion: You might want to take a look at the list of rules available. This configuration is equivalent to flake8 + isort, but we could want a different set of rules for harmonize_wq

Rules can also be ignored:

  • entirely
  • at the file level
  • for a specifc line using a comment # noqa: E722 for instance


[tool.ruff.lint.isort]
known-first-party = ["harmonize_wq"]

[tool.ruff.format]
quote-style = "single"
Copy link
Author

Choose a reason for hiding this comment

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

discussion: The default format used by black (and ruff as well) is to use double quotes for strings. However, this option will avoid messing with the full code base

docstring-code-format = true